From 8e0aa77715c7955873eca3462d226ce358b8fe7d Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 2 Nov 2016 17:38:56 +0100 Subject: [PATCH] Cleanup sodaq code --- sodaq_one/compass.ino | 12 +++--- sodaq_one/ledcolours.ino | 4 +- sodaq_one/lora.ino | 4 +- sodaq_one/sodaq_one.ino | 84 +++++++++++++++++++--------------------- 4 files changed, 50 insertions(+), 54 deletions(-) diff --git a/sodaq_one/compass.ino b/sodaq_one/compass.ino index 9a00df8..e9998bd 100644 --- a/sodaq_one/compass.ino +++ b/sodaq_one/compass.ino @@ -15,12 +15,12 @@ String getCompass() String tmps; compass.read(); - tmps = String("compass.a.x=" ) + compass.a.x + - 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.z=" ) + compass.m.z; + tmps = String("compass a.x=" ) + compass.a.x + + String(" a.y=" ) + compass.a.y + + String(" a.z=" ) + compass.a.z + + String(" m.x=" ) + compass.m.x + + String(" m.y=" ) + compass.m.y + + String(" m.z=" ) + compass.m.z; debugSerial.println(tmps); diff --git a/sodaq_one/ledcolours.ino b/sodaq_one/ledcolours.ino index af3e976..3ccb3a4 100644 --- a/sodaq_one/ledcolours.ino +++ b/sodaq_one/ledcolours.ino @@ -42,9 +42,11 @@ void blink(int length) { #elif LORADEV == 2 RED(); #elif LORADEV == 3 - GREEN(); + YELLOW(); #elif LORADEV == 4 WHITE(); +#else + GREEN(); #endif delay(length); CLEAR(); diff --git a/sodaq_one/lora.ino b/sodaq_one/lora.ino index c0d10ad..77d8e92 100644 --- a/sodaq_one/lora.ino +++ b/sodaq_one/lora.ino @@ -4,7 +4,6 @@ #define loraSerial Serial1 #define beePin ENABLE_PIN_IO - #ifdef LORA_ABP void setupLoRaABP(){ if (LoRaBee.initABP(loraSerial, devAddr, appSKey, nwkSKey, true)) @@ -34,7 +33,7 @@ void setupLoRaOTAA(){ void loraSetup() { - pinMode(ENABLE_PIN_IO, OUTPUT); // ONE + pinMode(beePin, OUTPUT); // ONE digitalWrite(beePin, HIGH); // Lorawan loraSerial.begin(LoRaBee.getDefaultBaudRate()); @@ -48,6 +47,7 @@ void loraSetup() } void loraSend(String packet){ + debugSerial.println("Trying to send: " + packet); switch (LoRaBee.sendReqAck(1, (uint8_t*)packet.c_str(), packet.length(), 8)) { case NoError: diff --git a/sodaq_one/sodaq_one.ino b/sodaq_one/sodaq_one.ino index 140dadd..37e7886 100644 --- a/sodaq_one/sodaq_one.ino +++ b/sodaq_one/sodaq_one.ino @@ -1,18 +1,17 @@ #include #include #include - #include "nsarduino.h" +#define DEBUG 1 + #define debugSerial SerialUSB -/* Which network to use */ +/* Which network to use, which device it is (internal only) */ #define LORADEV 1 -// #define SWISSCOM 1 +#define SWISSCOM 1 // #define LORIOT 1 -#define TTN 1 - -#define BUZZER_PIN 2 +// #define TTN 1 void signal_loop_start() { @@ -21,8 +20,7 @@ void signal_loop_start() blink(30); delay(50); } - -int sleepcnt; +int cnt; void setup() { while ((!SerialUSB) && (millis() < 10000)){ @@ -34,18 +32,15 @@ void setup() { digitalWrite(11, HIGH); setupLED(); - gpsSetup(); + // gpsSetup(); // setupBuzzer(); - setupCompass(); - setupSunLight(); + // setupCompass(); +// setupSunLight(); loraSetup(); - - /* sleep little in the beginning, longer the longer we run */ - sleepcnt = 0; - + cnt = 0; } @@ -63,33 +58,48 @@ void sendFloatAsString(String prefix, float value) { String tmps; +float tmp; #define TEMP_PIN 2 #define LOUDNESS_PIN 0 +#define BUZZER_PIN 2 -#define SLEEPTIME 5*60*1000 +#define SLEEPTIME 10000 + +#define LOUDNESS_AVG 6 +int loudnesses[LOUDNESS_AVG]; void loop() { signal_loop_start(); - sendFloatAsString("temperature=", getTemperature(TEMP_PIN)); - /* loraSend(String("node=") + String(deviceNo)); */ - sendIntAsString("battery=", getBatteryVoltage()); - sendIntAsString("loudness=", readLoudness(LOUDNESS_PIN)); - loraSend(getSunLight()); - loraSend(getCompass()); - if((tmps = gpsGetPostion(120)) != "") { - loraSend(tmps); - } +// sendIntAsString("loudness=", readLoudness(LOUDNESS_PIN)); +// loraSend(getSunLight()); + // loraSend(getTempHumidHDC1000()); + // loraSend(getCompass()); - if(sleepcnt < 10) { - sleepcnt++; - delay(10000); + /* if((tmps = gpsGetPostion(120)) != "") { */ + /* loraSend(tmps); */ + /* } */ + + if(cnt < LOUDNESS_AVG) { + loudnesses[cnt] = readLoudness(LOUDNESS_PIN); + debugSerial.println("temploudness=" + String(loudnesses[cnt])); + cnt++; } else { - delay(SLEEPTIME); + tmp = 0; + for(cnt = 0; cnt < LOUDNESS_AVG; cnt++) { + tmp += loudnesses[cnt]; + } + tmp = tmp / (float) (cnt+1); + + sendFloatAsString("loudness=", tmp); + sendIntAsString( "battery=", getBatteryVoltage()); +// sendFloatAsString("temperature=", getTemperature(TEMP_PIN)); + cnt = 0; } + delay(SLEEPTIME); } @@ -113,19 +123,3 @@ hex: 3030303441333042 */ - -/* #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); */