From 55ae7386c004d4625d427584cabcb5661e843464 Mon Sep 17 00:00:00 2001 From: Rainer 'rei' Schuth Date: Wed, 23 Nov 2016 15:20:47 +0100 Subject: [PATCH 1/9] Use the CXX and LD enviroment variables to compile the code --- Raspberry/makefile | 54 +++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/Raspberry/makefile b/Raspberry/makefile index 4762d889..6a53f77d 100644 --- a/Raspberry/makefile +++ b/Raspberry/makefile @@ -1,88 +1,88 @@ include radio.makefile lora_gateway: lora_gateway.o arduPi.o SX1272.o - g++ -lrt -lpthread lora_gateway.o arduPi.o SX1272.o -o lora_gateway + $(CXX) -lrt -lpthread lora_gateway.o arduPi.o SX1272.o -o lora_gateway lora_gateway_pi2: lora_gateway_pi2.o arduPi_pi2.o SX1272_pi2.o - g++ -lrt -lpthread lora_gateway_pi2.o arduPi_pi2.o SX1272_pi2.o -o lora_gateway_pi2 + $(CXX) -lrt -lpthread lora_gateway_pi2.o arduPi_pi2.o SX1272_pi2.o -o lora_gateway_pi2 rm -f lora_gateway ln -s lora_gateway_pi2 ./lora_gateway lora_gateway_wnetkey: lora_gateway.o arduPi.o SX1272_wnetkey.o - g++ -lrt -lpthread lora_gateway.o arduPi.o SX1272_wnetkey.o -o lora_gateway_wnetkey + $(CXX) -lrt -lpthread lora_gateway.o arduPi.o SX1272_wnetkey.o -o lora_gateway_wnetkey lora_gateway_pi2_wnetkey: lora_gateway_pi2.o arduPi_pi2.o SX1272_pi2_wnetkey.o - g++ -lrt -lpthread lora_gateway_pi2.o arduPi_pi2.o SX1272_pi2_wnetkey.o -o lora_gateway_pi2_wnetkey + $(CXX) -lrt -lpthread lora_gateway_pi2.o arduPi_pi2.o SX1272_pi2_wnetkey.o -o lora_gateway_pi2_wnetkey lora_gateway_winput: lora_gateway_winput.o arduPi.o SX1272.o - g++ -lrt -lpthread lora_gateway_winput.o arduPi.o SX1272.o -o lora_gateway_winput + $(CXX) -lrt -lpthread lora_gateway_winput.o arduPi.o SX1272.o -o lora_gateway_winput lora_gateway_pi2_winput: lora_gateway_pi2_winput.o arduPi_pi2.o SX1272_pi2.o - g++ -lrt -lpthread lora_gateway_pi2_winput.o arduPi_pi2.o SX1272_pi2.o -o lora_gateway_pi2_winput + $(CXX) -lrt -lpthread lora_gateway_pi2_winput.o arduPi_pi2.o SX1272_pi2.o -o lora_gateway_pi2_winput lora_gateway.o: lora_gateway.cpp - g++ $(CFLAGS) -DRASPBERRY -DIS_RCV_GATEWAY -c lora_gateway.cpp -o lora_gateway.o + $(CXX) $(CFLAGS) -DRASPBERRY -DIS_RCV_GATEWAY -c lora_gateway.cpp -o lora_gateway.o lora_gateway_pi2.o: lora_gateway.cpp - g++ $(CFLAGS) -DRASPBERRY -DRASPBERRY2 -DIS_RCV_GATEWAY -c lora_gateway.cpp -o lora_gateway_pi2.o + $(CXX) $(CFLAGS) -DRASPBERRY -DRASPBERRY2 -DIS_RCV_GATEWAY -c lora_gateway.cpp -o lora_gateway_pi2.o lora_gateway_winput.o: lora_gateway.cpp - g++ $(CFLAGS) -DRASPBERRY -DIS_RCV_GATEWAY -DWINPUT -c lora_gateway.cpp -o lora_gateway_winput.o + $(CXX) $(CFLAGS) -DRASPBERRY -DIS_RCV_GATEWAY -DWINPUT -c lora_gateway.cpp -o lora_gateway_winput.o lora_gateway_pi2_winput.o: lora_gateway.cpp - g++ $(CFLAGS) -DRASPBERRY -DRASPBERRY2 -DIS_RCV_GATEWAY -DWINPUT -c lora_gateway.cpp -o lora_gateway_pi2_winput.o + $(CXX) $(CFLAGS) -DRASPBERRY -DRASPBERRY2 -DIS_RCV_GATEWAY -DWINPUT -c lora_gateway.cpp -o lora_gateway_pi2_winput.o arduPi.o: arduPi.cpp arduPi.h - g++ -c arduPi.cpp -o arduPi.o + $(CXX) -c arduPi.cpp -o arduPi.o arduPi_pi2.o: arduPi_pi2.cpp arduPi_pi2.h - g++ -c arduPi_pi2.cpp -o arduPi_pi2.o + $(CXX) -c arduPi_pi2.cpp -o arduPi_pi2.o SX1272.o: SX1272.cpp SX1272.h - g++ -c SX1272.cpp -o SX1272.o + $(CXX) -c SX1272.cpp -o SX1272.o SX1272_pi2.o: SX1272.cpp SX1272.h - g++ -DRASPBERRY2 -c SX1272.cpp -o SX1272_pi2.o + $(CXX) -DRASPBERRY2 -c SX1272.cpp -o SX1272_pi2.o SX1272_wnetkey.o: SX1272.cpp - g++ -DW_NET_KEY -c SX1272.cpp -o SX1272_wnetkey.o + $(CXX) -DW_NET_KEY -c SX1272.cpp -o SX1272_wnetkey.o SX1272_pi2_wnetkey.o: SX1272.cpp - g++ -DRASPBERRY2 -DW_NET_KEY -c SX1272.cpp -o SX1272_pi2_wnetkey.o + $(CXX) -DRASPBERRY2 -DW_NET_KEY -c SX1272.cpp -o SX1272_pi2_wnetkey.o lora_las_gateway: lora_las_gateway.o LoRaActivitySharing.o arduPi.o SX1272.o - g++ -lrt -lpthread lora_las_gateway.o LoRaActivitySharing.o arduPi.o SX1272.o -o lora_las_gateway + $(CXX) -lrt -lpthread lora_las_gateway.o LoRaActivitySharing.o arduPi.o SX1272.o -o lora_las_gateway lora_las_gateway_pi2: lora_las_gateway_pi2.o LoRaActivitySharing.o arduPi_pi2.o SX1272_pi2.o - g++ -lrt -lpthread lora_las_gateway_pi2.o LoRaActivitySharing.o arduPi_pi2.o SX1272_pi2.o -o lora_las_gateway_pi2 + $(CXX) -lrt -lpthread lora_las_gateway_pi2.o LoRaActivitySharing.o arduPi_pi2.o SX1272_pi2.o -o lora_las_gateway_pi2 lora_las_gateway_wnetkey: lora_las_gateway.o LoRaActivitySharing.o arduPi.o SX1272_wnetkey.o - g++ -lrt -lpthread lora_las_gateway.o LoRaActivitySharing.o arduPi.o SX1272_wnetkey.o -o lora_las_gateway_wnetkey + $(CXX) -lrt -lpthread lora_las_gateway.o LoRaActivitySharing.o arduPi.o SX1272_wnetkey.o -o lora_las_gateway_wnetkey lora_las_gateway_pi2_wnetkey: lora_las_gateway_pi2.o LoRaActivitySharing.o arduPi_pi2.o SX1272_pi2_wnetkey.o - g++ -lrt -lpthread lora_las_gateway.o LoRaActivitySharing.o arduPi_pi2.o SX1272_pi2_wnetkey.o -o lora_las_gateway_pi2_wnetkey + $(CXX) -lrt -lpthread lora_las_gateway.o LoRaActivitySharing.o arduPi_pi2.o SX1272_pi2_wnetkey.o -o lora_las_gateway_pi2_wnetkey lora_las_gateway.o: lora_gateway.cpp - g++ $(CFLAGS) -DRASPBERRY -DIS_RCV_GATEWAY -DLORA_LAS -c lora_gateway.cpp -o lora_las_gateway.o + $(CXX) $(CFLAGS) -DRASPBERRY -DIS_RCV_GATEWAY -DLORA_LAS -c lora_gateway.cpp -o lora_las_gateway.o lora_las_gateway_pi2.o: lora_gateway.cpp - g++ $(CFLAGS) -DRASPBERRY -DRASPBERRY2 -DIS_RCV_GATEWAY -DLORA_LAS -c lora_gateway.cpp -o lora_las_gateway_pi2.o + $(CXX) $(CFLAGS) -DRASPBERRY -DRASPBERRY2 -DIS_RCV_GATEWAY -DLORA_LAS -c lora_gateway.cpp -o lora_las_gateway_pi2.o LoRaActivitySharing.o: LoRaActivitySharing.cpp LoRaActivitySharing.h - g++ -c LoRaActivitySharing.cpp -o LoRaActivitySharing.o + $(CXX) -c LoRaActivitySharing.cpp -o LoRaActivitySharing.o #for testing as a very simple end-device lora_device: lora_gateway_dev.o arduPi.o SX1272.o - g++ -lrt -lpthread lora_gateway_dev.o arduPi.o SX1272.o -o lora_device + $(CXX) -lrt -lpthread lora_gateway_dev.o arduPi.o SX1272.o -o lora_device lora_device_pi2: lora_gateway_dev_pi2.o arduPi_pi2.o SX1272_pi2.o - g++ -lrt -lpthread lora_gateway_dev.o arduPi_pi2.o SX1272_pi2.o -o lora_device_pi2 + $(CXX) -lrt -lpthread lora_gateway_dev.o arduPi_pi2.o SX1272_pi2.o -o lora_device_pi2 lora_gateway_dev.o: lora_gateway.cpp - g++ $(CFLAGS) -DRASPBERRY -DIS_SEND_GATEWAY -DWINPUT -c lora_gateway.cpp -o lora_gateway_dev.o + $(CXX) $(CFLAGS) -DRASPBERRY -DIS_SEND_GATEWAY -DWINPUT -c lora_gateway.cpp -o lora_gateway_dev.o lora_gateway_dev_pi2.o: lora_gateway.cpp - g++ $(CFLAGS) -DRASPBERRY -DRASPBERRY2 -DIS_SEND_GATEWAY -DWINPUT -c lora_gateway.cpp -o lora_gateway_dev_pi2.o + $(CXX) $(CFLAGS) -DRASPBERRY -DRASPBERRY2 -DIS_SEND_GATEWAY -DWINPUT -c lora_gateway.cpp -o lora_gateway_dev_pi2.o #end lib: arduPi.o arduPi_pi2.o SX1272.o SX1272_pi2.o SX1272_wnetkey.o SX1272_pi2_wnetkey.o lora_gateway.o lora_las_gateway.o lora_gateway_pi2.o lora_las_gateway_pi2.o From 6a9468bf31ed4ba31d8eb7acf0f8ab1f1402f8b8 Mon Sep 17 00:00:00 2001 From: Rainer 'rei' Schuth Date: Wed, 23 Nov 2016 15:23:55 +0100 Subject: [PATCH 2/9] Add readme on how to crosscompile for the rpi --- Raspberry/README.CROSSCOMPILE.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Raspberry/README.CROSSCOMPILE.md diff --git a/Raspberry/README.CROSSCOMPILE.md b/Raspberry/README.CROSSCOMPILE.md new file mode 100644 index 00000000..9476ea08 --- /dev/null +++ b/Raspberry/README.CROSSCOMPILE.md @@ -0,0 +1,24 @@ +Crosscompiling Low-cost LoRa gateway for the Raspberry +==================================== + + + > apt-get install git rsync cmake libc6-i386 lib32z1 lib32stdc++6 + + > mkdir -p ~/raspberrypi + > cd ~/raspberrypi + > git clone git://github.com/raspberrypi/tools.git + + +You wanted to use the following of the 3 ones, gcc-linaro-arm-linux-gnueabihf-raspbian + + > echo 'export PATH=$PATH:$HOME/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin' >> ~/.bashrc + + > source ~/.bashrc + +Now, verify that you can access the compiler: + + > arm-linux-gnueabihf-gcc -v + +Compiling: + + > make CXX=arm-linux-gnueabihf-g++ LD=arm-linux-gnueabihf-ld From 0d366ac6e83fa7f11c91c111408b0f87dafe6711 Mon Sep 17 00:00:00 2001 From: Rainer 'rei' Schuth Date: Wed, 23 Nov 2016 15:34:00 +0100 Subject: [PATCH 3/9] Update .gitignore to ignore Jetbrain, CMake and make files/folders --- .gitignore | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/.gitignore b/.gitignore index e43b0f98..0c180062 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,67 @@ .DS_Store + +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +.idea + +# User-specific stuff: +.idea/workspace.xml +.idea/tasks.xml + +# Sensitive or high-churn files: +.idea/dataSources/ +.idea/dataSources.ids +.idea/dataSources.xml +.idea/dataSources.local.xml +.idea/sqlDataSources.xml +.idea/dynamic.xml +.idea/uiDesigner.xml + +# Gradle: +.idea/gradle.xml +.idea/libraries + +# Mongo Explorer plugin: +.idea/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Ignore CMake stuff +CMakeCache.txt +CMakeFiles +CMakeScripts +Makefile +cmake_install.cmake +install_manifest.txt +CTestTestfile.cmake +CMakeLists.txt + +#files being edited +*~ + +# make and build files +*.lst +*.o +*.eep +*.lss +*.map +*.sym From f3890f22e3fcb0684dd00a76bf7e8923c70bb8ab Mon Sep 17 00:00:00 2001 From: Rainer 'rei' Schuth Date: Thu, 24 Nov 2016 10:28:43 +0100 Subject: [PATCH 4/9] Add simple_temp.cpp based on the arduino code. Send a random value as temperature. --- Raspberry/makefile | 13 +- Raspberry/simple_temp.cpp | 268 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 280 insertions(+), 1 deletion(-) create mode 100644 Raspberry/simple_temp.cpp diff --git a/Raspberry/makefile b/Raspberry/makefile index 6a53f77d..57dd99aa 100644 --- a/Raspberry/makefile +++ b/Raspberry/makefile @@ -1,5 +1,16 @@ include radio.makefile +############################################################################### +# Simple Temp example +############################################################################### +simple_temp_pi2: simple_temp_pi2.o arduPi_pi2.o SX1272_pi2.o + $(CXX) -lrt -lpthread simple_temp_pi2.o arduPi_pi2.o SX1272_pi2.o -o simple_temp_pi2 + +simple_temp_pi2.o: simple_temp.cpp + $(CXX) $(CFLAGS) -DRASPBERRY -DRASPBERRY2 -DIS_RCV_GATEWAY -c simple_temp.cpp -o simple_temp_pi2.o + +############################################################################### + lora_gateway: lora_gateway.o arduPi.o SX1272.o $(CXX) -lrt -lpthread lora_gateway.o arduPi.o SX1272.o -o lora_gateway @@ -88,4 +99,4 @@ lora_gateway_dev_pi2.o: lora_gateway.cpp lib: arduPi.o arduPi_pi2.o SX1272.o SX1272_pi2.o SX1272_wnetkey.o SX1272_pi2_wnetkey.o lora_gateway.o lora_las_gateway.o lora_gateway_pi2.o lora_las_gateway_pi2.o clean: - -rm *.o lora_*gateway + -rm *.o lora_*gateway simple_*temp_pi2 diff --git a/Raspberry/simple_temp.cpp b/Raspberry/simple_temp.cpp new file mode 100644 index 00000000..2c62dcb1 --- /dev/null +++ b/Raspberry/simple_temp.cpp @@ -0,0 +1,268 @@ +/* + * LoRa gateway to receive and send command + * + * Copyright (C) 2016 Rainer 'rei' Schuth + * + */ + +// Include the SX1272 +#include "SX1272.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +// IMPORTANT +/////////////////////////////////////////////////////////////////////////////////////////////////////////// +#define ETSI_EUROPE_REGULATION +//#define FCC_US_REGULATION +//#define SENEGAL_REGULATION + +// please uncomment only 1 choice +#define BAND868 +//#define BAND900 +//#define BAND433 + +#ifdef ETSI_EUROPE_REGULATION + #define MAX_DBM 14 +#elif defined SENEGAL_REGULATION + #define MAX_DBM 10 +#endif + +#ifndef MAX_DBM + #define MAX_DBM 14 +#endif + +#ifdef BAND868 + #ifdef SENEGAL_REGULATION + const uint32_t DEFAULT_CHANNEL=CH_04_868; + #else + const uint32_t DEFAULT_CHANNEL=CH_10_868; + #endif +#elif defined BAND900 + const uint32_t DEFAULT_CHANNEL=CH_05_900; +#elif defined BAND433 + const uint32_t DEFAULT_CHANNEL=CH_00_433; +#endif + +/////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#define PRINTLN printf("\n") +#define PRINT_CSTSTR(fmt,param) printf(fmt,param) +#define PRINT_STR(fmt,param) PRINT_CSTSTR(fmt,param) +#define PRINT_VALUE(fmt,param) PRINT_CSTSTR(fmt,param) +#define FLUSHOUTPUT fflush(stdout); + +#ifdef DEBUG + #define DEBUGLN PRINTLN + #define DEBUG_CSTSTR(fmt,param) PRINT_CSTSTR(fmt,param) + #define DEBUG_STR(fmt,param) PRINT_CSTSTR(fmt,param) + #define DEBUG_VALUE(fmt,param) PRINT_VALUE(fmt,param) +#else + #define DEBUGLN + #define DEBUG_CSTSTR(fmt,param) + #define DEBUG_STR(fmt,param) + #define DEBUG_VALUE(fmt,param) +#endif + +//#define RECEIVE_ALL +//#define CAD_TEST +//#define WINPUT +//#define WITH_SEND_LED + +/////////////////////////////////////////////////////////////////// +// CHANGE HERE THE LORA MODE, NODE ADDRESS +#define LORAMODE 1 +// the special mode to test BW=125MHz, CR=4/5, SF=12 +// on the 868.1MHz channel +//#define LORAMODE 11 + +#define node_addr 8 +////////////////////////////////////////////////////////////////// + +#ifdef BAND868 + #define MAX_NB_CHANNEL 9 + #define STARTING_CHANNEL 10 + #define ENDING_CHANNEL 18 +uint8_t loraChannelIndex=0; +uint32_t loraChannelArray[MAX_NB_CHANNEL]={CH_10_868,CH_11_868,CH_12_868,CH_13_868,CH_14_868,CH_15_868,CH_16_868,CH_17_868,CH_18_868}; +#else // assuming #defined BAND900 + #define MAX_NB_CHANNEL 13 + #define STARTING_CHANNEL 0 + #define ENDING_CHANNEL 12 + uint8_t loraChannelIndex=5; + uint32_t loraChannelArray[MAX_NB_CHANNEL]={CH_00_900,CH_01_900,CH_02_900,CH_03_900,CH_04_900,CH_05_900,CH_06_900,CH_07_900,CH_08_900, + CH_09_900,CH_10_900,CH_11_900,CH_12_900}; +#endif + +// use the dynamic ACK feature of our modified SX1272 lib +#define GW_AUTO_ACK + +#ifdef WITH_SEND_LED + #define SEND_LED 44 +#endif + +#define DEFAULT_DEST_ADDR 1 + +double temp; +uint8_t message[100]; + +void setup() +{ + int e; + srand (time(NULL)); + + // Power ON the module + e = sx1272.ON(); + + PRINT_CSTSTR("%s","^$**********Power ON: state "); + PRINT_VALUE("%d", e); + PRINTLN; + + // Set transmission mode and print the result + e = sx1272.setMode(LORAMODE); + PRINT_CSTSTR("%s","Setting Mode: state "); + PRINT_VALUE("%d", e); + PRINTLN; + + // enable carrier sense + sx1272._enableCarrierSense=true; + + // Select frequency channel + e = sx1272.setChannel(DEFAULT_CHANNEL); + PRINT_CSTSTR("%s","Setting Channel: state "); + PRINT_VALUE("%d", e); + PRINTLN; + + e = sx1272.setPowerDBM((uint8_t)MAX_DBM); + PRINT_CSTSTR("%s","Setting Power: state "); + PRINT_VALUE("%d", e); + PRINTLN; + + // Set the node address and print the result + e = sx1272.setNodeAddress(node_addr); + PRINT_CSTSTR("%s","Setting node addr: state "); + PRINT_VALUE("%d", e); + PRINTLN; + + // Print a success message + PRINT_CSTSTR("%s","SX1272 successfully configured\n"); + + FLUSHOUTPUT; + delay(1000); + + +#ifdef CAD_TEST + PRINT_CSTSTR("%s","Do CAD test\n"); +#endif +} + +void loop(void) +{ + long startSend; + long endSend; + uint8_t app_key_offset=0; + int e; + + temp = rand(); + + PRINT_CSTSTR("%s","Temp is "); + PRINT_VALUE("%f", temp); + PRINTLN; + +#ifdef WITH_APPKEY + app_key_offset = sizeof(my_appKey); + // set the app key in the payload + memcpy(message,my_appKey,app_key_offset); +#endif + + uint8_t r_size; + + PRINT_CSTSTR("%s","Sending "); + PRINT_STR("%s",(char*)(message+app_key_offset)); + PRINTLN; + + PRINT_CSTSTR("%s","Real payload size is "); + PRINT_VALUE("%d", r_size); + PRINTLN; + + int pl=r_size+app_key_offset; + + sx1272.CarrierSense(); + + startSend=millis(); + +#ifdef WITH_APPKEY + // indicate that we have an appkey + sx1272.setPacketType(PKT_TYPE_DATA | PKT_FLAG_DATA_WAPPKEY); +#else + // just a simple data packet + sx1272.setPacketType(PKT_TYPE_DATA); +#endif + + // Send message to the gateway and print the result + // with the app key if this feature is enabled +#ifdef WITH_ACK + int n_retry=NB_RETRIES; + + do { + e = sx1272.sendPacketTimeoutACK(DEFAULT_DEST_ADDR, message, pl); + + if (e==3) + PRINT_CSTSTR("%s","No ACK"); + + n_retry--; + + if (n_retry) + PRINT_CSTSTR("%s","Retry"); + else + PRINT_CSTSTR("%s","Abort"); + + } while (e && n_retry); +#else + e = sx1272.sendPacketTimeout(DEFAULT_DEST_ADDR, message, pl); +#endif + endSend=millis(); + + PRINT_CSTSTR("%s","LoRa pkt size "); + PRINT_VALUE("%d", pl); + PRINTLN; + + PRINT_CSTSTR("%s","LoRa pkt seq "); + PRINT_VALUE("%d", sx1272.packet_sent.packnum); + PRINTLN; + + PRINT_CSTSTR("%s","LoRa Sent in "); + PRINT_VALUE("%ld", endSend-startSend); + PRINTLN; + + PRINT_CSTSTR("%s","LoRa Sent w/CAD in "); + PRINT_VALUE("%ld", endSend-sx1272._startDoCad); + PRINTLN; + + PRINT_CSTSTR("%s","Packet sent, state "); + PRINT_VALUE("%d", e); + PRINTLN; + + delay(50); +} + +int main (int argc, char *argv[]){ + std::cout << "Hello World!" << std::endl; + + setup(); + + while(1){ + loop(); + } + + return 0; +} From 99583103280413c598a3d4e377b37e17990f8fa6 Mon Sep 17 00:00:00 2001 From: Rainer 'rei' Schuth Date: Thu, 24 Nov 2016 10:49:55 +0100 Subject: [PATCH 5/9] Parse cmd line paramters: node address --- Raspberry/simple_temp.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Raspberry/simple_temp.cpp b/Raspberry/simple_temp.cpp index 2c62dcb1..1fc05b15 100644 --- a/Raspberry/simple_temp.cpp +++ b/Raspberry/simple_temp.cpp @@ -85,7 +85,7 @@ // on the 868.1MHz channel //#define LORAMODE 11 -#define node_addr 8 +#define DEFAULT_NODE_ADDR 8 ////////////////////////////////////////////////////////////////// #ifdef BAND868 @@ -112,6 +112,7 @@ uint32_t loraChannelArray[MAX_NB_CHANNEL]={CH_10_868,CH_11_868,CH_12_868,CH_13_8 #define DEFAULT_DEST_ADDR 1 +int node_addr = DEFAULT_NODE_ADDR; double temp; uint8_t message[100]; @@ -256,7 +257,18 @@ void loop(void) } int main (int argc, char *argv[]){ - std::cout << "Hello World!" << std::endl; + + if(argc < 2) { + PRINT_CSTSTR("%s", "Need the node address as a parameter!"); + PRINTLN; + PRINT_CSTSTR("Example: %s ", argv[0]); + PRINTLN; + return 1; + } + node_addr = (uint8_t)atoi(argv[1]); + PRINT_CSTSTR("%s", "My node address is: "); + PRINT_VALUE("%d", node_addr); + PRINTLN; setup(); From 35143e53e5514b15ea68832b43b393c1311ad9c4 Mon Sep 17 00:00:00 2001 From: Rainer 'rei' Schuth Date: Thu, 24 Nov 2016 11:12:23 +0100 Subject: [PATCH 6/9] Add temperature float value to msg --- Raspberry/simple_temp.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Raspberry/simple_temp.cpp b/Raspberry/simple_temp.cpp index 1fc05b15..eadb008a 100644 --- a/Raspberry/simple_temp.cpp +++ b/Raspberry/simple_temp.cpp @@ -88,6 +88,11 @@ #define DEFAULT_NODE_ADDR 8 ////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +// CHANGE HERE THE THINGSPEAK FIELD BETWEEN 1 AND 4 +#define field_index 4 +/////////////////////////////////////////////////////////////////// + #ifdef BAND868 #define MAX_NB_CHANNEL 9 #define STARTING_CHANNEL 10 @@ -187,6 +192,10 @@ void loop(void) uint8_t r_size; + // then use app_key_offset to skip the app key + + r_size=sprintf((char*)message+app_key_offset, "\\!#%d#TC/%.2f", field_index, temp); + PRINT_CSTSTR("%s","Sending "); PRINT_STR("%s",(char*)(message+app_key_offset)); PRINTLN; @@ -253,7 +262,6 @@ void loop(void) PRINT_VALUE("%d", e); PRINTLN; - delay(50); } int main (int argc, char *argv[]){ @@ -274,6 +282,7 @@ int main (int argc, char *argv[]){ while(1){ loop(); + delay(1000); } return 0; From 59280b4c262d772b5b6010d63e3fb0bff0fbc4ce Mon Sep 17 00:00:00 2001 From: Rainer 'rei' Schuth Date: Thu, 24 Nov 2016 13:51:59 +0100 Subject: [PATCH 7/9] Reorganize config options. Add WITH_SEND_LED to blink an led during tx --- Raspberry/simple_temp.cpp | 142 +++++++++++++++++++++++++++----------- 1 file changed, 101 insertions(+), 41 deletions(-) diff --git a/Raspberry/simple_temp.cpp b/Raspberry/simple_temp.cpp index eadb008a..fc9d2c36 100644 --- a/Raspberry/simple_temp.cpp +++ b/Raspberry/simple_temp.cpp @@ -21,7 +21,9 @@ // IMPORTANT -/////////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +// please uncomment only 1 choice #define ETSI_EUROPE_REGULATION //#define FCC_US_REGULATION //#define SENEGAL_REGULATION @@ -53,30 +55,9 @@ const uint32_t DEFAULT_CHANNEL=CH_00_433; #endif -/////////////////////////////////////////////////////////////////////////////////////////////////////////// - -#define PRINTLN printf("\n") -#define PRINT_CSTSTR(fmt,param) printf(fmt,param) -#define PRINT_STR(fmt,param) PRINT_CSTSTR(fmt,param) -#define PRINT_VALUE(fmt,param) PRINT_CSTSTR(fmt,param) -#define FLUSHOUTPUT fflush(stdout); - -#ifdef DEBUG - #define DEBUGLN PRINTLN - #define DEBUG_CSTSTR(fmt,param) PRINT_CSTSTR(fmt,param) - #define DEBUG_STR(fmt,param) PRINT_CSTSTR(fmt,param) - #define DEBUG_VALUE(fmt,param) PRINT_VALUE(fmt,param) -#else - #define DEBUGLN - #define DEBUG_CSTSTR(fmt,param) - #define DEBUG_STR(fmt,param) - #define DEBUG_VALUE(fmt,param) -#endif +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// -//#define RECEIVE_ALL -//#define CAD_TEST -//#define WINPUT -//#define WITH_SEND_LED /////////////////////////////////////////////////////////////////// // CHANGE HERE THE LORA MODE, NODE ADDRESS @@ -84,43 +65,118 @@ // the special mode to test BW=125MHz, CR=4/5, SF=12 // on the 868.1MHz channel //#define LORAMODE 11 +////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////// #define DEFAULT_NODE_ADDR 8 +#define DEFAULT_DEST_ADDR 1 +////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////// +//#define WITH_APPKEY + +#ifdef WITH_APPKEY + // CHANGE HERE THE APPKEY, BUT IF GW CHECKS FOR APPKEY, MUST BE + // IN THE APPKEY LIST MAINTAINED BY GW. + uint8_t my_appKey[4]={5, 6, 7, 8}; +#endif +////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////// +#define WITH_ACK + +#ifdef WITH_ACK + #define NB_RETRIES 3 +#endif +////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////// +// use the dynamic ACK feature of our modified SX1272 lib +#define GW_AUTO_ACK ////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// // CHANGE HERE THE THINGSPEAK FIELD BETWEEN 1 AND 4 -#define field_index 4 +#define THINGSPEAK_FIELD_INDEX 4 +/////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////// +#define WITH_SEND_LED + +#ifdef WITH_SEND_LED + // Define the LED pin + #define SEND_LED 3 +#endif /////////////////////////////////////////////////////////////////// #ifdef BAND868 #define MAX_NB_CHANNEL 9 #define STARTING_CHANNEL 10 #define ENDING_CHANNEL 18 -uint8_t loraChannelIndex=0; -uint32_t loraChannelArray[MAX_NB_CHANNEL]={CH_10_868,CH_11_868,CH_12_868,CH_13_868,CH_14_868,CH_15_868,CH_16_868,CH_17_868,CH_18_868}; -#else // assuming #defined BAND900 + uint8_t loraChannelIndex=0; + uint32_t loraChannelArray[MAX_NB_CHANNEL]={ + CH_10_868, + CH_11_868, + CH_12_868, + CH_13_868, + CH_14_868, + CH_15_868, + CH_16_868, + CH_17_868, + CH_18_868 + }; +#elif defined BAND900 #define MAX_NB_CHANNEL 13 #define STARTING_CHANNEL 0 #define ENDING_CHANNEL 12 uint8_t loraChannelIndex=5; - uint32_t loraChannelArray[MAX_NB_CHANNEL]={CH_00_900,CH_01_900,CH_02_900,CH_03_900,CH_04_900,CH_05_900,CH_06_900,CH_07_900,CH_08_900, - CH_09_900,CH_10_900,CH_11_900,CH_12_900}; + uint32_t loraChannelArray[MAX_NB_CHANNEL]={ + CH_00_900, + CH_01_900, + CH_02_900, + CH_03_900, + CH_04_900, + CH_05_900, + CH_06_900, + CH_07_900, + CH_08_900, + CH_09_900, + CH_10_900, + CH_11_900, + CH_12_900 + }; #endif -// use the dynamic ACK feature of our modified SX1272 lib -#define GW_AUTO_ACK +#define PRINTLN printf("\n") +#define PRINT_CSTSTR(fmt,param) printf(fmt,param) +#define PRINT_STR(fmt,param) PRINT_CSTSTR(fmt,param) +#define PRINT_VALUE(fmt,param) PRINT_CSTSTR(fmt,param) +#define FLUSHOUTPUT fflush(stdout); -#ifdef WITH_SEND_LED - #define SEND_LED 44 +#ifdef DEBUG +#define DEBUGLN PRINTLN + #define DEBUG_CSTSTR(fmt,param) PRINT_CSTSTR(fmt,param) + #define DEBUG_STR(fmt,param) PRINT_CSTSTR(fmt,param) + #define DEBUG_VALUE(fmt,param) PRINT_VALUE(fmt,param) +#else + #define DEBUGLN + #define DEBUG_CSTSTR(fmt,param) + #define DEBUG_STR(fmt,param) + #define DEBUG_VALUE(fmt,param) #endif -#define DEFAULT_DEST_ADDR 1 + +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// int node_addr = DEFAULT_NODE_ADDR; double temp; uint8_t message[100]; + +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// + void setup() { int e; @@ -164,11 +220,6 @@ void setup() FLUSHOUTPUT; delay(1000); - - -#ifdef CAD_TEST - PRINT_CSTSTR("%s","Do CAD test\n"); -#endif } void loop(void) @@ -194,7 +245,7 @@ void loop(void) // then use app_key_offset to skip the app key - r_size=sprintf((char*)message+app_key_offset, "\\!#%d#TC/%.2f", field_index, temp); + r_size=sprintf((char*)message+app_key_offset, "\\!#%d#TC/%.2f", THINGSPEAK_FIELD_INDEX, temp); PRINT_CSTSTR("%s","Sending "); PRINT_STR("%s",(char*)(message+app_key_offset)); @@ -220,6 +271,10 @@ void loop(void) // Send message to the gateway and print the result // with the app key if this feature is enabled +#ifdef WITH_SEND_LED + digitalWrite(SEND_LED, HIGH); +#endif + #ifdef WITH_ACK int n_retry=NB_RETRIES; @@ -240,6 +295,11 @@ void loop(void) #else e = sx1272.sendPacketTimeout(DEFAULT_DEST_ADDR, message, pl); #endif + +#ifdef WITH_SEND_LED + digitalWrite(SEND_LED, LOW); +#endif + endSend=millis(); PRINT_CSTSTR("%s","LoRa pkt size "); From 316a6fa7af517b2d7434cedb30db001fcbb9ab80 Mon Sep 17 00:00:00 2001 From: Rainer 'rei' Schuth Date: Thu, 24 Nov 2016 13:58:53 +0100 Subject: [PATCH 8/9] Add carrier sense directive --- Raspberry/simple_temp.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Raspberry/simple_temp.cpp b/Raspberry/simple_temp.cpp index fc9d2c36..3fdb6075 100644 --- a/Raspberry/simple_temp.cpp +++ b/Raspberry/simple_temp.cpp @@ -95,6 +95,10 @@ #define GW_AUTO_ACK ////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////// +#define WITH_CARRIER_SENSE +////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// // CHANGE HERE THE THINGSPEAK FIELD BETWEEN 1 AND 4 #define THINGSPEAK_FIELD_INDEX 4 @@ -257,7 +261,9 @@ void loop(void) int pl=r_size+app_key_offset; +#ifdef WITH_CARRIER_SENSE sx1272.CarrierSense(); +#endif startSend=millis(); From fa26e4a944709a181554d5f731937a2d986935a4 Mon Sep 17 00:00:00 2001 From: Rainer 'rei' Schuth Date: Thu, 24 Nov 2016 14:11:57 +0100 Subject: [PATCH 9/9] Add table documenting the arduPi GPIO pin layout --- Raspberry/simple_temp.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Raspberry/simple_temp.cpp b/Raspberry/simple_temp.cpp index 3fdb6075..48b44e28 100644 --- a/Raspberry/simple_temp.cpp +++ b/Raspberry/simple_temp.cpp @@ -108,7 +108,31 @@ #define WITH_SEND_LED #ifdef WITH_SEND_LED - // Define the LED pin + /*** + + RPI vs arduPi GPIO Pin Layout + + | Raspbeery Pi v2,3 GPIO Pin | arduPi IO Pin | Alternativ Function | + | --------------------------- |---------------| --------------------| + | 2 | | I2C:SDA | + | 3 | | I2C:SCL | + | 4 | 6 | | + | 8 | 10 | SPI:CE0 | + | 9 | 12 | SPI:CE0 | + | 10 | 11 | SPI:CE0 | + | 11 | 13 | SPI:CE0 | + | 14 | 1 | UART:TX | + | 15 | 0 | UART:RX | + | 17 | 7 | | + | 18 | 2 | | + | 21/27 | 8 | | + | 22 | 9 | | + | 23 | 3 | | + | 24 | 4 | | + | 25 | 5 | | + + ***/ + // Define the LED pin based on the arduPi IO Pin column #define SEND_LED 3 #endif ///////////////////////////////////////////////////////////////////