diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d01f25c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +Setup +Lora/obj/* \ No newline at end of file diff --git a/Arduino/LoraProject/LoraProject.ino b/Arduino/LoraProject/LoraProject.ino deleted file mode 100644 index acee936..0000000 --- a/Arduino/LoraProject/LoraProject.ino +++ /dev/null @@ -1,543 +0,0 @@ -/* - RadioLib SX127x Ping-Pong Example - - For default module settings, see the wiki page - https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem - - For full API reference, see the GitHub Pages - https://jgromes.github.io/RadioLib/ -*/ - -// include the library -#include - -#define HEADER_0_POS 0 -#define HEADER_0 0x4E - -#define HEADER_1_POS 1 -#define HEADER_1 0xAD - -#define NETWORK_ID_POS 2 -#define NETWORK_ID 0x01 - -#define NODE_ID_POS 3 -#define NODE_ID 0x02 - -#define MSG_POS 4 -#define DISCOVER 0x01 -#define ASKING 0x02 -#define ABLE_MEASURE 0x03 -#define DISABLE_MEASURE 0x04 -#define ACK 0x05 -#define NACK 0x06 -#define TIMEOUT 0x42 -#define LED_ON 0x66 -#define LED_OFF 0x67 -#define PING 0x17 - -#define TYPE_CAPT_POS 4 -#define TYPE_CAPT 0x01 - -#define DATA_LONG_POS 5 -#define DATA_LONG 0x01 -#define NUL 0x00 - -#define DISCOVER_LONG 6 -#define ACK_LONG 5 -#define TRANSMIT_LONG (DATA_LONG + 4) -#define DISABLE_LONG 5 - -// SX1272 has the following connections: -// NSS pin: 10 -// DIO0 pin: 2 or 0 on rasp -// NRST pin: 9 or 7 on rasp -// DIO1 pin: 3 -SX1272 radio = new Module(10, 2, 9, 3); - -// save transmission states between loops -int state = RADIOLIB_ERR_NONE; - -// flag to indicate transmission or reception state -bool transmitFlag = false; - -// disable interrupt when it's not needed -volatile bool enableInterrupt = true; - -// flag to indicate that a packet was sent or received -volatile bool operationDone = false; - -void isSOk(void) { - if (state == RADIOLIB_ERR_NONE) { - Serial.println(F("success!")); - } else { - Serial.print(F("failed, code ")); - Serial.println(state); - } -} - -// this function is called when a complete packet -// is transmitted or received by the module -// IMPORTANT: this function MUST be 'void' type -// and MUST NOT have any arguments! -void setFlag(void) { - // check if the interrupt is enabled - if (!enableInterrupt) { - return; - } - - // we sent or received packet, set the flag - operationDone = true; -} - -void setup() { - Serial.begin(38400); - pinMode(4, OUTPUT); - - // initialize SX1272 with default settings - Serial.println(F("\n-------------------------------------")); - Serial.print(F("[SX1272] Initializing ... ")); - - state = radio.begin(868.0, 500.0, 12, 5, RADIOLIB_SX127X_SYNC_WORD, 2, 8, 6); // max bw - //state = radio.begin(866.4, 500.0, 7, 5, RADIOLIB_SX127X_SYNC_WORD, 2, 6, 6); // max bw - //int state = radio.begin(866.4, 125.0, 12, 5, RADIOLIB_SX127X_SYNC_WORD, 20, 8, 1); // max dist - - isSOk(); - - // some modules have an external RF switch - // controlled via two pins (RX enable, TX enable) - // to enable automatic control of the switch, - // call the following method - // RX enable: 8 or 3 on rasp - // TX enable: 7 or 2 on rasp - - radio.setRfSwitchPins(8, 7); - - // set the function that will be called - // when new packet is received - radio.setDio0Action(setFlag); - - //radio.setEncoding() // chiffrage -} // end of setup - -void printMsg(byte *data, int *dataLength, bool caret = true, bool hexad = true) { - if(hexad) { - char *hexa = "0123456789ABCDEF"; - for(int i = 0; i < dataLength; i++) { - if (data[i] > 4095) Serial.print(hexa[data[i] / 4096]); - if (data[i] > 255) Serial.print(hexa[data[i] / 256 % 16]); // write ASCII value of hexadecimal high nibble - Serial.print(hexa[data[i] / 16 % 16]); // write ASCII value of hexadecimal high nibble - Serial.print(hexa[data[i] % 16]); // write ASCII value of hexadecimal low nibble - Serial.print(" "); - } - } else { - for(int i = 0; i < dataLength; i++) { - Serial.print(data[i]); - Serial.print(" "); - } - } - if(caret) Serial.print("\r\n"); -} - -void printHex(byte data, bool caret = true, bool hexad = true) { - if(hexad) { - char *hexa = "0123456789ABCDEF"; - if (data > 4095) Serial.print(hexa[data / 4096]); - if (data > 255) Serial.print(hexa[data / 256 % 16]); // write ASCII value of hexadecimal high nibble - Serial.print(hexa[data / 16 % 16]); // write ASCII value of hexadecimal high nibble - Serial.print(hexa[data % 16]); // write ASCII value of hexadecimal low nibble - Serial.print(" "); - } else { - Serial.print(data); - Serial.print(" "); - } - if(caret) Serial.print("\r\n"); -} - -/* - * byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - * int state = radio.transmit(byteArr, 8); - */ - -/* - * RC5 MOSI 15 - * RC4 MISO 14 - * RC3 Clock 13 - * RC2 CS LoRa 16 - * RC1 CS Lcd - * RC0 CS Capteur - * RB4 RX Pic 5 - * RB3 TX Pic 4 - * RB2 Reset 12 - * - * #define HEADER_0_POS 0 - * #define HEADER_0 0x4E - * - * #define HEADER_1_POS 1 - * #define HEADER_1 0xAD - * - * #define NETWORK_ID_POS 2 - * #define NETWORK_ID 0x01 - * - * #define NODE_ID_POS 3 - * #define NODE_ID 0x01 - * - * #define MSG_POS 4 - * #define DISCOVER 0x01 - * #define ASKING 0x02 - * #define ABLE_MEASURE 0x03 - * #define DISABLE_MEASURE 0x04 - * #define ACK 0x05 - * #define NACK 0x06 - * #define TIMEOUT 0x42 - * #define LED_ON 0x66 - * #define LED_OFF 0x67 - * #define PING 0x17 - * - * #define TYPE_CAPT_POS 4 - * #define TYPE_CAPT 0x01 - * - * #define DATA_LONG_POS 5 - * #define DATA_LONG 0x01 - * #define NUL 0x00 - * - * #define DISCOVER_LONG 6 - * #define ACK_LONG 5 - * #define TRANSMIT_LONG (DATA_LONG + 4) - * #define DISABLE_LONG 5 - * - * const uint8_t rxMsg[] = { 0x4E, 0xAD, 0x01, 0x04, 0x01 }; //Découverte Réseau Base - * const uint8_t txMsg[] = { 0xAD, 0x4E, 0x01, 0x04, 0x01, 0x01 }; //Réponse header + network + node 4 + température + 1 octet - * const uint8_t rxMsg[] = { 0x4E, 0xAD, 0x01, 0x04, 0x02 }; //Requête données - * const uint8_t txMsg[] = { 0xAD, 0x4E, 0x01, 0x04, 0x03 }; //Réponse header + network + node 4 + possible ou 04 impossible - * const uint8_t txMsg[] = { 0xAD, 0x4E, 0x01, 0x04, txMsg[i], lvlBatt }; //Réponse header + network + node 4 + possible ou 04 impossible - * const uint8_t rxMsg[] = { 0x4E, 0xAD, 0x01, 0x04, 0x05 }; //Accusé reception ou 06 demande renvoi - * - * uint8_t RXNumberOfBytes; // to store the number of bytes received - * uint8_t rxMsg[30]; // message reçu - * uint8_t txMsg[] = { HEADER_1, HEADER_0, NETWORK_ID, NODE_ID, NUL, NUL, NUL, NUL, NUL }; // message transmit - */ - - -static char id = 1; -byte networkAvailable[] = { NUL, NUL, NUL, NUL, NUL }; // store ids of networks -int networkRssi[] = { NUL, NUL, NUL, NUL, NUL }; // store Rssi of networks -byte txMsg[] = { HEADER_0, HEADER_1, NETWORK_ID, NUL, NUL, NUL, NUL, NUL, NUL }; // message transmit -byte rxMsg[6]; -int rxLength; -byte idInc = 0x01; -const bool debuglvl = false; - -void debug(void) { - if (state == RADIOLIB_ERR_NONE) { - // packet was successfully received - Serial.println(F("[SX1272] Received packet!")); - - // print data of the packet - Serial.print(F("[SX1272] Data:\t\t")); - printMsg(rxMsg, rxLength); - - // print RSSI (Received Signal Strength Indicator) - Serial.print(F("[SX1272] RSSI:\t\t")); - Serial.print((int)radio.getRSSI()); - //Serial.print(rssi = ((int) radio.getRSSI())); - Serial.print(F(" dBm ")); - //Serial.print(((meanRSSI += rssi) / ++increment)); - Serial.println(); - - // print SNR (Signal-to-Noise Ratio) - Serial.print(F("[SX1272] SNR:\t\t")); - Serial.print(radio.getSNR()); - //Serial.print(snr = radio.getSNR()); - Serial.print(F(" dB ")); - //Serial.print(((meanSNR += snr) / increment)); - Serial.println(); - - // print frequency error - Serial.print(F("[SX1272] Frequ err:\t\t")); - Serial.print(radio.getFrequencyError(false)); - Serial.println(F(" Hz")); - - } else if (state == RADIOLIB_ERR_CRC_MISMATCH) { - // packet was received, but is malformed - Serial.println(F("[SX1272] CRC error!")); - } else { - // some other error occurred - Serial.print(F("[SX1272] Failed, code ")); - Serial.println(state); - } -} - -void loop() { - - if (operationDone) { - // disable the interrupt service routine while - // processing the data - enableInterrupt = false; - - // reset flag - operationDone = false; - - rxLength = radio.getPacketLength(); - state = radio.readData(rxMsg, rxLength); - - Serial.print(F("received data: ")); - printMsg(rxMsg, rxLength); - if(debuglvl) debug(); - - if(rxMsg[NETWORK_ID_POS] == NETWORK_ID) { // si message de notre réseau.. - switch (rxMsg[MSG_POS]) { // type de message - case DISCOVER: - Serial.print(F("Discover net : ")); - printHex(rxMsg[NODE_ID_POS]); // discover us - - if(rxMsg[NODE_ID_POS] != NODE_ID) break; // demande d'enregistrement d'un autre groupe - - Serial.println(F("Enregistrement")); - txMsg[HEADER_0_POS] = HEADER_1; // headers retournés - txMsg[HEADER_1_POS] = HEADER_0; // - txMsg[NETWORK_ID_POS] = NETWORK_ID; // network 1 - txMsg[NODE_ID_POS] = NODE_ID; // groupe 4 - txMsg[TYPE_CAPT_POS] = TYPE_CAPT; - txMsg[DATA_LONG_POS] = DATA_LONG; - - Serial.print(F("[SX1272] Sending : ")); - printMsg(txMsg, DISCOVER_LONG); - - state = radio.transmit(txMsg, DISCOVER_LONG); - //delay(5) // transmit est blocant - isSOk(); - break; - - case ASKING: - Serial.println(F("Requete de donnees ")); - - if(rxMsg[NODE_ID_POS] != NODE_ID) break; - - Serial.println(F("Mesure possible")); - // remplissage txMsg - txMsg[MSG_POS] = ABLE_MEASURE; - - Serial.print(F("[SX1272] Sending : ")); - printMsg(txMsg, ACK_LONG); - - state = radio.transmit(txMsg, ACK_LONG); - //delay(5) // transmit est blocant - isSOk(); - - // remplissage txMsg - txMsg[MSG_POS] = 0x20; - - Serial.print(F("[SX1272] Sending : ")); - printMsg(txMsg, TRANSMIT_LONG); - state = radio.transmit(txMsg, TRANSMIT_LONG); - //delay(5) // transmit est blocant - isSOk(); - break; - - case ABLE_MEASURE: - Serial.println(F("Mesure possible")); - break; - - case DISABLE_MEASURE: - Serial.println(F("Mesure impossible")); - - if(rxMsg[NODE_ID_POS] != NODE_ID) break; - - // remplissage txMsg - txMsg[MSG_POS] = DISABLE_MEASURE; - - Serial.print(F("[SX1272] Sending : ")); - printMsg(txMsg, DISABLE_LONG); - state = radio.transmit(txMsg, DISABLE_LONG); - //delay(5) // transmit est blocant - isSOk(); - break; - - case ACK: - Serial.println(F("Accuse reception")); - if(idInc >= 0x05) idInc = 0x1; - if(idInc == NETWORK_ID) idInc++; - networkAvailable[idInc-1] = rxMsg[NETWORK_ID_POS]; - networkRssi[idInc-1] = (int)radio.getRSSI(); - idInc++; - break; - - case NACK: - Serial.println(F("Erreur de transfert")); - - if(rxMsg[NODE_ID_POS] != NODE_ID) break; - - // remplissage txMsg - txMsg[MSG_POS] = 0x20; - - Serial.print(F("[SX1272] Sending : ")); - printMsg(txMsg, ACK_LONG); - state = radio.transmit(txMsg, ACK_LONG); - //delay(5) // transmit est blocant - isSOk(); - break; - - case TIMEOUT: - Serial.println(F("Timeout")); - rxMsg[MSG_POS] = 0; - break; - - case LED_ON: - digitalWrite(4, HIGH); - Serial.println(F("Led ON")); - txMsg[HEADER_0_POS] = HEADER_1; // headers retournés - txMsg[HEADER_1_POS] = HEADER_0; // - txMsg[NETWORK_ID_POS] = NETWORK_ID; // network 1 - txMsg[NODE_ID_POS] = NODE_ID; // groupe 4 - txMsg[MSG_POS] = ACK; - Serial.print(F("[SX1272] Sending : ")); - printMsg(txMsg, TRANSMIT_LONG); - state = radio.transmit(txMsg, TRANSMIT_LONG); - //delay(5) // transmit est blocant - isSOk(); - break; - - case LED_OFF: - digitalWrite(4, LOW); - Serial.println(F("Led OFF")); - txMsg[HEADER_0_POS] = HEADER_1; // headers retournés - txMsg[HEADER_1_POS] = HEADER_0; // - txMsg[NETWORK_ID_POS] = NETWORK_ID; // network 1 - txMsg[NODE_ID_POS] = NODE_ID; // groupe 4 - txMsg[MSG_POS] = ACK; - Serial.print(F("[SX1272] Sending : ")); - printMsg(txMsg, TRANSMIT_LONG); - state = radio.transmit(txMsg, TRANSMIT_LONG); - //delay(5) // transmit est blocant - isSOk(); - break; - - case PING: - Serial.print(F("Pinging from ")); - printHex(rxMsg[NODE_ID_POS], false); - Serial.print(F("to ")); - printHex(rxMsg[NETWORK_ID_POS]); - - if(rxMsg[NODE_ID_POS] != NODE_ID) break; - - Serial.println(F("Pong")); - txMsg[HEADER_0_POS] = HEADER_1; - txMsg[HEADER_1_POS] = HEADER_0; - txMsg[NETWORK_ID_POS] = 0x01; - txMsg[NODE_ID_POS] = 0x02; - txMsg[MSG_POS] = ACK; - - Serial.print(F("[SX1272] Sending : ")); - printMsg(txMsg, ACK_LONG); - - state = radio.transmit(txMsg, ACK_LONG); - //delay(5) // transmit est blocant - isSOk(); - break; - - default: - Serial.println(F("error")); - - } // end of switch case - - } else if(rxMsg[HEADER_0_POS] == HEADER_0 && rxMsg[HEADER_1_POS] == HEADER_1 && rxMsg[NETWORK_ID_POS] == NODE_ID) { - switch (rxMsg[MSG_POS]) { - case LED_ON: - digitalWrite(4, HIGH); - Serial.println(F("Led ON")); - txMsg[HEADER_0_POS] = HEADER_1; // headers retournés - txMsg[HEADER_1_POS] = HEADER_0; // - txMsg[NETWORK_ID_POS] = NETWORK_ID; // network 1 - txMsg[NODE_ID_POS] = NODE_ID; // groupe 4 - txMsg[MSG_POS] = ACK; - Serial.print(F("[SX1272] Sending : ")); - printMsg(txMsg, TRANSMIT_LONG); - state = radio.transmit(txMsg, TRANSMIT_LONG); - //delay(5) // transmit est blocant - isSOk(); - break; - - case LED_OFF: - digitalWrite(4, LOW); - Serial.println(F("Led OFF")); - txMsg[HEADER_0_POS] = HEADER_1; // headers retournés - txMsg[HEADER_1_POS] = HEADER_0; // - txMsg[NETWORK_ID_POS] = NETWORK_ID; // network 1 - txMsg[NODE_ID_POS] = NODE_ID; // groupe 4 - txMsg[MSG_POS] = ACK; - Serial.print(F("[SX1272] Sending : ")); - printMsg(txMsg, TRANSMIT_LONG); - state = radio.transmit(txMsg, TRANSMIT_LONG); - //delay(5) // transmit est blocant - isSOk(); - break; - - case PING: - Serial.print(F("Pinging from ")); - printHex(rxMsg[NODE_ID_POS], false); - Serial.print(F("to ")); - printHex(rxMsg[NETWORK_ID_POS]); - - if(rxMsg[NETWORK_ID_POS] != NODE_ID) break; - - Serial.println(F("Pong")); - txMsg[HEADER_0_POS] = HEADER_1; - txMsg[HEADER_1_POS] = HEADER_0; - txMsg[NETWORK_ID_POS] = 0x01; - txMsg[NODE_ID_POS] = 0x02; - txMsg[MSG_POS] = ACK; - - Serial.print(F("[SX1272] Sending : ")); - printMsg(txMsg, ACK_LONG); - - state = radio.transmit(txMsg, ACK_LONG); - //delay(5) // transmit est blocant - isSOk(); - break; - - default: - Serial.println(F("error")); - } // end of switch case - } else { - Serial.print(F("[SX1272] Data:\t\t")); - printMsg(rxMsg, rxLength); - } - - Serial.println(F("-------------------------------------")); - - } // end of if opdone - - - if(!networkAvailable[0] && false) { - enableInterrupt = false; - Serial.println(F("Discovering networks")); - Serial.print(F("Network ")); - printHex(NETWORK_ID, false); - Serial.print(F("scanning ")); - printHex(idInc); - - if(idInc >= 0x05) idInc = 0x1; - if(idInc == NETWORK_ID) idInc++; - - txMsg[HEADER_0_POS] = HEADER_0; // headers - txMsg[HEADER_1_POS] = HEADER_1; // - txMsg[NETWORK_ID_POS] = NETWORK_ID; // network 1 - txMsg[NODE_ID_POS] = idInc; // target - txMsg[MSG_POS] = DISCOVER; // command - - Serial.print(F("[SX1272] Sending : ")); - printMsg(txMsg, 5); - state = radio.transmit(txMsg, 5); - //delay(5) // transmit est blocant - isSOk(); - idInc++; - } else { // end of if !netwa - //printMsg(networkAvailable, 5); - //Serial.println(networkRssi[0]); - } - // put module back to listen mode - radio.startReceive(); - enableInterrupt = true; // enable interrupt - delay(250); - -} // end of loop diff --git a/Arduino/SX127x_PingPong/SX127x_PingPong.ino b/Arduino/SX127x_PingPong/SX127x_PingPong.ino deleted file mode 100644 index 411f4fc..0000000 --- a/Arduino/SX127x_PingPong/SX127x_PingPong.ino +++ /dev/null @@ -1,189 +0,0 @@ -/* - RadioLib SX127x Ping-Pong Example - - For default module settings, see the wiki page - https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem - - For full API reference, see the GitHub Pages - https://jgromes.github.io/RadioLib/ -*/ - -// include the library -#include - -// uncomment the following only on one -// of the nodes to initiate the pings -//#define INITIATING_NODE - -// SX1272 has the following connections: -// NSS pin: 10 -// DIO0 pin: 2 -// NRST pin: 9 -// DIO1 pin: 3 -SX1272 radio = new Module(10, 2, 9, 3); - -// or using RadioShield -// https://github.com/jgromes/RadioShield -//SX1272 radio = RadioShield.ModuleA; - -static char id = 1 - -// save transmission states between loops -int transmissionState = RADIOLIB_ERR_NONE; - -// flag to indicate transmission or reception state -bool transmitFlag = false; - -// disable interrupt when it's not needed -volatile bool enableInterrupt = true; - -// flag to indicate that a packet was sent or received -volatile bool operationDone = false; - -// this function is called when a complete packet -// is transmitted or received by the module -// IMPORTANT: this function MUST be 'void' type -// and MUST NOT have any arguments! -void setFlag(void) { - // check if the interrupt is enabled - if(!enableInterrupt) { - return; - } - - // we sent or received packet, set the flag - operationDone = true; -} - -void setup() { - Serial.begin(9600); - - // initialize SX1272 with default settings - Serial.println(F("\n-------------------------------------")); - Serial.print(F("[SX1272] Initializing ... ")); - int state = radio.begin(867.1, 500.0, 7, 5, RADIOLIB_SX127X_SYNC_WORD, 2, 6, 6); // max bw - //int state = radio.begin(867.1, 125.0, 12, 5, RADIOLIB_SX127X_SYNC_WORD, 20, 8, 1); // max dist - - if (state == RADIOLIB_ERR_NONE) { - Serial.println(F("success!")); - } else { - Serial.print(F("failed, code ")); - Serial.println(state); - while (true); - } - - // some modules have an external RF switch - // controlled via two pins (RX enable, TX enable) - // to enable automatic control of the switch, - // call the following method - // RX enable: 8 - // TX enable: 7 - - radio.setRfSwitchPins(8, 7); - - // set the function that will be called - // when new packet is received - radio.setDio0Action(setFlag); - - #if defined(INITIATING_NODE) - // send the first packet on this node - Serial.print(F("[SX1272] Sending first packet ... ")); - transmissionState = radio.startTransmit("Hello World!"); - transmitFlag = true; - #else - // start listening for LoRa packets on this node - Serial.print(F("[SX1272] Starting to listen ... ")); - state = radio.startReceive(); - if (state == RADIOLIB_ERR_NONE) { - Serial.println(F("success!")); - } else { - Serial.print(F("failed, code ")); - Serial.println(state); - while (true); - } - #endif -} - -void loop() { - // check if the previous operation finished - if(operationDone) { - // disable the interrupt service routine while - // processing the data - enableInterrupt = false; - - // reset flag - operationDone = false; - - if(transmitFlag) { - // the previous operation was transmission, listen for response - // print the result - if (transmissionState == RADIOLIB_ERR_NONE) { - // packet was successfully sent - Serial.println(F("transmission finished!")); - - } else { - Serial.print(F("failed, code ")); - Serial.println(transmissionState); - - } - - // listen for response - radio.startReceive(); - transmitFlag = false; - - } else { - // the previous operation was reception - // print data and send another packet - String str; - int state = radio.readData(str); - - if (state == RADIOLIB_ERR_NONE) { - // packet was successfully received - Serial.println(F("[SX1272] Received packet!")); - - // print data of the packet - Serial.print(F("[SX1272] Data:\t\t")); - Serial.println(str); - - // print RSSI (Received Signal Strength Indicator) - Serial.print(F("[SX1272] RSSI:\t\t")); - Serial.print(radio.getRSSI()); - Serial.println(F(" dBm")); - - // print SNR (Signal-to-Noise Ratio) - Serial.print(F("[SX1272] SNR:\t\t")); - Serial.print(radio.getSNR()); - Serial.println(F(" dB")); - - // print frequency error - Serial.print(F("[SX1272] Frequ err:\t\t")); - Serial.print(radio.getFrequencyError(true)); - Serial.println(F(" Hz")); - - } else if (state == RADIOLIB_ERR_CRC_MISMATCH) { - // packet was received, but is malformed - Serial.println(F("[SX1272] CRC error!")); - - } else { - // some other error occurred - Serial.print(F("[SX1272] Failed, code ")); - Serial.println(state); - } - - Serial.println(F("-------------------------------------")); - - // wait a second before transmitting again - delay(10000); - - // send another one - Serial.print(F("[SX1272] Sending another packet ... ")); - transmissionState = radio.startTransmit("Hello World!"); - transmitFlag = true; - } - - - // we're ready to process more packets, - // enable interrupt service routine - enableInterrupt = true; - - } -} diff --git a/Arduino/SX127x_Receive_Interrupt/SX127x_Receive_Interrupt.ino b/Arduino/SX127x_Receive_Interrupt/SX127x_Receive_Interrupt.ino deleted file mode 100644 index db3bf10..0000000 --- a/Arduino/SX127x_Receive_Interrupt/SX127x_Receive_Interrupt.ino +++ /dev/null @@ -1,220 +0,0 @@ -/* - RadioLib SX127x Receive with Interrupts Example - - This example listens for LoRa transmissions and tries to - receive them. Once a packet is received, an interrupt is - triggered. To successfully receive data, the following - settings have to be the same on both transmitter - and receiver: - - carrier frequency - - bandwidth - - spreading factor - - coding rate - - sync word - - Other modules from SX127x/RFM9x family can also be used. - - For default module settings, see the wiki page - https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem - - For full API reference, see the GitHub Pages - https://jgromes.github.io/RadioLib/ -*/ - -// include the library -#include - -// SX1272 has the following connections: -// NSS pin: 10 -// DIO0 pin: 2 -// RESET pin: 9 -// DIO1 pin: 3 -SX1272 radio = new Module(10, 2, 9, 3); - -int state, increment = 0, rssi, meanRSSI = 0, rxLength; -float snr, meanSNR = 0; -String str; - -// or using RadioShield -// https://github.com/jgromes/RadioShield -//SX1272 radio = RadioShield.ModuleA; - -void setup() { - Serial.begin(9600); - - // initialize SX1272 with default settings - Serial.println(F("-------------------------------------")); - Serial.print(F("[SX1272] Initializing ... ")); - -/* - * "freq" in MHz. Allowed values range from 860.0 MHz to 1020.0 MHz. - * in EU - * "bw" bandwidth in kHz. 125, 250 and 500 kHz. - * "sf" spreading factor. From 6 to 12. - * "cr" coding rate denominator. From 5 to 8. - * "syncWord" sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks. - * "currentLimit" Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA. - * Set to 0 to disable OCP (not recommended). - * "preambleLength" Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number. - * From 6 to 65535. - * "gain" Gain of receiver LNA (low-noise amplifier). From 1 to 6 where 1 is the highest gain and 0 is auto - * - * int16_t begin(float freq = 915.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0); - */ - - int state = radio.begin(868, 125.0, 12, 8, RADIOLIB_SX127X_SYNC_WORD, 2, 6, 6); - //int state = radio.begin(866.4, 500.0, 7, 5, RADIOLIB_SX127X_SYNC_WORD, 2, 6, 6); // max bw - //int state = radio.begin(866.4, 125.0, 12, 5, RADIOLIB_SX127X_SYNC_WORD, 20, 8, 1); // max dist - - if (state == RADIOLIB_ERR_NONE) { - Serial.println(F("success!")); - } else { - Serial.print(F("failed, code ")); - Serial.println(state); - while (true); - } - - // some modules have an external RF switch - // controlled via two pins (RX enable, TX enable) - // to enable automatic control of the switch, - // call the following method - // RX enable: 8 - // TX enable: 7 - - radio.setRfSwitchPins(8, 7); - - // set the function that will be called - // when new packet is received - radio.setDio0Action(setFlag); - - // start listening for LoRa packets - Serial.print(F("[SX1272] Starting to listen ... ")); - state = radio.startReceive(); - if (state == RADIOLIB_ERR_NONE) { - Serial.println(F("success!")); - } else { - Serial.print(F("failed, code ")); - Serial.println(state); - while (true); - } - - // if needed, 'listen' mode can be disabled by calling - // any of the following methods: - // - // radio.standby() - // radio.sleep() - // radio.transmit(); - // radio.receive(); - // radio.readData(); - // radio.scanChannel(); -} - -// flag to indicate that a packet was received -volatile bool receivedFlag = false; - -// disable interrupt when it's not needed -volatile bool enableInterrupt = true; - -// this function is called when a complete packet -// is received by the module -// IMPORTANT: this function MUST be 'void' type -// and MUST NOT have any arguments! -void setFlag(void) { - // check if the interrupt is enabled - if(!enableInterrupt) { - return; - } - - // we got a packet, set the flag - receivedFlag = true; -} - -void printMsg(String data, int *dataLength, bool caret = true, bool hexad = true) { - if(hexad) { - char *hexa = "0123456789ABCDEF"; - for(int i = 0; i < *dataLength; i++) { - if (data[i] > 4095) Serial.print(hexa[data[i] / 4096]); - if (data[i] > 255) Serial.print(hexa[data[i] / 256 % 16]); // write ASCII value of hexadecimal high nibble - Serial.print(hexa[data[i] / 16 % 16]); // write ASCII value of hexadecimal high nibble - Serial.print(hexa[data[i] % 16]); // write ASCII value of hexadecimal low nibble - Serial.print(" "); - } - } else { - for(int i = 0; i < *dataLength; i++) { - Serial.print(data[i]); - Serial.print(" "); - } - } - if(caret) Serial.print("\r\n"); -} - -void loop() { - // check if the flag is set - if(receivedFlag) { - // disable the interrupt service routine while - // processing the data - enableInterrupt = false; - - // reset flag - receivedFlag = false; - - // you can read received data as an Arduino String - state = radio.readData(str); - - // you can also read received data as byte array - /* - byte byteArr[8]; - int state = radio.readData(byteArr, 8); - */ - - if (state == RADIOLIB_ERR_NONE) { - // packet was successfully received - Serial.println(F("[SX1272] Received packet!")); - - // print data of the packet - Serial.print(F("[SX1272] Data:\t")); - //Serial.println(str); - rxLength = radio.getPacketLength(); - printMsg(str, &rxLength); - - // print RSSI (Received Signal Strength Indicator) - Serial.print(F("[SX1272] RSSI:\t")); - Serial.print(rssi = ((int) radio.getRSSI())); - Serial.print(F(" dBm ")); - Serial.print(((meanRSSI += rssi) / ++increment)); - Serial.println(); - - // print SNR (Signal-to-Noise Ratio) - Serial.print(F("[SX1272] SNR:\t")); - Serial.print(snr = radio.getSNR()); - Serial.print(F(" dB ")); - Serial.print(((meanSNR += snr) / increment)); - Serial.println(); - - // print frequency error - Serial.print(F("[SX1272] Frq er:\t")); - Serial.print(radio.getFrequencyError(true)); - Serial.println(F(" Hz")); - - } else if (state == RADIOLIB_ERR_CRC_MISMATCH) { - // packet was received, but is malformed - Serial.println(F("[SX1272] CRC error!")); - - } else { - // some other error occurred - Serial.print(F("[SX1272] Failed, code ")); - Serial.println(state); - - } - - Serial.println(F("-------------------------------------")); - - // put module back to listen mode - radio.startReceive(); - - // we're ready to receive more packets, - // enable interrupt service routine - enableInterrupt = true; - } - -} diff --git a/Arduino/SX127x_SettingsTest/SX127x_SettingsTest.ino b/Arduino/SX127x_SettingsTest/SX127x_SettingsTest.ino deleted file mode 100644 index aa46fef..0000000 --- a/Arduino/SX127x_SettingsTest/SX127x_SettingsTest.ino +++ /dev/null @@ -1,137 +0,0 @@ -/* - RadioLib SX127x Settings Example - - This example shows how to change all the properties of LoRa transmission. - RadioLib currently supports the following settings: - - pins (SPI slave select, digital IO 0, digital IO 1) - - carrier frequency - - bandwidth - - spreading factor - - coding rate - - sync word - - output power during transmission - - Other modules from SX127x/RFM9x family can also be used. - - For default module settings, see the wiki page - https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem - - For full API reference, see the GitHub Pages - https://jgromes.github.io/RadioLib/ -*/ - -// include the library -#include - -// SX1272 has the following connections: -// NSS pin: 10 -// DIO0 pin: 2 -// RESET pin: 9 -// DIO1 pin: 3 -SX1272 radio = new Module(10, 2, 9, 3); - -// or using RadioShield -// https://github.com/jgromes/RadioShield -//SX1276 radio3 = RadioShield.ModuleB; - -void setup() { - Serial.begin(9600); - - // initialize SX1272 with default settings - Serial.print(F("[SX1272] Initializing ... ")); - int state = radio.begin(); - if (state == RADIOLIB_ERR_NONE) { - Serial.println(F("success!")); - } else { - Serial.print(F("failed, code ")); - Serial.println(state); - while (true); - } - - // some modules have an external RF switch - // controlled via two pins (RX enable, TX enable) - // to enable automatic control of the switch, - // call the following method - // RX enable: 8 - // TX enable: 7 - - radio.setRfSwitchPins(8, 7); - - // you can also change the settings at runtime - // and check if the configuration was changed successfully - - // set carrier frequency to 433.5 MHz - if (radio.setFrequency(868.0) == RADIOLIB_ERR_INVALID_FREQUENCY) { - Serial.println(F("Selected frequency is invalid for this module!")); - while (true); - } - Serial.println("Frequency change success"); - - // set bandwidth to 250 kHz - if (radio.setBandwidth(500.0) == RADIOLIB_ERR_INVALID_BANDWIDTH) { - Serial.println(F("Selected bandwidth is invalid for this module!")); - while (true); - } - Serial.println("Brandwith change success"); - - // set spreading factor to 10 - if (radio.setSpreadingFactor(7) == RADIOLIB_ERR_INVALID_SPREADING_FACTOR) { - Serial.println(F("Selected spreading factor is invalid for this module!")); - while (true); - } - Serial.println("Spreading factor change success"); - - // set coding rate to 6 - if (radio.setCodingRate(5) == RADIOLIB_ERR_INVALID_CODING_RATE) { - Serial.println(F("Selected coding rate is invalid for this module!")); - while (true); - } - Serial.println("Coding rate change success"); - - // set LoRa sync word to 0x14 - // NOTE: value 0x34 is reserved for LoRaWAN networks and should not be used - if (radio.setSyncWord(0x12) != RADIOLIB_ERR_NONE) { - Serial.println(F("Unable to set sync word!")); - while (true); - } - Serial.println("Sync word change success"); - - // set output power to 10 dBm (accepted range is -3 - 17 dBm) - // NOTE: 20 dBm value allows high power operation, but transmission - // duty cycle MUST NOT exceed 1% - if (radio.setOutputPower(2) == RADIOLIB_ERR_INVALID_OUTPUT_POWER) { - Serial.println(F("Selected output power is invalid for this module!")); - while (true); - } - Serial.println("Out power change success"); - - // set over current protection limit to 80 mA (accepted range is 45 - 240 mA) - // NOTE: set value to 0 to disable overcurrent protection - if (radio.setCurrentLimit(80) == RADIOLIB_ERR_INVALID_CURRENT_LIMIT) { - Serial.println(F("Selected current limit is invalid for this module!")); - while (true); - } - Serial.println("Current limit change success"); - - // set LoRa preamble length to 15 symbols (accepted range is 6 - 65535) - if (radio.setPreambleLength(6) == RADIOLIB_ERR_INVALID_PREAMBLE_LENGTH) { - Serial.println(F("Selected preamble length is invalid for this module!")); - while (true); - } - Serial.println("Preamble change success"); - - // set amplifier gain to 1 (accepted range is 1 - 6, where 1 is maximum gain) - // NOTE: set value to 0 to enable automatic gain control - // leave at 0 unless you know what you're doing - if (radio.setGain(1) == RADIOLIB_ERR_INVALID_GAIN) { - Serial.println(F("Selected gain is invalid for this module!")); - while (true); - } - Serial.println("Frequency change success"); - - Serial.println(F("All settings successfully changed!")); -} - -void loop() { - // nothing here -} diff --git a/Arduino/SX127x_Transmit/SX127x_Transmit.ino b/Arduino/SX127x_Transmit/SX127x_Transmit.ino deleted file mode 100644 index de966d0..0000000 --- a/Arduino/SX127x_Transmit/SX127x_Transmit.ino +++ /dev/null @@ -1,175 +0,0 @@ -/* - RadioLib SX127x Transmit Example - - This example transmits packets using SX1272 LoRa radio module. - Each packet contains up to 256 bytes of data, in the form of: - - Arduino String - - null-terminated char array (C-string) - - arbitrary binary data (byte array) - - Other modules from SX127x/RFM9x family can also be used. - - For default module settings, see the wiki page - https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem - - For full API reference, see the GitHub Pages - https://jgromes.github.io/RadioLib/ -*/ - -// include the library -#include -#include - -#define TIME_HEADER "T" // Header tag for serial time sync message -//#define TIME_REQUEST 7 // ASCII bell character requests a time sync message - -// SX1272 has the following connections: -// NSS pin: 10 -// DIO0 pin: 2 -// RESET pin: 9 -// DIO1 pin: 3 -SX1272 radio = new Module(10, 2, 9, 3); - -int increment = 0, state; -float DR, meanDR = 0; -const String str = "Packet nb"; - -// or using RadioShield -// https://github.com/jgromes/RadioShield -//SX1272 radio = RadioShield.ModuleA; - -void setup() { - Serial.begin(9600); - - // time init - //setSyncProvider(requestSync); //set function to call when sync required - Serial.println("Waiting for sync message"); - - // initialize SX1272 with default settings - Serial.println(F(" -------------------------------------")); - Serial.print(F("[SX1272] Initializing ... ")); - -/* - * "freq" in MHz. Allowed values range from 860.0 MHz to 1020.0 MHz. - * in EU - * "bw" bandwidth in kHz. 125, 250 and 500 kHz. - * "sf" spreading factor. From 6 to 12. - * "cr" coding rate denominator. From 5 to 8. - * "syncWord" sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks. - * "currentLimit" Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA. - * Set to 0 to disable OCP (not recommended). - * "preambleLength" Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number. - * From 6 to 65535. - * "gain" Gain of receiver LNA (low-noise amplifier). From 1 to 6 where 1 is the highest gain and 0 is auto - * - * int16_t begin(float freq = 915.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0); - */ - - - state = radio.begin(867.1, 500.0, 7, 5, RADIOLIB_SX127X_SYNC_WORD, 2, 6, 6); // max bw - //state = radio.begin(867.1, 125.0, 12, 5, RADIOLIB_SX127X_SYNC_WORD, 20, 8, 1); // max dist - - - - if (state == RADIOLIB_ERR_NONE) { - Serial.println(F("success!")); - } else { - Serial.print(F("failed, code ")); - Serial.println(state); - while (true); - } - - // some modules have an external RF switch - // controlled via two pins (RX enable, TX enable) - // to enable automatic control of the switch, - // call the following method - // RX enable: 8 - // TX enable: 7 - - radio.setRfSwitchPins(8, 7); -} - -void loop() { - - if (timeStatus() == timeNotSet && Serial.available()) { - processSyncMessage(); - } - - if (timeStatus() != timeNotSet) { - Serial.print(hour() + 1); - Serial.print(normalizeDigit(minute())); - Serial.print(normalizeDigit(second())); - } - - Serial.println(F(" -------------------------------------")); - Serial.print(F("[SX1272] Transmitting packet ... ")); - - // you can transmit C-string or Arduino string up to - // 256 characters long - // NOTE: transmit() is a blocking method! - // See example SX127x_Transmit_Interrupt for details - // on non-blocking transmission method. - if (timeStatus()== timeNotSet) { - state = radio.transmit(str + (++increment)); - } else state = radio.transmit(str + (++increment) + " " + (hour() + 1) + normalizeDigit(minute()) + normalizeDigit(second())); - - Serial.print(increment); - - // you can also transmit byte array up to 256 bytes long - /* - byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - int state = radio.transmit(byteArr, 8); - */ - - if (state == RADIOLIB_ERR_NONE) { - // the packet was successfully transmitted - Serial.println(F(" success!")); - - // print measured data rate - Serial.print(F("[SX1272] Datarate:\t")); - Serial.print(DR = radio.getDataRate()); - Serial.print(F(" bps ")); - Serial.print(((meanDR += DR) / increment)); - Serial.print(F(" or ")); - Serial.println((increment / meanDR * (str.length() + 3) * 1000)); - Serial.println(); - - } else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) { - // the supplied packet was longer than 256 bytes - Serial.println(F("too long!")); - - } else if (state == RADIOLIB_ERR_TX_TIMEOUT) { - // timeout occurred while transmitting packet - Serial.println(F("timeout!")); - - } else { - // some other error occurred - Serial.print(F("failed, code ")); - Serial.println(state); - } - - delay(10000); -} - -String normalizeDigit(int digits){ - if(digits < 10) return(":0" + (String)digits); - return(':' + (String)digits); -} - -void processSyncMessage() { - unsigned long pctime; - const unsigned long DEFAULT_TIME = 1357041600; // Jan 1 2013 - - if(Serial.find((char*)TIME_HEADER)) { - pctime = Serial.parseInt(); - if( pctime >= DEFAULT_TIME) { // check the integer is a valid time (greater than Jan 1 2013) - setTime(pctime + 15); // Sync Arduino clock to the time received on the serial port - } - } -} -/* -time_t requestSync() -{ - Serial.write(TIME_REQUEST); - return 0; // the time will be sent later in response to serial mesg -}*/ diff --git a/Arduino/SX127x_Transmit_WithoutTime/SX127x_Transmit_WithoutTime.ino b/Arduino/SX127x_Transmit_WithoutTime/SX127x_Transmit_WithoutTime.ino deleted file mode 100644 index 1bfba84..0000000 --- a/Arduino/SX127x_Transmit_WithoutTime/SX127x_Transmit_WithoutTime.ino +++ /dev/null @@ -1,135 +0,0 @@ -/* - RadioLib SX127x Transmit Example - - This example transmits packets using SX1272 LoRa radio module. - Each packet contains up to 256 bytes of data, in the form of: - - Arduino String - - null-terminated char array (C-string) - - arbitrary binary data (byte array) - - Other modules from SX127x/RFM9x family can also be used. - - For default module settings, see the wiki page - https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem - - For full API reference, see the GitHub Pages - https://jgromes.github.io/RadioLib/ -*/ - -// include the library -#include - -// SX1272 has the following connections: -// NSS pin: 10 -// DIO0 pin: 2 -// RESET pin: 9 -// DIO1 pin: 3 -SX1272 radio = new Module(10, 2, 9, 3); - -String str = "Packet nb"; -int increment = 0; -float DR, meanDR = 0; - -// or using RadioShield -// https://github.com/jgromes/RadioShield -//SX1272 radio = RadioShield.ModuleA; - -void setup() { - Serial.begin(9600); - - // initialize SX1272 with default settings - Serial.println(F("-------------------------------------")); - Serial.print(F("[SX1272] Initializing ... ")); - -/* - * "freq" in MHz. Allowed values range from 860.0 MHz to 1020.0 MHz. - * in EU - * "bw" bandwidth in kHz. 125, 250 and 500 kHz. - * "sf" spreading factor. From 6 to 12. - * "cr" coding rate denominator. From 5 to 8. - * "syncWord" sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks. - * "currentLimit" Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA. - * Set to 0 to disable OCP (not recommended). - * "preambleLength" Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number. - * From 6 to 65535. - * "gain" Gain of receiver LNA (low-noise amplifier). From 1 to 6 where 1 is the highest gain and 0 is auto - * - * int16_t begin(float freq = 915.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0); - */ - - - int state = radio.begin(867.1, 500.0, 7, 5, RADIOLIB_SX127X_SYNC_WORD, 20, 6, 0); - //int state = radio.begin(867.1, 500.0, 7, 5, RADIOLIB_SX127X_SYNC_WORD, 20, 6, 6); - //int state = radio.begin(867.1, 125.0, 12, 5, RADIOLIB_SX127X_SYNC_WORD, 20, 6, 0); - //int state = radio.begin(); - - - - - if (state == RADIOLIB_ERR_NONE) { - Serial.println(F("success!")); - } else { - Serial.print(F("failed, code ")); - Serial.println(state); - while (true); - } - - // some modules have an external RF switch - // controlled via two pins (RX enable, TX enable) - // to enable automatic control of the switch, - // call the following method - // RX enable: 8 - // TX enable: 7 - - radio.setRfSwitchPins(8, 7); -} - -void loop() { - Serial.print(F("[SX1272] Transmitting packet ... ")); - - // you can transmit C-string or Arduino string up to - // 256 characters long - // NOTE: transmit() is a blocking method! - // See example SX127x_Transmit_Interrupt for details - // on non-blocking transmission method. - - int state = radio.transmit(str + (++increment)); - Serial.print(increment); - - // you can also transmit byte array up to 256 bytes long - /* - byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - int state = radio.transmit(byteArr, 8); - */ - - if (state == RADIOLIB_ERR_NONE) { - // the packet was successfully transmitted - Serial.println(F(" success!")); - - // print measured data rate - Serial.print(F("[SX1272] Datarate:\t")); - Serial.print(DR = radio.getDataRate()); - Serial.print(F(" bps ")); - Serial.print(((meanDR += DR) / increment)); - Serial.print(F(" or ")); - Serial.println((increment / meanDR * (str.length() + 3) * 1000)); - - } else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) { - // the supplied packet was longer than 256 bytes - Serial.println(F("too long!")); - - } else if (state == RADIOLIB_ERR_TX_TIMEOUT) { - // timeout occurred while transmitting packet - Serial.println(F("timeout!")); - - } else { - // some other error occurred - Serial.print(F("failed, code ")); - Serial.println(state); - - } - - // wait for a second before transmitting again - Serial.println(F("-------------------------------------")); - delay(5000); -} diff --git a/Arduino/TestTransmit/TestTransmit.ino b/Arduino/TestTransmit/TestTransmit.ino deleted file mode 100644 index 562d750..0000000 --- a/Arduino/TestTransmit/TestTransmit.ino +++ /dev/null @@ -1,396 +0,0 @@ -/* - RadioLib SX127x Ping-Pong Example - - For default module settings, see the wiki page - https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem - - For full API reference, see the GitHub Pages - https://jgromes.github.io/RadioLib/ -*/ - -// include the library -#include - -#define TRANSMIT_HEADER "T" // Header tag for serial transmit message - -#define HEADER_0_POS 0 -#define HEADER_0 0x4E - -#define HEADER_1_POS 1 -#define HEADER_1 0xAD - -#define DEST_ID_POS 2 -#define SOURCE_ID_POS 3 -#define HEI_ID 0x01 -#define ISEN_ID 0x02 -#define MY_ID HEI_ID - -#define COMMAND_POS 4 -#define DISCOVER 0x01 -#define ASKING 0x02 -#define ABLE_MEASURE 0x03 -#define DISABLE_MEASURE 0x04 -#define ACK 0x05 -#define NACK 0x06 -#define TIMEOUT 0x42 -#define LED_ON 0x66 -#define LED_OFF 0x67 -#define PING 0x17 - -#define DATA_LONG_POS 5 -#define DATA_LONG 0x01 -#define NUL 0x00 - -#define DISCOVER_LONG 6 -#define ACK_LONG 5 -#define TRANSMIT_LONG (DATA_LONG + 4) -#define DISABLE_LONG 5 - -// SX1272 has the following connections: -// NSS pin: 10 -// DIO0 pin: 2 or 0 on rasp -// NRST pin: 9 or 7 on rasp -// DIO1 pin: 3 -SX1272 radio = new Module(10, 2, 9, 3); - -// save transmission states between loops -int state = RADIOLIB_ERR_NONE; - -// disable interrupt when it's not needed -volatile bool enableInterrupt = true; - -// flag to indicate that a packet was sent or received -volatile bool operationDone = false; - -void isSOk(void) { - if (state == RADIOLIB_ERR_NONE) { - Serial.println(F("success!")); - } else { - Serial.print(F("failed, code ")); - Serial.println(state); - } -} - -// this function is called when a complete packet -// is transmitted or received by the module -// IMPORTANT: this function MUST be 'void' type -// and MUST NOT have any arguments! -void setFlag(void) { - // check if the interrupt is enabled - if (!enableInterrupt) { - return; - } - - // we sent or received packet, set the flag - operationDone = true; -} - -void setup() { - Serial.begin(38400); - pinMode(4, OUTPUT); - - // initialize SX1272 with default settings - Serial.println(F("\n-------------------------------------")); - Serial.print(F("[SX1272] Initializing ... ")); - - state = radio.begin(868.0, 500.0, 12, 5, RADIOLIB_SX127X_SYNC_WORD, 2, 8, 6); // max bw - //state = radio.begin(866.4, 500.0, 7, 5, RADIOLIB_SX127X_SYNC_WORD, 2, 6, 6); // max bw - //int state = radio.begin(866.4, 125.0, 12, 5, RADIOLIB_SX127X_SYNC_WORD, 20, 8, 1); // max dist - - isSOk(); - - // some modules have an external RF switch - // controlled via two pins (RX enable, TX enable) - // to enable automatic control of the switch, - // call the following method - // RX enable: 8 or 3 on rasp - // TX enable: 7 or 2 on rasp - - radio.setRfSwitchPins(8, 7); - - // set the function that will be called - // when new packet is received - radio.setDio0Action(setFlag); - - //radio.setEncoding() // chiffrage -} // end of setup - -void printMsg(byte *data, int *dataLength, bool caret = true, bool hexad = true) { - if(hexad) { - char *hexa = "0123456789ABCDEF"; - for(int i = 0; i < dataLength; i++) { - if (data[i] > 4095) Serial.print(hexa[data[i] / 4096]); - if (data[i] > 255) Serial.print(hexa[data[i] / 256 % 16]); // write ASCII value of hexadecimal high nibble - Serial.print(hexa[data[i] / 16 % 16]); // write ASCII value of hexadecimal high nibble - Serial.print(hexa[data[i] % 16]); // write ASCII value of hexadecimal low nibble - Serial.print(" "); - } - } else { - for(int i = 0; i < dataLength; i++) { - Serial.print(data[i]); - Serial.print(" "); - } - } - if(caret) Serial.print("\r\n"); -} - -void printHex(byte data, bool caret = true, bool hexad = true) { - if(hexad) { - char *hexa = "0123456789ABCDEF"; - if (data > 4095) Serial.print(hexa[data / 4096]); - if (data > 255) Serial.print(hexa[data / 256 % 16]); // write ASCII value of hexadecimal high nibble - Serial.print(hexa[data / 16 % 16]); // write ASCII value of hexadecimal high nibble - Serial.print(hexa[data % 16]); // write ASCII value of hexadecimal low nibble - Serial.print(" "); - } else { - Serial.print(data); - Serial.print(" "); - } - if(caret) Serial.print("\r\n"); -} - -/* - * byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - * int state = radio.transmit(byteArr, 8); - */ - -/* - * RC5 MOSI 15 - * RC4 MISO 14 - * RC3 Clock 13 - * RC2 CS LoRa 16 - * RC1 CS Lcd - * RC0 CS Capteur - * RB4 RX Pic 5 - * RB3 TX Pic 4 - * RB2 Reset 12 - * - * #define HEADER_0_POS 0 - * #define HEADER_0 0x4E - * - * #define HEADER_1_POS 1 - * #define HEADER_1 0xAD - * - * #define NETWORK_ID_POS 2 - * #define NETWORK_ID 0x01 - * - * #define TARGET_ID_POS 3 - * #define TARGET_ID 0x01 - * - * #define COMMAND_POS 4 - * #define DISCOVER 0x01 - * #define ASKING 0x02 - * #define ABLE_MEASURE 0x03 - * #define DISABLE_MEASURE 0x04 - * #define ACK 0x05 - * #define NACK 0x06 - * #define TIMEOUT 0x42 - * #define LED_ON 0x66 - * #define LED_OFF 0x67 - * - * #define TYPE_CAPT_POS 4 - * #define TYPE_CAPT 0x01 - * - * #define DATA_LONG_POS 5 - * #define DATA_LONG 0x01 - * #define NUL 0x00 - * - * #define DISCOVER_LONG 6 - * #define ACK_LONG 5 - * #define TRANSMIT_LONG (DATA_LONG + 4) - * - * const uint8_t rxMsg[] = { 0x4E, 0xAD, 0x01, 0x04, 0x01 }; //Découverte Réseau Base - * const uint8_t txMsg[] = { 0xAD, 0x4E, 0x01, 0x04, 0x01, 0x01 }; //Réponse header + network + node 4 + température + 1 octet - * const uint8_t rxMsg[] = { 0x4E, 0xAD, 0x01, 0x04, 0x02 }; //Requête données - * const uint8_t txMsg[] = { 0xAD, 0x4E, 0x01, 0x04, 0x03 }; //Réponse header + network + node 4 + possible ou 04 impossible - * const uint8_t txMsg[] = { 0xAD, 0x4E, 0x01, 0x04, txMsg[i], lvlBatt }; //Réponse header + network + node 4 + possible ou 04 impossible - * const uint8_t rxMsg[] = { 0x4E, 0xAD, 0x01, 0x04, 0x05 }; //Accusé reception ou 06 demande renvoi - * - * uint8_t RXNumberOfBytes; // to store the number of bytes received - * uint8_t rxMsg[30]; // message reçu - * uint8_t txMsg[] = { HEADER_1, HEADER_0, NETWORK_ID, TARGET_ID, NUL, NUL, NUL, NUL, NUL }; // message transmit - */ - - -static char id = 1; -byte networkAvailable[] = { NUL, NUL, NUL, NUL, NUL }; // store ids of networks -int networkRssi[] = { NUL, NUL, NUL, NUL, NUL }; // store Rssi of networks -byte txMsg[] = { HEADER_0, HEADER_1, NUL, MY_ID, NUL, NUL, NUL, NUL, NUL }; // message transmit -byte rxMsg[6]; -int rxLength; -byte idInc = 0x01; -const bool debuglvl = true; - -int data = 0; - -void debug(void) { - if (state == RADIOLIB_ERR_NONE) { - // packet was successfully received - Serial.println(F("[SX1272] Received packet!")); - - // print data of the packet - Serial.print(F("[SX1272] Data:\t\t")); - printMsg(rxMsg, rxLength); - - // print RSSI (Received Signal Strength Indicator) - Serial.print(F("[SX1272] RSSI:\t\t")); - Serial.print((int)radio.getRSSI()); - //Serial.print(rssi = ((int) radio.getRSSI())); - Serial.print(F(" dBm ")); - //Serial.print(((meanRSSI += rssi) / ++increment)); - Serial.println(); - - // print SNR (Signal-to-Noise Ratio) - Serial.print(F("[SX1272] SNR:\t\t")); - Serial.print(radio.getSNR()); - //Serial.print(snr = radio.getSNR()); - Serial.print(F(" dB ")); - //Serial.print(((meanSNR += snr) / increment)); - Serial.println(); - - // print frequency error - Serial.print(F("[SX1272] Frequ err:\t\t")); - Serial.print(radio.getFrequencyError(false)); - Serial.println(F(" Hz")); - - } else if (state == RADIOLIB_ERR_CRC_MISMATCH) { - // packet was received, but is malformed - Serial.println(F("[SX1272] CRC error!")); - } else { - // some other error occurred - Serial.print(F("[SX1272] Failed, code ")); - Serial.println(state); - } -} - -void loop() { - if (Serial.available()) { - if(Serial.find((char*)TRANSMIT_HEADER)) { - enableInterrupt = false; - //T_HEADER, DEST, CMD - //T, ISEN_ID, LED_ON - //T 21 - - data = Serial.parseInt(); - Serial.println(data); - if (data < 100) { - txMsg[HEADER_0_POS] = HEADER_0; - txMsg[HEADER_1_POS] = HEADER_1; - txMsg[DEST_ID_POS] = (byte)(data / 10 % 10); - txMsg[SOURCE_ID_POS] = MY_ID; - if (data % 10) txMsg[COMMAND_POS] = LED_ON; - else txMsg[COMMAND_POS] = LED_OFF; - - Serial.print(F("[SX1272] Sending : ")); - printMsg(txMsg, 5); - state = radio.transmit(txMsg, 5); - //delay(5) // transmit est blocant - isSOk(); - } - } - } - - if (operationDone) { - // disable the interrupt service routine while - // processing the data - enableInterrupt = false; - - // reset flag - operationDone = false; - - rxLength = radio.getPacketLength(); - state = radio.readData(rxMsg, rxLength); - - Serial.print(F("received data: ")); - printMsg(rxMsg, rxLength); - if(debuglvl) debug(); - - if(rxMsg[HEADER_0_POS] == HEADER_0 && rxMsg[HEADER_1_POS] == HEADER_1 && rxMsg[DEST_ID_POS] == MY_ID) { - switch (rxMsg[COMMAND_POS]) { // type de message - case ACK: - Serial.println(F("Accuse reception")); - networkAvailable[idInc-1] = rxMsg[SOURCE_ID_POS]; - networkRssi[idInc-1] = (int)radio.getRSSI(); - idInc++; - if(idInc >= 0x05) idInc = 0x1; - if(idInc == MY_ID) idInc++; - break; - - case TIMEOUT: - Serial.println(F("Timeout")); - rxMsg[COMMAND_POS] = 0; - break; - - case LED_ON: - digitalWrite(4, HIGH); - Serial.println(F("Led ON")); - txMsg[HEADER_0_POS] = HEADER_1; - txMsg[HEADER_1_POS] = HEADER_0; - txMsg[DEST_ID_POS] = ISEN_ID; - txMsg[SOURCE_ID_POS] = MY_ID; - txMsg[COMMAND_POS] = ACK; - Serial.print(F("[SX1272] Sending : ")); - printMsg(txMsg, TRANSMIT_LONG); - state = radio.transmit(txMsg, TRANSMIT_LONG); - //delay(5) // transmit est blocant - isSOk(); - break; - - case LED_OFF: - digitalWrite(4, LOW); - Serial.println(F("Led OFF")); - txMsg[HEADER_0_POS] = HEADER_1; - txMsg[HEADER_1_POS] = HEADER_0; - txMsg[DEST_ID_POS] = ISEN_ID; - txMsg[SOURCE_ID_POS] = MY_ID; - txMsg[COMMAND_POS] = ACK; - Serial.print(F("[SX1272] Sending : ")); - printMsg(txMsg, TRANSMIT_LONG); - state = radio.transmit(txMsg, TRANSMIT_LONG); - //delay(5) // transmit est blocant - isSOk(); - break; - - case PING: - Serial.print(F("Pinging from ")); - printHex(rxMsg[SOURCE_ID_POS], false); - Serial.print(F("to ")); - printHex(rxMsg[DEST_ID_POS]); - - if(rxMsg[DEST_ID_POS] != MY_ID) break; - - Serial.println(F("Pong")); - txMsg[HEADER_0_POS] = HEADER_1; - txMsg[HEADER_1_POS] = HEADER_0; - txMsg[DEST_ID_POS] = ISEN_ID; - txMsg[SOURCE_ID_POS] = MY_ID; - txMsg[COMMAND_POS] = ACK; - - Serial.print(F("[SX1272] Sending : ")); - printMsg(txMsg, ACK_LONG); - - state = radio.transmit(txMsg, ACK_LONG); - //delay(5) // transmit est blocant - isSOk(); - break; - - default: - Serial.println(F("error")); - - } // end of switch case - - } else { // end of if - Serial.print(F("[SX1272] Data:\t\t")); - printMsg(rxMsg, rxLength); - } - - Serial.println(F("-------------------------------------")); - - } // end of if opdone - - // put module back to listen mode - radio.startReceive(); - enableInterrupt = true; // enable interrupt - delay(1000); - -} // end of loop diff --git a/Lora/Makefile b/Lora/Makefile new file mode 100644 index 0000000..af8d1f8 --- /dev/null +++ b/Lora/Makefile @@ -0,0 +1,32 @@ +CC:=gcc +CFLAGS:=-Wall -Wextra +SOURCE:=src +BUILD:=obj +SRC:=$(wildcard $(SOURCE)/*.c) +OBJ:=$(addprefix $(BUILD)/, $(notdir $(SRC:.c=.o))) +EXEC:=TestLora +FINAL:=Init Receive Transmit +BASE:=filecsv.o gpio_util.o RF_LoRa_868_SO.o sendRecept.o SX1272.o + +all: $(FINAL) + +$(EXEC): $(OBJ) + $(CC) -o $(BIN)/$@ $^ $(CFLAGS) + +$(BUILD)/%.o: $(SOURCE)/%.c + $(CC) -o $@ -c $< $(CFLAGS) + +Init: $(OBJ) + $(CC) -o $@ $(addprefix $(BUILD)/, $(BASE)) $(BUILD)/$@.o $(CFLAGS) + +Receive: $(OBJ) + $(CC) -o $@ $(addprefix $(BUILD)/, $(BASE)) $(BUILD)/$@.o $(CFLAGS) + +Transmit: $(OBJ) + $(CC) -o $@ $(addprefix $(BUILD)/, $(BASE)) $(BUILD)/$@.o $(CFLAGS) + +clean: + rm -vrf $(BUILD)/*.o + +cleanall: clean + rm -vrf $(EXEC) $(FINAL) data.csv info_debug.txt \ No newline at end of file diff --git a/Rasp/Init.c b/Lora/src/Init.c similarity index 100% rename from Rasp/Init.c rename to Lora/src/Init.c diff --git a/Rasp/RF_LoRa_868_SO.c b/Lora/src/RF_LoRa_868_SO.c similarity index 100% rename from Rasp/RF_LoRa_868_SO.c rename to Lora/src/RF_LoRa_868_SO.c diff --git a/Rasp/RF_LoRa_868_SO.h b/Lora/src/RF_LoRa_868_SO.h similarity index 100% rename from Rasp/RF_LoRa_868_SO.h rename to Lora/src/RF_LoRa_868_SO.h diff --git a/Rasp/Receive.c b/Lora/src/Receive.c similarity index 97% rename from Rasp/Receive.c rename to Lora/src/Receive.c index 4c490d1..6248514 100644 --- a/Rasp/Receive.c +++ b/Lora/src/Receive.c @@ -1,176 +1,176 @@ -/* - * File: Receive.c - * Author: Fabien AMELINCK - * - * Created on 13 April 2022 - */ - -#include -#include -#include -#include -#include -#include -#include -#include "gpio_util.h" -#include "SX1272.h" -#include "RF_LoRa_868_SO.h" -#include "sendRecept.h" -#include "filecsv.h" - -#define debug 1 -#define useInit - -//#define MY_ID ISEN_ID - -int main(int argc, char *argv[]) { - - uint8_t NodeData[255]; // data sent by a node - - uint8_t TxBuffer[50]; // buffer containing data to write in SX1272 FIFO before transmission - uint8_t RxBuffer[50]; // buffer containing data read from SX1272 FIFO after reception - - uint8_t NbBytesReceived; // length of the received payload - // (after reception, read from dedicated register REG_RX_NB_BYTES) - //uint8_t PayloadLength; // length of the transmitted payload - // (before transmission, must be stored in the dedicated register REG_PAYLOAD_LENGTH_LORA) - - uint8_t CRCError; // returned by functions WaitIncomingMessageRXContinuous and WaitIncomingMessageRXSingle - // 0 => no CRC error in the received message - // 1 => CRC error in the received message - - uint8_t TimeoutOccured = 0; // written by function WaitIncomingMessageRXSingle - // 0 => a message was received before end of timeout (no timeout occured) - // 1 => timeout occured before reception of any message - - if (init_spi()) return -1; - - // Configure the pin used for RESET of LoRa transceiver - // here: physical pin n°38 (GPIO20) - create_port(20); - set_port_direction(20, 1); - - // Configure the pin used for RX_SWITCH of LoRa transceiver - // here: physical pin n°29 (GPIO5) - create_port(5); - set_port_direction(5, 0); - set_port_value(5, 0); - - // Configure the pin used for TX_SWITCH of LoRa transceiver - // here: physical pin n°31 (GPIO6) - create_port(6); - set_port_direction(6, 0); - if (set_port_value(6, 0)) { - fprintf(stdout, "Bug in port openning, please retry"); - return -1; - } - - // Configure the pin used for LED - // here: physical pin n°40 (GPIO21) - /*create_port(21); - set_port_direction(21, 0); - set_port_value(21, 0);*/ - - #ifndef useInit - ResetModule(); - - if (ReadSXRegister(REG_VERSION) != 0x22) { - fprintf(stdout, "Wrong module or not working !"); - return -1; - } - - // put module in LoRa mode (see SX1272 datasheet page 107) - WriteSXRegister(REG_OP_MODE, FSK_SLEEP_MODE); // SLEEP mode required first to switch from FSK to LoRa - WriteSXRegister(REG_OP_MODE, LORA_SLEEP_MODE); // switch from FSK mode to LoRa mode - WriteSXRegister(REG_OP_MODE, LORA_STANDBY_MODE); // STANDBY mode required for FIFO loading - usleep(100000); // delay since switching mode takes time - - // clearing buffers - // memset(inbuf, 0, sizeof inbuf); - // memset(outbuf, 0, sizeof outbuf); - - //InitModule(freq, bw, sf, cr, sync, preamble, pout, gain, rxtimeout, hder, crc); - InitModule(CH_17_868, BW_500, SF_12, CR_5, 0x12, 0x08, 2, G1, 0x00, HEADER_ON, CRC_ON); - #endif - - if (argc > 1) { - #if debug - fprintf(stdout, "args %d", argc); // Printing all args passed during call - for (uint8_t i = 0; i < argc; i++) { - fprintf(stdout, " %s", argv[i]); - } - fprintf(stdout, "\n"); - #endif - - #ifndef MY_ID - uint8_t MY_ID = (uint8_t) atoi(argv[1]); - #endif - - uint8_t received = 0, loop = 0, maxLoop = 10; - if (argc == 3) maxLoop = atoi(argv[2]); - - while (!received && loop < maxLoop) { - if (argc == 3) CRCError = WaitIncomingMessageRXSingle(&TimeoutOccured); - else CRCError = WaitIncomingMessageRXContinuous(); - - if (TimeoutOccured) { - #if debug - //fprintf(stdout, "Pas de reponse\n"); - #endif - } else if (CRCError) { - #if debug - fprintf(stdout, "CRC Error!\n"); - #endif - } else { - received = 1; - clock_t t1 = clock(); - - int8_t RSSI = LoadRxBufferWithRxFifo(RxBuffer, &NbBytesReceived); // addresses of RxBuffer and NbBytesReceived are passed to function LoadRxBufferWithRxFifo - // in order to update the values of their content - #if debug - fprintf(stdout, "RSSI = %d\n", RSSI); - #endif - - if (RxBuffer[HEADER_0_POS] == HEADER_0 - && RxBuffer[HEADER_1_POS] == HEADER_1 - && RxBuffer[DEST_ID_POS] == MY_ID) { - - TxBuffer[HEADER_0_POS] = HEADER_1; - TxBuffer[HEADER_1_POS] = HEADER_0; - TxBuffer[DEST_ID_POS] = RxBuffer[SOURCE_ID_POS]; - TxBuffer[SOURCE_ID_POS] = MY_ID; - TxBuffer[COMMAND_POS] = ACK; - - LoadTxFifoWithTxBuffer(TxBuffer, COMMAND_LONG); // address of TxBuffer and value of PayloadLength are passed to function LoadTxFifoWithTxBuffer - // in order to read the values of their content and copy them in SX1272 registers - TransmitLoRaMessage(); - - fprintf(stdout, "%fms\n", (float)(clock()-t1)/CLOCKS_PER_SEC); - - for (uint8_t i = 0; i < NbBytesReceived - 4; i++) NodeData[i] = RxBuffer[i + 4]; - WriteDataInFile(&RxBuffer[SOURCE_ID_POS], &NbBytesReceived, NodeData, &RSSI); - - if (RxBuffer[COMMAND_POS] == DISCOVER) { - fprintf(stdout, "D%d,%d\n", RxBuffer[SOURCE_ID_POS], RSSI); - } else if (RxBuffer[COMMAND_POS] == DATA) { - fprintf(stdout, "T%d,%d,%d,%d,%d\n", RxBuffer[SENSOR_ID_POS], RxBuffer[T_POS], RxBuffer[O_POS], RxBuffer[DEST_ID_POS], RxBuffer[SOURCE_ID_POS]); - } else if (RxBuffer[COMMAND_POS] == ACK_ZIGBEE) { - fprintf(stdout, "A%d,%d,%d,%d,%d\n", RxBuffer[SENSOR_ID_POS], RxBuffer[ACK_POS], RxBuffer[R_POS], RxBuffer[DEST_ID_POS], RxBuffer[SOURCE_ID_POS]); - } else if (RxBuffer[COMMAND_POS] == LED_ON) { - fprintf(stdout, "LED_ON\n"); - } else if (RxBuffer[COMMAND_POS] == LED_OFF) { - fprintf(stdout, "LED_OFF\n"); - } - } - } - loop++; - } // end of while - if (!received) { - #if debug - fprintf(stdout, "Pas de reponse\n"); - #endif - } - } // end of if - else fprintf(stdout, "Error nb args, usage : \n"); - return 0; -} // end of main +/* + * File: Receive.c + * Author: Fabien AMELINCK + * + * Created on 13 April 2022 + */ + +#include +#include +#include +#include +#include +#include +#include +#include "gpio_util.h" +#include "SX1272.h" +#include "RF_LoRa_868_SO.h" +#include "sendRecept.h" +#include "filecsv.h" + +#define debug 1 +#define useInit + +//#define MY_ID ISEN_ID + +int main(int argc, char *argv[]) { + + uint8_t NodeData[255]; // data sent by a node + + uint8_t TxBuffer[50]; // buffer containing data to write in SX1272 FIFO before transmission + uint8_t RxBuffer[50]; // buffer containing data read from SX1272 FIFO after reception + + uint8_t NbBytesReceived; // length of the received payload + // (after reception, read from dedicated register REG_RX_NB_BYTES) + //uint8_t PayloadLength; // length of the transmitted payload + // (before transmission, must be stored in the dedicated register REG_PAYLOAD_LENGTH_LORA) + + uint8_t CRCError; // returned by functions WaitIncomingMessageRXContinuous and WaitIncomingMessageRXSingle + // 0 => no CRC error in the received message + // 1 => CRC error in the received message + + uint8_t TimeoutOccured = 0; // written by function WaitIncomingMessageRXSingle + // 0 => a message was received before end of timeout (no timeout occured) + // 1 => timeout occured before reception of any message + + if (init_spi()) return -1; + + // Configure the pin used for RESET of LoRa transceiver + // here: physical pin n°38 (GPIO20) + create_port(20); + set_port_direction(20, 1); + + // Configure the pin used for RX_SWITCH of LoRa transceiver + // here: physical pin n°29 (GPIO5) + create_port(5); + set_port_direction(5, 0); + set_port_value(5, 0); + + // Configure the pin used for TX_SWITCH of LoRa transceiver + // here: physical pin n°31 (GPIO6) + create_port(6); + set_port_direction(6, 0); + if (set_port_value(6, 0)) { + fprintf(stdout, "Bug in port openning, please retry"); + return -1; + } + + // Configure the pin used for LED + // here: physical pin n°40 (GPIO21) + /*create_port(21); + set_port_direction(21, 0); + set_port_value(21, 0);*/ + + #ifndef useInit + ResetModule(); + + if (ReadSXRegister(REG_VERSION) != 0x22) { + fprintf(stdout, "Wrong module or not working !"); + return -1; + } + + // put module in LoRa mode (see SX1272 datasheet page 107) + WriteSXRegister(REG_OP_MODE, FSK_SLEEP_MODE); // SLEEP mode required first to switch from FSK to LoRa + WriteSXRegister(REG_OP_MODE, LORA_SLEEP_MODE); // switch from FSK mode to LoRa mode + WriteSXRegister(REG_OP_MODE, LORA_STANDBY_MODE); // STANDBY mode required for FIFO loading + usleep(100000); // delay since switching mode takes time + + // clearing buffers + // memset(inbuf, 0, sizeof inbuf); + // memset(outbuf, 0, sizeof outbuf); + + //InitModule(freq, bw, sf, cr, sync, preamble, pout, gain, rxtimeout, hder, crc); + InitModule(CH_17_868, BW_500, SF_12, CR_5, 0x12, 0x08, 2, G1, 0x00, HEADER_ON, CRC_ON); + #endif + + if (argc > 1) { + #if debug + fprintf(stdout, "args %d", argc); // Printing all args passed during call + for (uint8_t i = 0; i < argc; i++) { + fprintf(stdout, " %s", argv[i]); + } + fprintf(stdout, "\n"); + #endif + + #ifndef MY_ID + uint8_t MY_ID = (uint8_t) atoi(argv[1]); + #endif + + uint8_t received = 0, loop = 0, maxLoop = 10; + if (argc == 3) maxLoop = atoi(argv[2]); + + while (!received && loop < maxLoop) { + if (argc == 3) CRCError = WaitIncomingMessageRXSingle(&TimeoutOccured); + else CRCError = WaitIncomingMessageRXContinuous(); + + if (TimeoutOccured) { + #if debug + //fprintf(stdout, "Pas de reponse\n"); + #endif + } else if (CRCError) { + #if debug + fprintf(stdout, "CRC Error!\n"); + #endif + } else { + received = 1; + clock_t t1 = clock(); + + int8_t RSSI = LoadRxBufferWithRxFifo(RxBuffer, &NbBytesReceived); // addresses of RxBuffer and NbBytesReceived are passed to function LoadRxBufferWithRxFifo + // in order to update the values of their content + #if debug + fprintf(stdout, "RSSI = %d\n", RSSI); + #endif + + if (RxBuffer[HEADER_0_POS] == HEADER_0 + && RxBuffer[HEADER_1_POS] == HEADER_1 + && RxBuffer[DEST_ID_POS] == MY_ID) { + + TxBuffer[HEADER_0_POS] = HEADER_1; + TxBuffer[HEADER_1_POS] = HEADER_0; + TxBuffer[DEST_ID_POS] = RxBuffer[SOURCE_ID_POS]; + TxBuffer[SOURCE_ID_POS] = MY_ID; + TxBuffer[COMMAND_POS] = ACK; + + LoadTxFifoWithTxBuffer(TxBuffer, COMMAND_LONG); // address of TxBuffer and value of PayloadLength are passed to function LoadTxFifoWithTxBuffer + // in order to read the values of their content and copy them in SX1272 registers + TransmitLoRaMessage(); + + fprintf(stdout, "%fms\n", (float)(clock()-t1)/CLOCKS_PER_SEC); + + for (uint8_t i = 0; i < NbBytesReceived - 4; i++) NodeData[i] = RxBuffer[i + 4]; + WriteDataInFile(&RxBuffer[SOURCE_ID_POS], &NbBytesReceived, NodeData, &RSSI); + + if (RxBuffer[COMMAND_POS] == DISCOVER) { + fprintf(stdout, "D%d,%d\n", RxBuffer[SOURCE_ID_POS], RSSI); + } else if (RxBuffer[COMMAND_POS] == DATA) { + fprintf(stdout, "T%d,%d,%d,%d,%d\n", RxBuffer[SENSOR_ID_POS], RxBuffer[T_POS], RxBuffer[O_POS], RxBuffer[DEST_ID_POS], RxBuffer[SOURCE_ID_POS]); + } else if (RxBuffer[COMMAND_POS] == ACK_ZIGBEE) { + fprintf(stdout, "A%d,%d,%d,%d,%d\n", RxBuffer[SENSOR_ID_POS], RxBuffer[ACK_POS], RxBuffer[R_POS], RxBuffer[DEST_ID_POS], RxBuffer[SOURCE_ID_POS]); + } else if (RxBuffer[COMMAND_POS] == LED_ON) { + fprintf(stdout, "LED_ON\n"); + } else if (RxBuffer[COMMAND_POS] == LED_OFF) { + fprintf(stdout, "LED_OFF\n"); + } + } + } + loop++; + } // end of while + if (!received) { + #if debug + fprintf(stdout, "Pas de reponse\n"); + #endif + } + } // end of if + else fprintf(stdout, "Error nb args, usage : \n"); + return 0; +} // end of main diff --git a/Rasp/SX1272.c b/Lora/src/SX1272.c similarity index 100% rename from Rasp/SX1272.c rename to Lora/src/SX1272.c diff --git a/Rasp/SX1272.h b/Lora/src/SX1272.h similarity index 100% rename from Rasp/SX1272.h rename to Lora/src/SX1272.h diff --git a/Rasp/TestLora.c b/Lora/src/TestLora.c similarity index 100% rename from Rasp/TestLora.c rename to Lora/src/TestLora.c diff --git a/Rasp/Transmit.c b/Lora/src/Transmit.c similarity index 100% rename from Rasp/Transmit.c rename to Lora/src/Transmit.c diff --git a/Rasp/filecsv.c b/Lora/src/filecsv.c similarity index 100% rename from Rasp/filecsv.c rename to Lora/src/filecsv.c diff --git a/Rasp/filecsv.h b/Lora/src/filecsv.h similarity index 100% rename from Rasp/filecsv.h rename to Lora/src/filecsv.h diff --git a/Rasp/gpio_util.c b/Lora/src/gpio_util.c similarity index 100% rename from Rasp/gpio_util.c rename to Lora/src/gpio_util.c diff --git a/Rasp/gpio_util.h b/Lora/src/gpio_util.h similarity index 100% rename from Rasp/gpio_util.h rename to Lora/src/gpio_util.h diff --git a/Rasp/sendRecept.c b/Lora/src/sendRecept.c similarity index 100% rename from Rasp/sendRecept.c rename to Lora/src/sendRecept.c diff --git a/Rasp/sendRecept.h b/Lora/src/sendRecept.h similarity index 100% rename from Rasp/sendRecept.h rename to Lora/src/sendRecept.h diff --git a/Rasp/Makefile b/Rasp/Makefile deleted file mode 100644 index 85050b9..0000000 --- a/Rasp/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -CC=gcc -CFLAGS=-Wall -Wextra -EXEC=TestLora -SRC=$(wildcard *.c) -OBJ=$(SRC:.c=.o) -FINAL=Init Receive Transmit -BASE=SX1272.o gpio_util.o RF_LoRa_868_SO.o filecsv.o sendRecept.o - -all: $(FINAL) -# make clean - -$(EXEC): $(OBJ) - $(CC) -o $@ $^ $(CFLAGS) - -%.o: %.c - $(CC) -o $@ -c $< $(CFLAGS) - -Init: $(OBJ) - $(CC) -o $@ $(BASE) $@.o $(CFLAGS) - -Receive: $(OBJ) - $(CC) -o $@ $(BASE) $@.o $(CFLAGS) - -Transmit: $(OBJ) - $(CC) -o $@ $(BASE) $@.o $(CFLAGS) - -clean: - rm -vrf *.o - -cleanall: clean - rm -vrf $(EXEC) $(FINAL) data.csv info_debug.txt \ No newline at end of file diff --git a/Zolertia/allumageled.py b/Rasp/Test/allumageled.py similarity index 100% rename from Zolertia/allumageled.py rename to Rasp/Test/allumageled.py diff --git a/Zolertia/client_order.py b/Rasp/Test/client_order.py similarity index 100% rename from Zolertia/client_order.py rename to Rasp/Test/client_order.py diff --git a/Zolertia/testLora.py b/Rasp/Test/testLora.py similarity index 70% rename from Zolertia/testLora.py rename to Rasp/Test/testLora.py index 547dd96..46cecd7 100644 --- a/Zolertia/testLora.py +++ b/Rasp/Test/testLora.py @@ -7,7 +7,7 @@ if True: print("Initializing LoRa module") - proc = subprocess.Popen(["../Rasp/Init"], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) + proc = subprocess.Popen(["../../Rasp/Init"], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) print(proc) # initializing lora module stdout, stderr = proc.communicate(timeout=15) @@ -17,7 +17,7 @@ if False: print("Transmitting a LED_ON order") - proc = subprocess.Popen(["../Rasp/Transmit", "T", destNet, myNet, "1", "1", "1"], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) + proc = subprocess.Popen(["../../Rasp/Transmit", "T", destNet, myNet, "1", "1", "1"], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) print(proc) # turn on the led stdout, stderr = proc.communicate(timeout=15) @@ -27,7 +27,7 @@ if True: print("Waiting for a LoRa packet") - proc = subprocess.Popen(["../Rasp/Receive", myNet, "20"], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) + proc = subprocess.Popen(["../../Rasp/Receive", myNet, "20"], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) print(proc) # Waiting for zigbee ack stdout, stderr = proc.communicate(timeout=60) @@ -39,7 +39,7 @@ if False: print("Transmitting a LED_OFF order") - proc = subprocess.Popen(["../Rasp/Transmit", "T", destNet, myNet, "1", "1", "0"], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) + proc = subprocess.Popen(["../../Rasp/Transmit", "T", destNet, myNet, "1", "1", "0"], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) print(proc) # shut off the led stdout, stderr = proc.communicate(timeout=15) @@ -49,7 +49,7 @@ if True: print("Waiting for a LoRa packet") - proc = subprocess.Popen(["../Rasp/Receive", 1, "20"], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) + proc = subprocess.Popen(["../../Rasp/Receive", 1, "20"], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) print(proc) # waiting for zigbee ack stdout, stderr = proc.communicate(timeout=60) diff --git a/Zolertia/raspb_Z1.py b/Rasp/raspb_Z1.py similarity index 88% rename from Zolertia/raspb_Z1.py rename to Rasp/raspb_Z1.py index f2fc514..193c4dc 100644 --- a/Zolertia/raspb_Z1.py +++ b/Rasp/raspb_Z1.py @@ -27,7 +27,7 @@ ) class Receive(Thread): - def __init__(self, loop = 10): + def __init__(self, loop = 1): Thread.__init__(self) self.loraReceived = False # the thread initialise the flag of lora reception self.loop = loop # numper of loop in reception mode, time for a loop is determined by SF and BW @@ -35,7 +35,7 @@ def __init__(self, loop = 10): def run(self): try: print("thread start", self.loraReceived) - proc = subprocess.Popen(["../Rasp/Receive", myNet, str(self.loop)], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) # this function allows to start the sub-process + proc = subprocess.Popen(["../Lora/Receive", myNet, str(self.loop)], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) # this function allows to start the sub-process #print(proc) stdout, stderr = proc.communicate(timeout=300) print("Output:\n", stdout.decode('utf-8'), stderr.decode('utf-8')) @@ -98,9 +98,9 @@ def my_debug_message(msg): myNet = key""" print("Init LoRa Module") -proc = subprocess.Popen(["../Rasp/Init"], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) +proc = subprocess.Popen(["../Lora/Init"], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) stdout, stderr = proc.communicate(timeout=10) -proc = subprocess.Popen(["../Rasp/Init"], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) # bug at startup with the GPIO +proc = subprocess.Popen(["../Lora/Init"], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) # bug at startup with the GPIO print(proc) stdout, stderr = proc.communicate(timeout=10) # print("Output:\n", stdout.decode('utf-8'), stderr.decode('utf-8')) @@ -150,27 +150,28 @@ def my_debug_message(msg): print("Publishing on the server ") elif ( (str(zolertiadicback["NETD"]) in NETWORK ) and NETWORK[str(zolertiadicback["NETD"])]==False ): print("Sending to the lora module") - proc = subprocess.Popen(["../Rasp/Init"], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) + proc = subprocess.Popen(["../Lora/Init"], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) thread_1.join() # we close the reception thread before transmission + #penser à enculer le thread threadInitiated = False TimeTLora = time.time() if "ACK" in zolertiadicback.keys(): # return message processing if str(zolertiadicback["R"]) == "led_on" or zolertiadicback["R"] == 1: - proc = subprocess.Popen(["../Rasp/Transmit", "A", str(zolertiadicback["NETD"]), myNet, str(zolertiadicback["ID"]), str(zolertiadicback["ACK"]), "1"], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) - # ex : ../Rasp/Transmit A NETD NETS SENDORID ACK R - # ex : ../Rasp/Transmit A 1 2 1 1 1 + proc = subprocess.Popen(["../Lora/Transmit", "A", str(zolertiadicback["NETD"]), myNet, str(zolertiadicback["ID"]), str(zolertiadicback["ACK"]), "1"], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) + # ex : ../Lora/Transmit A NETD NETS SENDORID ACK R + # ex : ../Lora/Transmit A 1 2 1 1 1 elif str(zolertiadicback["R"]) == "led_off" or zolertiadicback["R"] == 0: - proc = subprocess.Popen(["../Rasp/Transmit", "A", str(zolertiadicback["NETD"]), myNet, str(zolertiadicback["ID"]), str(zolertiadicback["ACK"]), "0"], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) - # ex : ../Rasp/Transmit A NETD NETS SENDORID ACK R - # ex : ../Rasp/Transmit A 1 2 1 1 0 + proc = subprocess.Popen(["../Lora/Transmit", "A", str(zolertiadicback["NETD"]), myNet, str(zolertiadicback["ID"]), str(zolertiadicback["ACK"]), "0"], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) + # ex : ../Lora/Transmit A NETD NETS SENDORID ACK R + # ex : ../Lora/Transmit A 1 2 1 1 0 else: - proc = subprocess.Popen(["../Rasp/Transmit", "A", str(zolertiadicback["NETD"]), myNet, str(zolertiadicback["ID"]), "0", "0"], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) - # ex : ../Rasp/Transmit A NETD NETS SENDORID ACK R - # ex : ../Rasp/Transmit A 1 2 1 0 0 + proc = subprocess.Popen(["../Lora/Transmit", "A", str(zolertiadicback["NETD"]), myNet, str(zolertiadicback["ID"]), "0", "0"], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) + # ex : ../Lora/Transmit A NETD NETS SENDORID ACK R + # ex : ../Lora/Transmit A 1 2 1 0 0 else: - proc = subprocess.Popen(["../Rasp/Transmit", "T", str(network["NETD"]), myNet, str(network["ID"]), str(network["T"]), str(network["O"])], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) - # ex : ../Rasp/Transmit T NETD NETS SENDORID T O - # ex : ../Rasp/Transmit A 1 2 1 1 1 + proc = subprocess.Popen(["../Lora/Transmit", "T", str(network["NETD"]), myNet, str(network["ID"]), str(network["T"]), str(network["O"])], shell=False, stderr=subprocess.PIPE, stdout=subprocess.PIPE) + # ex : ../Lora/Transmit T NETD NETS SENDORID T O + # ex : ../Lora/Transmit A 1 2 1 1 1 print(proc) stdout, stderr = proc.communicate(timeout=15) elapsed = time.time() - TimeTLora diff --git a/Zolertia/raspb_ZNm2led.py b/Rasp/raspb_ZN.py similarity index 100% rename from Zolertia/raspb_ZNm2led.py rename to Rasp/raspb_ZN.py diff --git a/Zolertia/relayZ.py b/Rasp/relayZ.py similarity index 100% rename from Zolertia/relayZ.py rename to Rasp/relayZ.py diff --git a/Zolertia/raspb_ZN.py b/Zolertia/raspb_ZN.py deleted file mode 100644 index 1a57b6f..0000000 --- a/Zolertia/raspb_ZN.py +++ /dev/null @@ -1,185 +0,0 @@ -""" -This scripts simulates sensor reading and actions on equipments of our network. It also writes the messages we send back to Z1. -The boolean "simul" must be set to False if you are manipulating real equipment with grovepi. Otherwise, set it to True, and the leds/fans will only be represented by variables. - -authors : Mahraz Anass and Robyns Jonathan -""" - -simul = False # boolean set tro true if we use mock data, false if we use real leds - -import json -import time -import serial -if not simul: - from grovepi import * -from datetime import datetime -import pytz -import random - -ser = serial.Serial( - port='/dev/ttyUSB0', - baudrate = 115200, -) - -leds = [0,0,0] # mock data. Represents the three leds (id 1, 24 and 182). 1 for on and 0 for off -fans = [0,0] # mock data. Represents the theree fans's speeds (id 102 and 144) - -order_back = {"ID": None, "ACK": None, "R": None, "NET":None} # The message we send back to Z1 - -def my_debug_message(msg): - """ - msg (string) : debug message to write in infor_debug.txt - - This fonction has no return value. It simply writes msg in "info_debug.txt" - """ - with open("info_debug.txt",'a') as debug_file: - debug_file.write(msg) - debug_file.write("\n") - - -def setLeds(i,id,val): - """ - i (int) : index of the led in the leds list - id (int) : id of the led - val (int) : 1 to turn the led on, 0 to turn it off - - returns the message to put in order_back["ACK"] - """ - global leds - leds[i]=val - pinMode(led,"OUTPUT") - led=i+2 - if val== 1: - if simul: - digitalWrite(led,1) - return "Led "+str(id)+" on." - elif val== 0: - if simul: - digitalWrite(led,0) - return "Led "+str(id)+" off." - -def setFans(i,id,val): - """ - i (int) : index of the fan in the fans list - id (int) : id of the fan - val (int) : speed wanted for the fan - - returns the message to put in order_back["ACK"] - """ - global fans - fans[i]=val - return "Fan "+str(id)+" set to speed "+str(val)+"." - -def my_action_device(id,val,NET): - """ - id (int) : ID of the device we want to give an order to - val (int) : value defining the order. It can have several meanings depending on the nature of the device - - THis function has no return value. It is supposed to give an order to a device, for example, a led lamp. - - """ - global order_back - global leds - global fans - order_back["R"] = None - order_back["NET"] = NET - print("Action on the sensor %s"%(id)) - if id == 1: - order_back["ID"] = id - order_back["ACK"] = setLeds(0,id,val) - order_back_json= json.dumps(order_back) - print("order_back_json = "+order_back_json+"\n") - ser.write(bytes(order_back_json+"\n",'utf-8')) - elif id == 24: - order_back["ID"] = id - order_back["ACK"] = setLeds(1,id,val) - order_back_json= json.dumps(order_back) - print("order_back_json = "+order_back_json+"\n") - ser.write(bytes(order_back_json+"\n",'utf-8')) - elif id == 102: - order_back["ID"] = id - order_back["ACK"] = setFans(0,id,val) - order_back_json= json.dumps(order_back) - print("order_back_json = "+order_back_json+"\n") - ser.write(bytes(order_back_json+"\n",'utf-8')) - elif id == 144: - order_back["ID"] = id - order_back["ACK"] = setFans(1,id,val) - order_back_json= json.dumps(order_back) - print("order_back_json = "+order_back_json+"\n") - ser.write(bytes(order_back_json+"\n",'utf-8')) - elif id == 182: - order_back["ID"] = id - order_back["ACK"] = setLeds(2,id,val) - order_back_json= json.dumps(order_back) - print("order_back_json = "+order_back_json+"\n") - ser.write(bytes(order_back_json+"\n",'utf-8')) - -def my_read_sensor(id,NET): - """ - id (int) : ID of the sensor we read - - This function has no return value. It simulates the reading of the sensor that has the id given in paramater. - """ - global order_back - global leds - global fans - order_back["ACK"] = None - order_back["NET"] = NET - id = int(id) - print("Reading sensor %d"%(id)) - if id == 1: - order_back["ID"] = id - order_back["R"] = led[0] - order_back_json = json.dumps(order_back) # convert the message in JSON before sending it - print("order_back_json = "+order_back_json+"\n") - ser.write(bytes(order_back_json+"\n",'utf-8')) - elif id == 24: - order_back["ID"] = id - order_back["R"] = leds[1] - order_back_json = json.dumps(order_back) - print("order_back_json = "+order_back_json+"\n") - ser.write(bytes(order_back_json+"\n",'utf-8')) - elif id == 102: - order_back["ID"] = id - order_back["R"] = fans[0] - order_back_json = json.dumps(order_back) - print("order_back_json = "+order_back_json+"\n") - ser.write(bytes(order_back_json+"\n",'utf-8')) - elif id == 144: - order_back["ID"] = id - order_back["R"] = fans[1] - order_back_json = json.dumps(order_back) - print("order_back_json = "+order_back_json+"\n") - ser.write(bytes(order_back_json+"\n",'utf-8')) - elif id == 182: - order_back["ID"] = id - order_back["R"] = leds[2] - order_back_json = json.dumps(order_back) - print("order_back_json = "+order_back_json+"\n") - ser.write(bytes(order_back_json+"\n",'utf-8')) - else: - pass - - -while True: - zolertia_info=str(ser.readline().decode("utf-8")) - print("zolertia info = "+zolertia_info+"\n") - if zolertia_info[0] == "{": - zolertia_info_dic=json.loads(zolertia_info) # convertion into a dictionnary - if "T" in zolertia_info_dic: # T indicates if we must read or write on our device. NB: the ACKs have no "T" value - if zolertia_info_dic["T"] == 0 : - my_read_sensor(zolertia_info_dic["ID"],zolertia_info_dic["NET"]) - elif zolertia_info_dic["T"] == 1 : - my_action_device(zolertia_info_dic["ID"], zolertia_info_dic["O"],zolertia_info_dic["NET"]) - elif "ACK" in zolertia_info_dic : - pass - else : - print("NO EXISTING SENSOR MATCHING THIS ID\n") - - else: # debug messages - now=datetime.utcnow() - now=now.replace(tzinfo=pytz.utc) - now=now.astimezone(pytz.timezone("Europe/Paris")) - current_time = now.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3] - my_debug_message(current_time+zolertia_info) diff --git a/Zolertia/script b/Zolertia/script deleted file mode 100644 index 50227ea..0000000 --- a/Zolertia/script +++ /dev/null @@ -1,10 +0,0 @@ -git clone https://github.com/contiki-ng/contiki-ng.git -sudo apt update -cd contiki-ng -git submodule update --init -sudo apt install python3-pip -sudo pip3 install pyserial -sudo pip3 install intelhex -sudo pip3 install python-magic -sudo pip3 install grovepi -sudo pip3 install pytz diff --git a/Zolertia/zolertia_Z1.c b/Zolertia/zolertia_Z1.c index 9d3ee3c..0abe15b 100644 --- a/Zolertia/zolertia_Z1.c +++ b/Zolertia/zolertia_Z1.c @@ -23,7 +23,7 @@ authors : MAHRAZ Anass and Robyns Jonathan #define UDP_SERVER_PORT 5678 #define ENABLE_DEBUG_LOG 1 // 1 to enable the debug logs -/* Note that depending on the machine you use, enabling the debug logs can interfere with the communication +/* Note that depending on the machine you use, enabling the debug logs can interfere with the communication between the raspberry pi and the zolertia because the required baudrate of the serial port can change */ typedef struct { @@ -64,7 +64,7 @@ This fonction is called when we get a message int is_know=0; // 0 is the zolertia has not been identified yet, else 1 int* ID_table = NULL; // IDs of the sensors - if (data[0]=='Z') { // If the message begins with a 'Z', it's an identification message + if (data[0]=='Z') { // If the message begins with a 'Z', it's an identification message for (int h=0; h> ~/.bashrc +sudo apt update; sudo apt full-upgrade -y; sudo apt autoremove -y; sudo apt purge; sudo apt clean +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh +sudo apt install -y libgirepository1.0-dev +sudo apt install -y libdbus-1-dev +sudo apt install -y libglib2.0-dev +sudo apt install -y libcairo2-dev +sudo apt install -y libssl-dev +pip3 install -U pip +pip3 list -o | cut -f1 -d' ' | tr " " "\n" | awk '{if(NR>=3)print}' | cut -d' ' -f1 | xargs -n1 pip3 install -U > /dev/tty1 + + + +git clone https://github.com/contiki-ng/contiki-ng.git +cd contiki-ng +git submodule update --init +sudo apt install -y python3-pip +sudo apt install -y gcc-arm-none-eabi +sudo pip3 install pyserial +sudo pip3 install intelhex +sudo pip3 install python-magic +sudo pip3 install grovepi +sudo pip3 install pytz +sudo chmod 666 /dev/ttyUSB0 +# cp ~/Zigbee-LoRa-Interconnection/Zolertia/zolertia_Z1.c ~/contiki-ng/examples/rpl-udp/ +cp ~/zolertia_Z1.c ~/contiki-ng/examples/rpl-udp/ +cd ~/contiki-ng/examples/rpl-udp/ +sudo make BOARD=firefly TARGET=zoul zolertia_ZN.upload login +# ../../tools/cc2538-bsl/cc2538-bsl.py -e -w -v -a 0x00202000 \ +# ../../tools/serial-io/serialdump -b115200 /dev/ttyUSB0 +# {"ID":1,"T":1,"O":1,"NETD":2,"NETS":1} +# python raspb_Z1.py \ No newline at end of file