From 70bd0084982440127c8b58e152386e5e3619ed63 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 24 Oct 2016 21:34:02 +0200 Subject: [PATCH] Cleanup --- .../.gitignore | 0 .../Arduino.mk | 0 {sodaq_one_gps => sodaq_one}/Sodaq_RN2483.cpp | 0 {sodaq_one_gps => sodaq_one}/Sodaq_RN2483.h | 0 {sodaq_one_gps => sodaq_one}/StringLiterals.h | 0 .../Switchable_Device.cpp | 0 .../Switchable_Device.h | 0 {sodaq_one_gps => sodaq_one}/Utils.h | 0 .../battery.ino | 0 .../buzzer.ino | 0 .../compass.ino | 0 sodaq_one/gps.ino | 41 +++ .../ledcolours.ino | 6 + .../lora.ino | 0 sodaq_one/loudness.ino | 6 + .../nsarduino.h | 7 + sodaq_one/sodaq_one.ino | 112 ++++++++ .../sunlight.ino | 0 sodaq_one_gps/sodaq_one_gps.ino | 220 --------------- sodaq_one_gps_battery/Sodaq_RN2483.cpp | 1 - sodaq_one_gps_battery/Sodaq_RN2483.h | 1 - sodaq_one_gps_battery/StringLiterals.h | 1 - sodaq_one_gps_battery/Switchable_Device.cpp | 1 - sodaq_one_gps_battery/Switchable_Device.h | 1 - sodaq_one_gps_battery/Utils.h | 1 - .../sodaq_one_gps_battery.ino | 253 ------------------ .../Sodaq_RN2483.cpp | 1 - sodaq_one_gps_battery_loudness/Sodaq_RN2483.h | 1 - .../StringLiterals.h | 1 - .../Switchable_Device.cpp | 1 - .../Switchable_Device.h | 1 - sodaq_one_gps_battery_loudness/Utils.h | 1 - .../sodaq_one_gps_battery_loudness.ino | 189 ------------- 33 files changed, 172 insertions(+), 674 deletions(-) rename {sodaq_one_gps_battery_loudness => sodaq_one}/.gitignore (100%) rename {sodaq_one_gps_battery_loudness => sodaq_one}/Arduino.mk (100%) rename {sodaq_one_gps => sodaq_one}/Sodaq_RN2483.cpp (100%) rename {sodaq_one_gps => sodaq_one}/Sodaq_RN2483.h (100%) rename {sodaq_one_gps => sodaq_one}/StringLiterals.h (100%) rename {sodaq_one_gps => sodaq_one}/Switchable_Device.cpp (100%) rename {sodaq_one_gps => sodaq_one}/Switchable_Device.h (100%) rename {sodaq_one_gps => sodaq_one}/Utils.h (100%) rename {sodaq_one_gps_battery_loudness => sodaq_one}/battery.ino (100%) rename {sodaq_one_gps_battery_loudness => sodaq_one}/buzzer.ino (100%) rename {sodaq_one_gps_battery_loudness => sodaq_one}/compass.ino (100%) create mode 100644 sodaq_one/gps.ino rename {sodaq_one_gps_battery_loudness => sodaq_one}/ledcolours.ino (89%) rename {sodaq_one_gps_battery_loudness => sodaq_one}/lora.ino (100%) create mode 100644 sodaq_one/loudness.ino rename {sodaq_one_gps_battery_loudness => sodaq_one}/nsarduino.h (79%) create mode 100644 sodaq_one/sodaq_one.ino rename {sodaq_one_gps_battery_loudness => sodaq_one}/sunlight.ino (100%) delete mode 100644 sodaq_one_gps/sodaq_one_gps.ino delete mode 120000 sodaq_one_gps_battery/Sodaq_RN2483.cpp delete mode 120000 sodaq_one_gps_battery/Sodaq_RN2483.h delete mode 120000 sodaq_one_gps_battery/StringLiterals.h delete mode 120000 sodaq_one_gps_battery/Switchable_Device.cpp delete mode 120000 sodaq_one_gps_battery/Switchable_Device.h delete mode 120000 sodaq_one_gps_battery/Utils.h delete mode 100644 sodaq_one_gps_battery/sodaq_one_gps_battery.ino delete mode 120000 sodaq_one_gps_battery_loudness/Sodaq_RN2483.cpp delete mode 120000 sodaq_one_gps_battery_loudness/Sodaq_RN2483.h delete mode 120000 sodaq_one_gps_battery_loudness/StringLiterals.h delete mode 120000 sodaq_one_gps_battery_loudness/Switchable_Device.cpp delete mode 120000 sodaq_one_gps_battery_loudness/Switchable_Device.h delete mode 120000 sodaq_one_gps_battery_loudness/Utils.h delete mode 100644 sodaq_one_gps_battery_loudness/sodaq_one_gps_battery_loudness.ino diff --git a/sodaq_one_gps_battery_loudness/.gitignore b/sodaq_one/.gitignore similarity index 100% rename from sodaq_one_gps_battery_loudness/.gitignore rename to sodaq_one/.gitignore diff --git a/sodaq_one_gps_battery_loudness/Arduino.mk b/sodaq_one/Arduino.mk similarity index 100% rename from sodaq_one_gps_battery_loudness/Arduino.mk rename to sodaq_one/Arduino.mk diff --git a/sodaq_one_gps/Sodaq_RN2483.cpp b/sodaq_one/Sodaq_RN2483.cpp similarity index 100% rename from sodaq_one_gps/Sodaq_RN2483.cpp rename to sodaq_one/Sodaq_RN2483.cpp diff --git a/sodaq_one_gps/Sodaq_RN2483.h b/sodaq_one/Sodaq_RN2483.h similarity index 100% rename from sodaq_one_gps/Sodaq_RN2483.h rename to sodaq_one/Sodaq_RN2483.h diff --git a/sodaq_one_gps/StringLiterals.h b/sodaq_one/StringLiterals.h similarity index 100% rename from sodaq_one_gps/StringLiterals.h rename to sodaq_one/StringLiterals.h diff --git a/sodaq_one_gps/Switchable_Device.cpp b/sodaq_one/Switchable_Device.cpp similarity index 100% rename from sodaq_one_gps/Switchable_Device.cpp rename to sodaq_one/Switchable_Device.cpp diff --git a/sodaq_one_gps/Switchable_Device.h b/sodaq_one/Switchable_Device.h similarity index 100% rename from sodaq_one_gps/Switchable_Device.h rename to sodaq_one/Switchable_Device.h diff --git a/sodaq_one_gps/Utils.h b/sodaq_one/Utils.h similarity index 100% rename from sodaq_one_gps/Utils.h rename to sodaq_one/Utils.h diff --git a/sodaq_one_gps_battery_loudness/battery.ino b/sodaq_one/battery.ino similarity index 100% rename from sodaq_one_gps_battery_loudness/battery.ino rename to sodaq_one/battery.ino diff --git a/sodaq_one_gps_battery_loudness/buzzer.ino b/sodaq_one/buzzer.ino similarity index 100% rename from sodaq_one_gps_battery_loudness/buzzer.ino rename to sodaq_one/buzzer.ino diff --git a/sodaq_one_gps_battery_loudness/compass.ino b/sodaq_one/compass.ino similarity index 100% rename from sodaq_one_gps_battery_loudness/compass.ino rename to sodaq_one/compass.ino diff --git a/sodaq_one/gps.ino b/sodaq_one/gps.ino new file mode 100644 index 0000000..031ff00 --- /dev/null +++ b/sodaq_one/gps.ino @@ -0,0 +1,41 @@ +#include +#include + +void gpsSetup() { sodaq_gps.init(GPS_ENABLE); } + +/*! + * Find a GPS fix, but first wait a while + */ +String gpsGetPostion(long waittime) +{ + String res; + uint32_t timeout = waittime * 1000; + + debugSerial.println(String("waiting for fix ..., timeout=") + timeout + String("ms")); + + uint32_t start = millis(); + + if (sodaq_gps.scan(false, timeout)) { + debugSerial.println(String(" time to find fix: ") + (millis() - start) + String("ms")); + debugSerial.println(String(" datetime = ") + sodaq_gps.getDateTimeString()); + + res = String("lat=") + String(sodaq_gps.getLat(), 7) + " " + String("lon=") + String(sodaq_gps.getLon(), 7) + " " + String("sats=") + String(sodaq_gps.getNumberOfSatellites()); + + debugSerial.println(res); + } else { + debugSerial.println("GPS: No Fix"); + return ""; + } + return res; +} + +String gpsGetDateTime(long waittime) { + String res = ""; + uint32_t timeout = waittime * 1000; + if (sodaq_gps.scan(false, timeout)) { + res= String("datetime =") + sodaq_gps.getDateTimeString(); + debugSerial.println(res); + } + + return res; +} diff --git a/sodaq_one_gps_battery_loudness/ledcolours.ino b/sodaq_one/ledcolours.ino similarity index 89% rename from sodaq_one_gps_battery_loudness/ledcolours.ino rename to sodaq_one/ledcolours.ino index ceed6b8..1a780d9 100644 --- a/sodaq_one_gps_battery_loudness/ledcolours.ino +++ b/sodaq_one/ledcolours.ino @@ -54,3 +54,9 @@ void blink(int length) { delay(length); CLEAR(); } + +void setupLED() { + pinMode(LED_RED, OUTPUT); + pinMode(LED_GREEN, OUTPUT); + pinMode(LED_BLUE, OUTPUT); +} diff --git a/sodaq_one_gps_battery_loudness/lora.ino b/sodaq_one/lora.ino similarity index 100% rename from sodaq_one_gps_battery_loudness/lora.ino rename to sodaq_one/lora.ino diff --git a/sodaq_one/loudness.ino b/sodaq_one/loudness.ino new file mode 100644 index 0000000..e7ad110 --- /dev/null +++ b/sodaq_one/loudness.ino @@ -0,0 +1,6 @@ +#include + +int readLoudness() +{ + return analogRead(LOUDNESS_SENSOR); +} diff --git a/sodaq_one_gps_battery_loudness/nsarduino.h b/sodaq_one/nsarduino.h similarity index 79% rename from sodaq_one_gps_battery_loudness/nsarduino.h rename to sodaq_one/nsarduino.h index b5f1a53..e820d27 100644 --- a/sodaq_one_gps_battery_loudness/nsarduino.h +++ b/sodaq_one/nsarduino.h @@ -11,6 +11,13 @@ void buzz(int ms); /* compass.ino */ extern char compassReport[80]; +/* ledcolours.ino */ +void setupLED(); + +/* loudness.ino */ +int readLoudness(); + + /* lora.ino */ void setupLoRa(); void sendPacket(String packet); diff --git a/sodaq_one/sodaq_one.ino b/sodaq_one/sodaq_one.ino new file mode 100644 index 0000000..6f68730 --- /dev/null +++ b/sodaq_one/sodaq_one.ino @@ -0,0 +1,112 @@ +#include +#include + +#include "nsarduino.h" + +#define debugSerial SerialUSB + +#define deviceNo 2 + +#define LOUDNESS_SENSOR 0 +#define USE_LOUDNESS 1 +#define BUZZER_PIN 2 + +void sendBatVoltage() { + String battery = String("bat1=") + String(getBatteryVoltage()); + sendPacket(battery); +} + +void signal_loop_start() +{ + blink(30); delay(50); + blink(30); delay(50); + blink(30); delay(50); +} + +void signal_loop_end() +{ + blink(1000); delay(29000); +} + +void setup() { + while ((!SerialUSB) && (millis() < 10000)){ + // Wait 10 seconds for the Serial Monitor + } + + /* Enable the pins 2/3, 6/7 and 8/9 */ + pinMode(11, OUTPUT); + digitalWrite(11, HIGH); + + setupLED(); + gpsSetup(); + setupBuzzer(); + setupCompass(); + setupSunLight(); + loraSetup(); +} + + +void sendIntAsString(String prefix, int value) { + String tmp = prefix + String(value); + debugSerial.println(tmp); + loraSend(tmp); +} + +String tmps; +int tmpi; + +void loop() { + signal_loop_start(); + + loraSend(String("node=") + String(deviceNo)); + sendIntAsString("battery=", getBatteryVoltage()); + sendIntAsString("loudness=", readLoudness()); + + tmps = getSunLight(); + debugSerial.println(tmps); + loraSend(tmps); + + readCompass(); + debugSerial.println(compassReport); + + // buzz(30); + + /* if((tmps = gpsGetPostion(120)) != "") { */ + /* loraSend(tmps); */ + /* } */ + + signal_loop_end(); +} + + +/* Node = 2 +48 +48 +48 +52 +65 +51 +48 +66 + +hex: 3030303441333042 +*/ + +/* temp / humidity code (not functional) + +/* 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); diff --git a/sodaq_one_gps_battery_loudness/sunlight.ino b/sodaq_one/sunlight.ino similarity index 100% rename from sodaq_one_gps_battery_loudness/sunlight.ino rename to sodaq_one/sunlight.ino diff --git a/sodaq_one_gps/sodaq_one_gps.ino b/sodaq_one_gps/sodaq_one_gps.ino deleted file mode 100644 index 71ddcb4..0000000 --- a/sodaq_one_gps/sodaq_one_gps.ino +++ /dev/null @@ -1,220 +0,0 @@ -#include -#include - -#include "Sodaq_RN2483.h" - -#define debugSerial SerialUSB -#define loraSerial Serial1 - -/* The number of the device: 1,2,3,4 */ -#define deviceNo 2 - -#define beePin ENABLE_PIN_IO - -void sendPacket(String packet); - -void BLUE() { - digitalWrite(LED_RED, HIGH); - digitalWrite(LED_GREEN, HIGH); - digitalWrite(LED_BLUE, LOW); -} - -void RED() { - digitalWrite(LED_RED, LOW); - digitalWrite(LED_GREEN, HIGH); - digitalWrite(LED_BLUE, HIGH); -} - -void YELLOW() { - digitalWrite(LED_RED, LOW); - digitalWrite(LED_GREEN, LOW); - digitalWrite(LED_BLUE, HIGH); -} - -void WHITE() { - digitalWrite(LED_RED, LOW); - digitalWrite(LED_GREEN, LOW); - digitalWrite(LED_BLUE, LOW); -} - - -void GREEN() { - digitalWrite(LED_RED, HIGH); - digitalWrite(LED_GREEN, LOW); - digitalWrite(LED_BLUE, HIGH); -} - -void CLEAR() { - digitalWrite(LED_RED, HIGH); - digitalWrite(LED_GREEN, HIGH); - digitalWrite(LED_BLUE, HIGH); -} - -void blink(int length) { - switch(deviceNo) { - case 1: - BLUE(); - break; - case 2: - WHITE(); - break; - case 3: - GREEN(); - break; - case 4: - RED(); - break; - } - delay(length); - CLEAR(); -} - - -void setupLED() { - pinMode(LED_RED, OUTPUT); - pinMode(LED_GREEN, OUTPUT); - pinMode(LED_BLUE, OUTPUT); -} - -void setupGPS() - { - sodaq_gps.init(GPS_ENABLE); - } - -/*! - * Find a GPS fix, but first wait a while - */ -void send_gps() -{ - /* Delay and light up */ - blink(10000); - - uint32_t start = millis(); - uint32_t timeout = 900L * 1000; - debugSerial.println(String("waiting for fix ..., timeout=") + timeout + String("ms")); - - if (sodaq_gps.scan(false, timeout)) { - debugSerial.println(String(" time to find fix: ") + (millis() - start) + String("ms")); - debugSerial.println(String(" datetime = ") + sodaq_gps.getDateTimeString()); - - String lat= String("lat=") + String(sodaq_gps.getLat(), 7); - debugSerial.println(lat); - sendPacket(lat); - - String lon = String("lon=") + String(sodaq_gps.getLon(), 7); - debugSerial.println(lon); - sendPacket(lon); - - String sats = String("num sats = ") + String(sodaq_gps.getNumberOfSatellites()); - debugSerial.println(sats); - sendPacket(sats); - } else { - debugSerial.println("No Fix"); - sendPacket("No Fix"); - } -} - - -// OTAA -// Random numbers chosen + device id -uint8_t DevEUI[8] = { 0x9c, 0xd9, 0x0b, 0xb5, 0x2b, 0x6a, 0x1d, deviceNo }; -uint8_t AppEUI[8] = { 0xd4, 0x16, 0xcd, 0x0b, 0x7b, 0xcf, 0x2d, 0x5c }; -uint8_t AppKey[16] = { 0xa9, 0xbc, 0x8b, 0x6a, 0x81, 0x75, 0xf6, 0x33, 0xe0, 0xd6, 0x64, 0xd9, 0x2b, 0xcb, 0x13, 0x78 }; - - -void setupLoRaOTAA(){ - if (LoRaBee.initOTA(loraSerial, DevEUI, AppEUI, AppKey, true)) - { - debugSerial.println("Communication to LoRaBEE successful."); - } - else - { - debugSerial.println("OTAA Setup failed!"); - } -} - - -void setup() { - //Power up the LoRaBEE - on loraone/sodaq one - pinMode(ENABLE_PIN_IO, OUTPUT); // ONE - digitalWrite(beePin, HIGH); // ONE - delay(3000); - - while ((!SerialUSB) && (millis() < 10000)){ - // Wait 10 seconds for the Serial Monitor - } - - //Set baud rate - debugSerial.begin(57600); - loraSerial.begin(LoRaBee.getDefaultBaudRate()); - - setupGPS(); - blink(30); - blink(30); - - setupLED(); - blink(60); - - //connect to the LoRa Network - setupLoRa(); -} - -void setupLoRa() -{ - setupLoRaOTAA(); -} - -void sendPacket(String packet){ - switch (LoRaBee.sendReqAck(1, (uint8_t*)packet.c_str(), packet.length(), 8)) - { - case NoError: - debugSerial.println("Successful transmission."); - break; - case NoResponse: - debugSerial.println("There was no response from the device."); - setupLoRa(); - break; - case Timeout: - debugSerial.println("Connection timed-out. Check your serial connection to the device! Sleeping for 20sec."); - delay(20000); - break; - case PayloadSizeError: - debugSerial.println("The size of the payload is greater than allowed. Transmission failed!"); - break; - case InternalError: - debugSerial.println("Oh No! This shouldn't happen. Something is really wrong! Try restarting the device!\r\nThe network connection will reset."); - setupLoRa(); - break; - case Busy: - debugSerial.println("The device is busy. Sleeping for 10 extra seconds."); - delay(10000); - break; - case NetworkFatalError: - debugSerial.println("There is a non-recoverable error with the network connection. You should re-connect.\r\nThe network connection will reset."); - setupLoRa(); - break; - case NotConnected: - debugSerial.println("The device is not connected to the network. Please connect to the network before attempting to send data.\r\nThe network connection will reset."); - setupLoRa(); - break; - case NoAcknowledgment: - debugSerial.println("There was no acknowledgment sent back!"); - // When you this message you are probaly out of range of the network. - break; - default: - break; - } -} - -void loop() { - /* Announce begin of code */ - blink(20); delay(50); - blink(20); delay(50); - blink(20); delay(50); - - sendPacket("GPS node"); - blink(1000); delay(29000); - - /* Wait one minute for finding fix */ - send_gps(); -} diff --git a/sodaq_one_gps_battery/Sodaq_RN2483.cpp b/sodaq_one_gps_battery/Sodaq_RN2483.cpp deleted file mode 120000 index 5102a89..0000000 --- a/sodaq_one_gps_battery/Sodaq_RN2483.cpp +++ /dev/null @@ -1 +0,0 @@ -../Sodaq_RN2483.cpp \ No newline at end of file diff --git a/sodaq_one_gps_battery/Sodaq_RN2483.h b/sodaq_one_gps_battery/Sodaq_RN2483.h deleted file mode 120000 index 515c9e8..0000000 --- a/sodaq_one_gps_battery/Sodaq_RN2483.h +++ /dev/null @@ -1 +0,0 @@ -../Sodaq_RN2483.h \ No newline at end of file diff --git a/sodaq_one_gps_battery/StringLiterals.h b/sodaq_one_gps_battery/StringLiterals.h deleted file mode 120000 index 83e008e..0000000 --- a/sodaq_one_gps_battery/StringLiterals.h +++ /dev/null @@ -1 +0,0 @@ -../StringLiterals.h \ No newline at end of file diff --git a/sodaq_one_gps_battery/Switchable_Device.cpp b/sodaq_one_gps_battery/Switchable_Device.cpp deleted file mode 120000 index 5fb5dda..0000000 --- a/sodaq_one_gps_battery/Switchable_Device.cpp +++ /dev/null @@ -1 +0,0 @@ -../Switchable_Device.cpp \ No newline at end of file diff --git a/sodaq_one_gps_battery/Switchable_Device.h b/sodaq_one_gps_battery/Switchable_Device.h deleted file mode 120000 index 0c82682..0000000 --- a/sodaq_one_gps_battery/Switchable_Device.h +++ /dev/null @@ -1 +0,0 @@ -../Switchable_Device.h \ No newline at end of file diff --git a/sodaq_one_gps_battery/Utils.h b/sodaq_one_gps_battery/Utils.h deleted file mode 120000 index 70d35c6..0000000 --- a/sodaq_one_gps_battery/Utils.h +++ /dev/null @@ -1 +0,0 @@ -../Utils.h \ No newline at end of file diff --git a/sodaq_one_gps_battery/sodaq_one_gps_battery.ino b/sodaq_one_gps_battery/sodaq_one_gps_battery.ino deleted file mode 100644 index 7de221b..0000000 --- a/sodaq_one_gps_battery/sodaq_one_gps_battery.ino +++ /dev/null @@ -1,253 +0,0 @@ -#include -#include - -#include "Sodaq_RN2483.h" - -#define debugSerial SerialUSB -#define loraSerial Serial1 - -/* The number of the device: 1,2,3,4 */ -#define deviceNo 1 - -#define beePin ENABLE_PIN_IO - -void sendPacket(String packet); - -void BLUE() { - digitalWrite(LED_RED, HIGH); - digitalWrite(LED_GREEN, HIGH); - digitalWrite(LED_BLUE, LOW); -} - -void RED() { - digitalWrite(LED_RED, LOW); - digitalWrite(LED_GREEN, HIGH); - digitalWrite(LED_BLUE, HIGH); -} - -void YELLOW() { - digitalWrite(LED_RED, LOW); - digitalWrite(LED_GREEN, LOW); - digitalWrite(LED_BLUE, HIGH); -} - -void WHITE() { - digitalWrite(LED_RED, LOW); - digitalWrite(LED_GREEN, LOW); - digitalWrite(LED_BLUE, LOW); -} - - -void GREEN() { - digitalWrite(LED_RED, HIGH); - digitalWrite(LED_GREEN, LOW); - digitalWrite(LED_BLUE, HIGH); -} - -void CLEAR() { - digitalWrite(LED_RED, HIGH); - digitalWrite(LED_GREEN, HIGH); - digitalWrite(LED_BLUE, HIGH); -} - -void blink(int length) { - switch(deviceNo) { - case 1: - BLUE(); - break; - case 2: - WHITE(); - break; - case 3: - GREEN(); - break; - case 4: - RED(); - break; - } - delay(length); - CLEAR(); -} - -#define ADC_AREF 3.3f -#define BATVOLT_R1 2.0f -#define BATVOLT_R2 2.0f -#define BATVOLT_PIN BAT_VOLT - -uint16_t getBatteryVoltage() -{ - uint16_t voltage = (uint16_t)((ADC_AREF / 1.023) * (BATVOLT_R1 + BATVOLT_R2) / BATVOLT_R2 * (float)analogRead(BATVOLT_PIN)); - - return voltage; -} - - -void sendBatVoltage() { - String battery = String("bat1=") + String(getBatteryVoltage()); - sendPacket(battery); -} - - -void setupLED() { - pinMode(LED_RED, OUTPUT); - pinMode(LED_GREEN, OUTPUT); - pinMode(LED_BLUE, OUTPUT); -} - -void setupGPS() - { - sodaq_gps.init(GPS_ENABLE); - } - -/*! - * Find a GPS fix, but first wait a while - */ -void send_gps() -{ - /* Delay and light up */ - blink(10000); - - uint32_t start = millis(); - uint32_t timeout = 900L * 1000; - debugSerial.println(String("waiting for fix ..., timeout=") + timeout + String("ms")); - - if (sodaq_gps.scan(false, timeout)) { - debugSerial.println(String(" time to find fix: ") + (millis() - start) + String("ms")); - debugSerial.println(String(" datetime = ") + sodaq_gps.getDateTimeString()); - - String lat= String("lat=") + String(sodaq_gps.getLat(), 7); - debugSerial.println(lat); - sendPacket(lat); - - String lon = String("lon=") + String(sodaq_gps.getLon(), 7); - debugSerial.println(lon); - sendPacket(lon); - - String sats = String("num sats = ") + String(sodaq_gps.getNumberOfSatellites()); - debugSerial.println(sats); - sendPacket(sats); - } else { - debugSerial.println("No Fix"); - sendPacket("No Fix"); - } -} - - -// OTAA -// Random numbers chosen + device id -uint8_t DevEUI[8] = { 0x9c, 0xd9, 0x0b, 0xb5, 0x2b, 0x6a, 0x1d, deviceNo }; -// uint8_t AppEUI[8] = { 0xd4, 0x16, 0xcd, 0x0b, 0x7b, 0xcf, 0x2d, 0x5c }; -// uint8_t AppKey[16] = { 0xa9, 0xbc, 0x8b, 0x6a, 0x81, 0x75, 0xf6, 0x33, 0xe0, 0xd6, 0x64, 0xd9, 0x2b, 0xcb, 0x13, 0x78 }; - -// ttn -uint8_t AppEUI[8] = { 0x70, 0xB3, 0xD5, 0x7E, 0xD0, 0x00, 0x0E, 0x9B -}; - -// id=2 -// uint8_t AppKey[16] = { 0xE4, 0xAC, 0x4D, 0xD4, 0xB2, 0xA7, -// 0x84,0xB8, 0x9D, 0xC9, 0x4C, 0x37, 0xD9, 0x0E, 0x22, 0x45 }; - -// id=1 -uint8_t AppKey[16] = { 0x27, 0x29, 0xCC, 0x46, 0xAD, 0xFA, 0xFA, 0x95, 0xA1, 0x8A, 0xA1, 0x21, 0x57, 0x21, 0x23, 0x6E }; - - -void setupLoRaOTAA(){ - if (LoRaBee.initOTA(loraSerial, DevEUI, AppEUI, AppKey, true)) - { - debugSerial.println("Communication to LoRaBEE successful."); - } - else - { - debugSerial.println("OTAA Setup failed!"); - } -} - - -void setup() { - //Power up the LoRaBEE - on loraone/sodaq one - pinMode(ENABLE_PIN_IO, OUTPUT); // ONE - digitalWrite(beePin, HIGH); // ONE - delay(3000); - - while ((!SerialUSB) && (millis() < 10000)){ - // Wait 10 seconds for the Serial Monitor - } - - //Set baud rate - debugSerial.begin(57600); - loraSerial.begin(LoRaBee.getDefaultBaudRate()); - - setupGPS(); - blink(30); - blink(30); - - setupLED(); - blink(60); - - //connect to the LoRa Network - setupLoRa(); -} - -void setupLoRa() -{ - setupLoRaOTAA(); -} - -void sendPacket(String packet){ - switch (LoRaBee.sendReqAck(1, (uint8_t*)packet.c_str(), packet.length(), 8)) - { - case NoError: - debugSerial.println("Successful transmission."); - break; - case NoResponse: - debugSerial.println("There was no response from the device."); - setupLoRa(); - break; - case Timeout: - debugSerial.println("Connection timed-out. Check your serial connection to the device! Sleeping for 20sec."); - delay(20000); - break; - case PayloadSizeError: - debugSerial.println("The size of the payload is greater than allowed. Transmission failed!"); - break; - case InternalError: - debugSerial.println("Oh No! This shouldn't happen. Something is really wrong! Try restarting the device!\r\nThe network connection will reset."); - setupLoRa(); - break; - case Busy: - debugSerial.println("The device is busy. Sleeping for 10 extra seconds."); - delay(10000); - break; - case NetworkFatalError: - debugSerial.println("There is a non-recoverable error with the network connection. You should re-connect.\r\nThe network connection will reset."); - setupLoRa(); - break; - case NotConnected: - debugSerial.println("The device is not connected to the network. Please connect to the network before attempting to send data.\r\nThe network connection will reset."); - setupLoRa(); - break; - case NoAcknowledgment: - debugSerial.println("There was no acknowledgment sent back!"); - // When you this message you are probaly out of range of the network. - break; - default: - break; - } -} - -void loop() { - /* Announce begin of code */ - blink(20); delay(50); - blink(20); delay(50); - blink(20); delay(50); - - String id = String("GPS node ") + String(deviceNo); - sendPacket(id); - sendBatVoltage(); - - /* Wait for 30s to send again */ - blink(1000); delay(29000); - - /* Wait one minute for finding fix */ - send_gps(); -} diff --git a/sodaq_one_gps_battery_loudness/Sodaq_RN2483.cpp b/sodaq_one_gps_battery_loudness/Sodaq_RN2483.cpp deleted file mode 120000 index 5102a89..0000000 --- a/sodaq_one_gps_battery_loudness/Sodaq_RN2483.cpp +++ /dev/null @@ -1 +0,0 @@ -../Sodaq_RN2483.cpp \ No newline at end of file diff --git a/sodaq_one_gps_battery_loudness/Sodaq_RN2483.h b/sodaq_one_gps_battery_loudness/Sodaq_RN2483.h deleted file mode 120000 index 515c9e8..0000000 --- a/sodaq_one_gps_battery_loudness/Sodaq_RN2483.h +++ /dev/null @@ -1 +0,0 @@ -../Sodaq_RN2483.h \ No newline at end of file diff --git a/sodaq_one_gps_battery_loudness/StringLiterals.h b/sodaq_one_gps_battery_loudness/StringLiterals.h deleted file mode 120000 index 83e008e..0000000 --- a/sodaq_one_gps_battery_loudness/StringLiterals.h +++ /dev/null @@ -1 +0,0 @@ -../StringLiterals.h \ No newline at end of file diff --git a/sodaq_one_gps_battery_loudness/Switchable_Device.cpp b/sodaq_one_gps_battery_loudness/Switchable_Device.cpp deleted file mode 120000 index 5fb5dda..0000000 --- a/sodaq_one_gps_battery_loudness/Switchable_Device.cpp +++ /dev/null @@ -1 +0,0 @@ -../Switchable_Device.cpp \ No newline at end of file diff --git a/sodaq_one_gps_battery_loudness/Switchable_Device.h b/sodaq_one_gps_battery_loudness/Switchable_Device.h deleted file mode 120000 index 0c82682..0000000 --- a/sodaq_one_gps_battery_loudness/Switchable_Device.h +++ /dev/null @@ -1 +0,0 @@ -../Switchable_Device.h \ No newline at end of file diff --git a/sodaq_one_gps_battery_loudness/Utils.h b/sodaq_one_gps_battery_loudness/Utils.h deleted file mode 120000 index 70d35c6..0000000 --- a/sodaq_one_gps_battery_loudness/Utils.h +++ /dev/null @@ -1 +0,0 @@ -../Utils.h \ No newline at end of file diff --git a/sodaq_one_gps_battery_loudness/sodaq_one_gps_battery_loudness.ino b/sodaq_one_gps_battery_loudness/sodaq_one_gps_battery_loudness.ino deleted file mode 100644 index 427b567..0000000 --- a/sodaq_one_gps_battery_loudness/sodaq_one_gps_battery_loudness.ino +++ /dev/null @@ -1,189 +0,0 @@ -#include -#include -#include - - -#include "nsarduino.h" - -#define debugSerial SerialUSB - -/* The number of the device: 1,2,3,4 */ -#define deviceNo 2 - -#define LOUDNESS_SENSOR 0 -#define USE_LOUDNESS 1 -#define BUZZER_PIN 2 - -String msg_gps; -int loudness; - -int readLoudness() -{ - return analogRead(LOUDNESS_SENSOR); -} - -void sendBatVoltage() { - String battery = String("bat1=") + String(getBatteryVoltage()); - sendPacket(battery); -} - -void setupLED() { - pinMode(LED_RED, OUTPUT); - pinMode(LED_GREEN, OUTPUT); - pinMode(LED_BLUE, OUTPUT); -} - -void setup_gps() { sodaq_gps.init(GPS_ENABLE); } - -/*! - * Find a GPS fix, but first wait a while - */ -boolean get_gps(long waittime) -{ - uint32_t timeout = waittime * 1000; - - debugSerial.println(String("waiting for fix ..., timeout=") + timeout + String("ms")); - blink(5000); - - uint32_t start = millis(); - - if (sodaq_gps.scan(false, timeout)) { - debugSerial.println(String(" time to find fix: ") + (millis() - start) + String("ms")); - debugSerial.println(String(" datetime = ") + sodaq_gps.getDateTimeString()); - - - msg_gps = String("lat=") + String(sodaq_gps.getLat(), 7) + " " + String("lon=") + String(sodaq_gps.getLon(), 7) + " " + String("sats=") + String(sodaq_gps.getNumberOfSatellites()); - - /* String lat= String("lat=") + String(sodaq_gps.getLat(), 7); */ - /* debugSerial.println(lat); */ - /* msg_gps = lat; */ - - /* String lon = String("lon=") + String(sodaq_gps.getLon(), 7); */ - /* debugSerial.println(lon); */ - /* msg_gps += " " + lon; */ - - /* String sats = String("sats=") + String(sodaq_gps.getNumberOfSatellites()); */ - - /* msg_gps += " " + sats; */ - - debugSerial.println(msg_gps); - } else { - debugSerial.println("GPS: No Fix"); - return false; - } - return true; -} - -/* -* 1 Sodaq -* 2 sodaq -* 3 sodaq -* 4 rpi -*/ -// 9cd90bb52b6a1d - -void signal_loop_start() -{ - blink(30); delay(50); - blink(30); delay(50); - blink(30); delay(50); -} - -void signal_loop_end() -{ - /* Wait for 30s to send again */ - blink(1000); delay(29000); -} - -void setup() { - while ((!SerialUSB) && (millis() < 10000)){ - // Wait 10 seconds for the Serial Monitor - } - - /* Enable the pins 2/3, 6/7 and 8/9 */ - pinMode(11, OUTPUT); - digitalWrite(11, HIGH); - - setupLED(); - - setup_gps(); - - setupBuzzer(); - setupCompass(); - - - blink(60); - - setupSunLight(); - - loraSetup(); -} - -int mybyte; -int i; - -String tmp; - -void loop() { - signal_loop_start(); - - /* String msg_id = String("node=") + String(deviceNo); */ - /* sendPacket(msg_id); */ - - /* sendBatVoltage(); */ - // sendLight(); - - /* loudness = readLoudness(); */ - /* String msg_loudness = "loudness=" + String(loudness); */ - /* debugSerial.println(msg_loudness); */ - - tmp = getSunLight(); - debugSerial.println(tmp); - loraSend(tmp); - - readCompass(); - debugSerial.println(compassReport); - - // buzz(30); - -// sendPacket(msg_loudness); - - /* if(get_gps(60)) { */ - /* sendPacket(msg_gps); */ - /* } */ - - signal_loop_end(); -} - - -/* Node = 2 -48 -48 -48 -52 -65 -51 -48 -66 - -hex: 3030303441333042 -*/ - -/* temp / humidity code (not functional) - -/* 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);