From 73dcd8879e4c7efb7e183087d9bcb50fb8d08ff1 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 3 Nov 2016 08:08:08 +0100 Subject: [PATCH] Cleanups in sodaq code --- .gitignore | 1 + sodaq_one/ledcolours.ino | 5 +++-- sodaq_one/lora.ino | 13 +++++++++++++ sodaq_one/nsarduino.h | 4 ---- sodaq_one/sodaq_one.ino | 22 ++++------------------ sodaq_one/temp-hdc1000.ino | 18 ++++++++++++++++++ 6 files changed, 39 insertions(+), 24 deletions(-) create mode 100644 sodaq_one/temp-hdc1000.ino diff --git a/.gitignore b/.gitignore index 9036908..e3e9618 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ Sodaq_UBlox_GPS/ libraries/ a.out /venv/ +/sodaq_one/internal.h diff --git a/sodaq_one/ledcolours.ino b/sodaq_one/ledcolours.ino index 3ccb3a4..fd95cea 100644 --- a/sodaq_one/ledcolours.ino +++ b/sodaq_one/ledcolours.ino @@ -40,11 +40,12 @@ void blink(int length) { #if LORADEV == 1 BLUE(); #elif LORADEV == 2 - RED(); + WHITE(); #elif LORADEV == 3 YELLOW(); #elif LORADEV == 4 - WHITE(); + RED(); + #else GREEN(); #endif diff --git a/sodaq_one/lora.ino b/sodaq_one/lora.ino index 77d8e92..b582195 100644 --- a/sodaq_one/lora.ino +++ b/sodaq_one/lora.ino @@ -1,5 +1,6 @@ #include #include "Sodaq_RN2483.h" +#include "internal.h" #define loraSerial Serial1 #define beePin ENABLE_PIN_IO @@ -91,3 +92,15 @@ void loraSend(String packet){ /* Delay some time to give avoid keeping the device busy */ delay(2000); } + +void sendIntAsString(String prefix, int value) { + String tmp = prefix + String(value); + debugSerial.println(tmp); + loraSend(tmp); +} + +void sendFloatAsString(String prefix, float value) { + String tmp = prefix + String(value); + debugSerial.println(tmp); + loraSend(tmp); +} diff --git a/sodaq_one/nsarduino.h b/sodaq_one/nsarduino.h index bbaf3d5..e820d27 100644 --- a/sodaq_one/nsarduino.h +++ b/sodaq_one/nsarduino.h @@ -1,7 +1,3 @@ -#define SWISSCOM 1 -#define TTN 2 -#define LORIOT 3 - /* battery.ino */ uint16_t getBatteryVoltage(); diff --git a/sodaq_one/sodaq_one.ino b/sodaq_one/sodaq_one.ino index 4fdc877..cd7ef55 100644 --- a/sodaq_one/sodaq_one.ino +++ b/sodaq_one/sodaq_one.ino @@ -5,7 +5,6 @@ #define debugSerial SerialUSB - void signal_loop_start() { blink(30); delay(50); @@ -36,26 +35,12 @@ void setup() { cnt = 0; } - -void sendIntAsString(String prefix, int value) { - String tmp = prefix + String(value); - debugSerial.println(tmp); - loraSend(tmp); -} - -void sendFloatAsString(String prefix, float value) { - String tmp = prefix + String(value); - debugSerial.println(tmp); - loraSend(tmp); -} - - String tmps; float tmp; #define TEMP_PIN 2 #define LOUDNESS_PIN 0 -#define BUZZER_PIN 2 +#define BUZZER_PIN 6 #define SLEEPTIME 10000 @@ -66,7 +51,6 @@ void loop() { signal_loop_start(); - // sendIntAsString("loudness=", readLoudness(LOUDNESS_PIN)); // loraSend(getSunLight()); // loraSend(getTempHumidHDC1000()); @@ -76,6 +60,8 @@ void loop() { /* loraSend(tmps); */ /* } */ + + if(cnt < LOUDNESS_AVG) { loudnesses[cnt] = readLoudness(LOUDNESS_PIN); debugSerial.println("temploudness=" + String(loudnesses[cnt])); @@ -87,8 +73,8 @@ void loop() { } tmp = tmp / (float) (cnt+1); + sendIntAsString("battery=", getBatteryVoltage()); sendFloatAsString("loudness=", tmp); - sendIntAsString( "battery=", getBatteryVoltage()); sendFloatAsString("temperature=", getTemperature(TEMP_PIN)); cnt = 0; } diff --git a/sodaq_one/temp-hdc1000.ino b/sodaq_one/temp-hdc1000.ino new file mode 100644 index 0000000..3112c29 --- /dev/null +++ b/sodaq_one/temp-hdc1000.ino @@ -0,0 +1,18 @@ +#include +#include +#include + +HDC1000 hdc; + +void setupTempHumidHDC1000() { + hdc.begin(); delay(500); +} + +String getTempHumidHDC1000() { + float temperature; + float humidity; + + humidity = hdc.getHumidity(); + temperature = hdc.getTemperature(); + return String("tmp=") + temperature + String(" humid=") + humidity; +}