diff --git a/receiver/loriot-receiver.py b/receiver/loriot-receiver.py index 399bb01..0224a41 100644 --- a/receiver/loriot-receiver.py +++ b/receiver/loriot-receiver.py @@ -19,9 +19,12 @@ class Loriot(): while True: result = self.ws.recv() print(result) - jdata = jsonToDict(result) - eui = devEUI(jdata) - payload = get_payloan(jdata) + + jdata = self.jsonToDict(result) + eui = self.devEUI(jdata) + self.insert_json("loriot", result, deveui=eui) + + # payload = self.get_payload(jdata) def jsonToDict(self, data): @@ -30,8 +33,9 @@ class Loriot(): def devEUI(self, data): return data['EUI'] - def get_payload(self, ): - return data['EUI'] + def get_payload(self, data): + return "" + # return data['EUI'] def insert_json(self, provider, data, payload='', deveui=''): try: diff --git a/sodaq_one/compass.ino b/sodaq_one/compass.ino index 26adc85..9a00df8 100644 --- a/sodaq_one/compass.ino +++ b/sodaq_one/compass.ino @@ -3,8 +3,6 @@ LSM303 compass; -char compassReport[80]; - void setupCompass() { Wire.begin(); @@ -21,13 +19,10 @@ String getCompass() String(" compass.a.y=" ) + compass.a.y + String(" compass.a.z=" ) + compass.a.z + String(" compass.m.x=" ) + compass.m.x + - String(" compass.m.y" ) + compass.m.y + + String(" compass.m.y=" ) + compass.m.y + String(" compass.m.z=" ) + compass.m.z; debugSerial.println(tmps); - /* snprintf(compassReport, sizeof(compassReport), "A: %6d %6d %6d M: %6d %6d %6d", */ - /* compass.a.x, compass.a.y, compass.a.z, */ - /* compass.m.x, compass.m.y, compass.m.z); */ - + return tmps; } diff --git a/sodaq_one/gps.ino b/sodaq_one/gps.ino index 031ff00..495f1f8 100644 --- a/sodaq_one/gps.ino +++ b/sodaq_one/gps.ino @@ -1,14 +1,20 @@ #include #include -void gpsSetup() { sodaq_gps.init(GPS_ENABLE); } +void gpsSetup() { + sodaq_gps.init(GPS_ENABLE); + } + +/* FIXME: find out power consumption if turned off */ +// void gpsStop() { sodaq_gps.off(); } + /*! * Find a GPS fix, but first wait a while */ String gpsGetPostion(long waittime) { - String res; + String res = ""; uint32_t timeout = waittime * 1000; debugSerial.println(String("waiting for fix ..., timeout=") + timeout + String("ms")); @@ -24,7 +30,6 @@ String gpsGetPostion(long waittime) debugSerial.println(res); } else { debugSerial.println("GPS: No Fix"); - return ""; } return res; } @@ -35,6 +40,8 @@ String gpsGetDateTime(long waittime) { if (sodaq_gps.scan(false, timeout)) { res= String("datetime =") + sodaq_gps.getDateTimeString(); debugSerial.println(res); + } else { + debugSerial.println("GPS: No Fix"); } return res; diff --git a/sodaq_one/ledcolours.ino b/sodaq_one/ledcolours.ino index 1a780d9..af3e976 100644 --- a/sodaq_one/ledcolours.ino +++ b/sodaq_one/ledcolours.ino @@ -37,20 +37,15 @@ void CLEAR() { } void blink(int length) { - switch(deviceNo) { - case 1: +#if LORADEV == 1 BLUE(); - break; - case 2: +#elif LORADEV == 2 RED(); - break; - case 3: +#elif LORADEV == 3 GREEN(); - break; - case 4: +#elif LORADEV == 4 WHITE(); - break; - } +#endif delay(length); CLEAR(); } diff --git a/sodaq_one/lora.ino b/sodaq_one/lora.ino index fc2f80c..c0d10ad 100644 --- a/sodaq_one/lora.ino +++ b/sodaq_one/lora.ino @@ -87,4 +87,7 @@ void loraSend(String packet){ default: break; } + + /* Delay some time to give avoid keeping the device busy */ + delay(2000); } diff --git a/sodaq_one/loudness.ino b/sodaq_one/loudness.ino index e7ad110..b3d46a9 100644 --- a/sodaq_one/loudness.ino +++ b/sodaq_one/loudness.ino @@ -1,6 +1,6 @@ #include -int readLoudness() +int readLoudness(int pin) { - return analogRead(LOUDNESS_SENSOR); + return analogRead(pin); } diff --git a/sodaq_one/sodaq_one.ino b/sodaq_one/sodaq_one.ino index b2fe16c..140dadd 100644 --- a/sodaq_one/sodaq_one.ino +++ b/sodaq_one/sodaq_one.ino @@ -1,14 +1,17 @@ #include #include +#include #include "nsarduino.h" #define debugSerial SerialUSB -#define deviceNo 2 +/* Which network to use */ +#define LORADEV 1 +// #define SWISSCOM 1 +// #define LORIOT 1 +#define TTN 1 -#define LOUDNESS_SENSOR 0 -#define USE_LOUDNESS 1 #define BUZZER_PIN 2 void signal_loop_start() @@ -18,10 +21,8 @@ void signal_loop_start() blink(30); delay(50); } -void signal_loop_end() -{ - blink(1000); delay(29000); -} + +int sleepcnt; void setup() { while ((!SerialUSB) && (millis() < 10000)){ @@ -34,10 +35,17 @@ void setup() { setupLED(); gpsSetup(); - setupBuzzer(); + + // setupBuzzer(); + setupCompass(); setupSunLight(); loraSetup(); + + + /* sleep little in the beginning, longer the longer we run */ + sleepcnt = 0; + } @@ -47,22 +55,41 @@ void sendIntAsString(String prefix, int value) { loraSend(tmp); } +void sendFloatAsString(String prefix, float value) { + String tmp = prefix + String(value); + debugSerial.println(tmp); + loraSend(tmp); +} + + String tmps; +#define TEMP_PIN 2 +#define LOUDNESS_PIN 0 + +#define SLEEPTIME 5*60*1000 + void loop() { signal_loop_start(); - loraSend(String("node=") + String(deviceNo)); + sendFloatAsString("temperature=", getTemperature(TEMP_PIN)); + + /* loraSend(String("node=") + String(deviceNo)); */ sendIntAsString("battery=", getBatteryVoltage()); - sendIntAsString("loudness=", readLoudness()); + sendIntAsString("loudness=", readLoudness(LOUDNESS_PIN)); loraSend(getSunLight()); loraSend(getCompass()); - /* if((tmps = gpsGetPostion(120)) != "") { */ - /* loraSend(tmps); */ - /* } */ + if((tmps = gpsGetPostion(120)) != "") { + loraSend(tmps); + } - signal_loop_end(); + if(sleepcnt < 10) { + sleepcnt++; + delay(10000); + } else { + delay(SLEEPTIME); + } } @@ -83,17 +110,22 @@ hex: 3030303441333042 /* humid / temperature */ /* -#include - -HDC1000 hdc; - -float temperature; -float humidity; */ -// temperature = hdc.getTemperature(); -// humidity = hdc.getHumidity(); -// String msg_tmphumid = String("tmp=") + temperature + String(" humid=") + humidity; -// debugSerial.println(msg_tmphumid); +/* #include */ +/* #include */ + +/* HDC1000 hdc; */ + +/* float temperature; */ +/* float humidity; */ + + /* hdc.begin(); delay(500); */ + /* temperature = hdc.getTemperature(); */ + /* delay(500); */ + /* hdc.begin(); delay(500); */ + /* humidity = hdc.getHumidity(); */ + /* String msg_tmphumid = String("tmp=") + temperature + String(" humid=") + humidity; */ + /* debugSerial.println(msg_tmphumid); */ diff --git a/sodaq_one/temperature.ino b/sodaq_one/temperature.ino new file mode 100644 index 0000000..c1b2b49 --- /dev/null +++ b/sodaq_one/temperature.ino @@ -0,0 +1,22 @@ +#include + +/* +* Temp sensor: +* https://www.seeedstudio.com/Grove-Temperature-Sensor-p-774.html +* +** NCP18WF104F03RC +*/ + +float getTemperature(int pin) { + int a = analogRead(pin); + + const int B=4250; // B value of the thermistor + + float R = 1023.0/((float)a)-1.0; + + R = 100000.0*R; + + float temperature=1.0/(log(R/100000.0)/B+1/298.15)-273.15; + + return temperature; +}