본문 바로가기

프로그래밍/Waspmote-LoRa

WASPMOTE LoRa 기본 통신


WASPMOTE와 LoRa(sx1272)모듈을 통한 RX & TX test


준비물

waspmote x2

waspmote용 lora(sx1272) module x2

Antenna x2

usb A형 x2

컴퓨터 2대



waspmote receive, transmission test는 기본 예제를 통해서 수행 할 수 있다.


기본 예제는 IDE에서 바로 불러와서 수행이 가능하다.




===sx1272 Receiver code===

/*
* ------ [SX_02b] - RX LoRa --------
*
* Explanation: This example shows how to configure the semtech
* module in LoRa mode and then receive packets with plain-text payloads
*
* Copyright (C) 2014 Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Version: 0.1
* Design: David Gascón
* Implementation: Covadonga Albiñana, Yuri Carmona
*/
// Include this library for transmit with sx1272
#include <WaspSX1272.h>
// status variable
int8_t e;
void setup()
{
// Init USB port
USB.ON();
USB.println(F("SX_02b example"));
USB.println(F("Semtech SX1272 module RX in LoRa"));
USB.println(F("----------------------------------------"));
USB.println(F("Setting configuration:"));
USB.println(F("----------------------------------------"));
// Init sx1272 module
sx1272.ON();
// Select frequency channel
e = sx1272.setChannel(CH_10_868);
USB.print(F("Setting Channel CH_10_868.\t state "));
USB.println(e);
// Select implicit (off) or explicit (on) header mode
e = sx1272.setHeaderON();
USB.print(F("Setting Header ON.\t\t state "));
USB.println(e);
// Select mode: from 1 to 10
e = sx1272.setMode(1);
USB.print(F("Setting Mode '1'.\t\t state "));
USB.println(e);
// Select CRC on or off
e = sx1272.setCRC_ON();
USB.print(F("Setting CRC ON.\t\t\t state "));
USB.println(e);
// Select output power (Max, High or Low)
e = sx1272.setPower('L');
USB.print(F("Setting Power to 'L'.\t\t state "));
USB.println(e);
// Select the node address value: from 2 to 255
e = sx1272.setNodeAddress(8);
USB.print(F("Setting Node Address to '8'.\t state "));
USB.println(e);
delay(1000);
USB.println(F("----------------------------------------"));
USB.println(F("Receiving:"));
USB.println(F("----------------------------------------"));
}
void loop()
{
// receive packet
e = sx1272.receivePacketTimeout(10000);
// check rx status
if( e == 0 )
{
USB.println(F("\nShow packet received: "));
// show packet received
sx1272.showReceivedPacket();
}
else
{
USB.print(F("\nReceiving packet TIMEOUT, state "));
USB.println(e, DEC);
}
}


=======


===sx1272 Receiver code===

/*
* ------ [SX_02a] - TX LoRa --------
*
* Explanation: This example shows how to configure the semtech
* module in LoRa mode and then send packets with plain-text payloads
*
* Copyright (C) 2014 Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Version: 0.1
* Design: David Gascón
* Implementation: Covadonga Albiñana, Yuri Carmona
*/
// Include this library to transmit with sx1272
#include <WaspSX1272.h>
// define the destination address to send packets
uint8_t rx_address = 8;
// status variable
int8_t e;
void setup()
{
// Init USB port
USB.ON();
USB.println(F("SX_02a example"));
USB.println(F("Semtech SX1272 module TX in LoRa"));
USB.println(F("----------------------------------------"));
USB.println(F("Setting configuration:"));
USB.println(F("----------------------------------------"));
// Init sx1272 module
sx1272.ON();
// Select frequency channel
e = sx1272.setChannel(CH_10_868);
USB.print(F("Setting Channel CH_10_868.\t state "));
USB.println(e);
// Select implicit (off) or explicit (on) header mode
e = sx1272.setHeaderON();
USB.print(F("Setting Header ON.\t\t state "));
USB.println(e);
// Select mode: from 1 to 10
e = sx1272.setMode(1);
USB.print(F("Setting Mode '1'.\t\t state "));
USB.println(e);
// Select CRC on or off
e = sx1272.setCRC_ON();
USB.print(F("Setting CRC ON.\t\t\t state "));
USB.println(e);
// Select output power (Max, High or Low)
e = sx1272.setPower('L');
USB.print(F("Setting Power to 'L'.\t\t state "));
USB.println(e);
// Select the node address value: from 2 to 255
e = sx1272.setNodeAddress(2);
USB.print(F("Setting Node Address to '2'.\t state "));
USB.println(e);
USB.println();
delay(1000);
USB.println(F("----------------------------------------"));
USB.println(F("Sending:"));
USB.println(F("----------------------------------------"));
}
void loop()
{
// Sending packet before ending a timeout
e = sx1272.sendPacketTimeout( rx_address, "This_is_a_new_message");
// Check sending status
if( e == 0 )
{
USB.println(F("Packet sent OK"));
}
else
{
USB.println(F("Error sending the packet"));
USB.print(F("state: "));
USB.println(e, DEC);
}
delay(2500);
}


=======




위 code를 각각의 waspmote에 넣고 수행하면 아래와 같은 결과가 나타난다.


===sx1272 Receiver===




===sx1272 Transmission===



각각의 수신, 송신 코드와 화면을 보면 알 수 있듯이


송신(Transmission)은 broadcast형식으로 연결이 되지 않더라도 계속 해서 packet을 날리는


모습을 볼 수 있다.


반면 수신(Receiver)의 경우 수신이 될때 까지 기다리다가 수신을 받으면


해당 구문을 print하고 다시 loop를 돌아 수신을 기다리고 있는 것을 


볼 수 있다.






'프로그래밍 > Waspmote-LoRa' 카테고리의 다른 글

WASPMOTE LORA mode 종류  (1) 2016.06.21
WASPMOTE PRO IDE 소개  (0) 2016.06.21
WASPMOTE 소개  (1) 2016.06.21