diff --git a/.gitignore b/.gitignore index e3e9618..10af916 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ libraries/ a.out /venv/ /sodaq_one/internal.h +/swisscom-pricing.png diff --git a/python/adeunisrf.py b/python/adeunisrf.py index 0e02783..0d7abe5 100644 --- a/python/adeunisrf.py +++ b/python/adeunisrf.py @@ -29,6 +29,8 @@ log.setLevel(logging.DEBUG) known_devices = [ "0018B20000000C58", "0018B20000000C37", "0018B20000000C59", "0018B20000000CD0", "0018B200000001C5" ] + + def convert_gps_from_stdin(): for line in sys.stdin: res = get_gps("", line) @@ -37,7 +39,8 @@ def convert_gps_from_stdin(): def get_gps(deveui, payload): res = [] - if not int(payload[0:2], 16) & (2**7): + if not int(payload[0:2], 16) & (2**4): + log.debug("No GPS information present") return res try: @@ -84,7 +87,7 @@ def decode_adeunis(provider, pkg): # ttn -> base64 encoded if provider == "ttn": - binascii.b2a_hex(binascii.a2b_base64(payload)) + payload = binascii.b2a_hex(binascii.a2b_base64(payload)) res = [] diff --git a/sodaq_one/battery.ino b/sodaq_one/battery.ino deleted file mode 100644 index 01c9ec2..0000000 --- a/sodaq_one/battery.ino +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#define ADC_AREF 3.3f -#define BATVOLT_R1 2.0f -#define BATVOLT_R2 2.0f -#define BATVOLT_PIN BAT_VOLT - - -// uint16_t getBatteryVoltage() -int getB() -{ - uint16_t voltage = (uint16_t)((ADC_AREF / 1.023) * (BATVOLT_R1 + BATVOLT_R2) / BATVOLT_R2 * (float)analogRead(BATVOLT_PIN)); - - return voltage; -} diff --git a/sodaq_one/buzzer.ino b/sodaq_one/buzzer.ino deleted file mode 100644 index 0a852b0..0000000 --- a/sodaq_one/buzzer.ino +++ /dev/null @@ -1,20 +0,0 @@ -#include - -void setupBuzzer(int pin) -{ - pinMode(pin, OUTPUT); -} - -void buzzerOn(int pin) { - digitalWrite(pin, HIGH); -} - -void buzzerOff(int pin) { - digitalWrite(pin, LOW); -} - -void buzz(int pin, int ms) { - buzzerOn(pin); - delay(ms); - buzzerOff(pin); -} diff --git a/sodaq_one/ledcolours.ino b/sodaq_one/ledcolours.ino index 38d2e22..6a2f53d 100644 --- a/sodaq_one/ledcolours.ino +++ b/sodaq_one/ledcolours.ino @@ -36,11 +36,13 @@ void CLEAR() { digitalWrite(LED_BLUE, HIGH); } -void blink(int length) { +void led_on() { #if LORADEV == 1 BLUE(); #elif LORADEV == 2 WHITE(); +#elif LORADEV == 0xA2 + WHITE(); #elif LORADEV == 3 YELLOW(); #elif LORADEV == 4 @@ -48,6 +50,14 @@ void blink(int length) { #else GREEN(); #endif +} + +void led_off() { + CLEAR(); +} + +void blink(int length) { + led_on(); delay(length); CLEAR(); } diff --git a/sodaq_one/lora.ino b/sodaq_one/lora.ino index 73096e2..6432009 100644 --- a/sodaq_one/lora.ino +++ b/sodaq_one/lora.ino @@ -49,7 +49,7 @@ void loraSetup() void loraSend(String packet){ debugSerial.println("Trying to send: " + packet); - BLUE(); + led_on(); /* with ack */ //switch (LoRaBee.sendReqAck(1, (uint8_t*)packet.c_str(), packet.length(), 8)) @@ -95,7 +95,7 @@ void loraSend(String packet){ /* Delay some time to give avoid keeping the device busy */ delay(2000); - CLEAR(); + led_off(); } void sendIntAsString(String prefix, int value) { diff --git a/sodaq_one/nico.ino b/sodaq_one/nico.ino deleted file mode 100644 index 4ee97fd..0000000 --- a/sodaq_one/nico.ino +++ /dev/null @@ -1,11 +0,0 @@ -#include - -#define ADC_AREF 3.3f -#define BATVOLT_R1 2.0f -#define BATVOLT_R2 2.0f -#define BATVOLT_PIN BAT_VOLT - -int getB() -{ - return ((ADC_AREF / 1.023) * (BATVOLT_R1 + BATVOLT_R2) / BATVOLT_R2 * (float)analogRead(BATVOLT_PIN)); -} diff --git a/sodaq_one/nsarduino.h b/sodaq_one/nsarduino.h index dfb2824..98ea6fe 100644 --- a/sodaq_one/nsarduino.h +++ b/sodaq_one/nsarduino.h @@ -2,13 +2,18 @@ /* battery.ino */ // uint16_t getBatteryVoltage(); -int getB(); +int getBattery(); void blink(int length); +void led_on(); +void led_off(); + + +void setupBuzzer(int pin); void buzzerOn(); void buzzerOff(); -void buzz(int ms); +void buzz(int pin, int ms); /* compass.ino */ extern char compassReport[80]; diff --git a/sodaq_one/sodaq_one.ino b/sodaq_one/sodaq_one.ino index c785116..335422a 100644 --- a/sodaq_one/sodaq_one.ino +++ b/sodaq_one/sodaq_one.ino @@ -3,6 +3,7 @@ #include #include #include "nsarduino.h" +#include "internal.h" #define debugSerial SerialUSB @@ -15,7 +16,7 @@ void signal_loop_start() #define TEMP_PIN 2 #define LOUDNESS_PIN 0 -#define BUZZER_PIN 2 +#define BUZZER_PIN 6 #define WATER_SENSOR_PIN 6 int cnt; @@ -25,6 +26,8 @@ void setup() { // Wait 10 seconds for the Serial Monitor } + loraSetup(); + /* Enable the pins 2/3, 6/7 and 8/9 */ pinMode(11, OUTPUT); digitalWrite(11, HIGH); @@ -32,7 +35,7 @@ void setup() { setupLED(); // setupWater(WATER_SENSOR_PIN); - // setupBuzzer(BUZZER_PIN); + setupBuzzer(BUZZER_PIN); // gpsSetup(); @@ -40,8 +43,8 @@ void setup() { // setupCompass(); // setupSunLight(); - loraSetup(); + buzz(BUZZER_PIN, 100); cnt = 0; } @@ -53,9 +56,10 @@ float tmp; #define LOUDNESS_AVG 60 int loudnesses[LOUDNESS_AVG]; - void loop() { - // signal_loop_start(); + signal_loop_start(); + + debugSerial.println("Deveui=" + String(LORADEV) + " => " + String(LORA_ADDR)); /* if(hasWater(WATER_SENSOR_PIN)) { */ /* debugSerial.println("Having water"); */ @@ -66,15 +70,11 @@ void loop() { /* debugSerial.println("it's dry"); */ /* } */ - // loraSend(getSunLight()); // loraSend(getTempHumidHDC1000()); // loraSend(getCompass()); - -// sendIntAsString("battery=", getBatteryVoltage()); - - getB(); + sendIntAsString("battery=", getBattery()); /* Tracker code */ /* if((tmps = gpsGetPostion(120)) != "") { */ @@ -93,13 +93,11 @@ void loop() { } tmp = tmp / (float) (cnt+1); -// sendIntAsString("battery=", getBatteryVoltage()); sendFloatAsString("loudness=", tmp); sendFloatAsString("temperature=", getTemperature(TEMP_PIN)); cnt = 0; } - delay(SLEEPTIME); }