From 39825d2a0a26c1ac9767af8a2e349c1a77f13b31 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 16 Sep 2016 23:42:17 +0200 Subject: [PATCH] Various updates --- send_and_blink/send_and_blink.ino | 64 ++++++++++++++++++++++++++++--- web-to-db.py | 2 +- 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/send_and_blink/send_and_blink.ino b/send_and_blink/send_and_blink.ino index f47bcd1..ee37ffa 100644 --- a/send_and_blink/send_and_blink.ino +++ b/send_and_blink/send_and_blink.ino @@ -6,10 +6,16 @@ #define loraSerial Serial1 /* The number of the device: 1,2,3,4 */ -#define deviceNo 4 +#define deviceNo 1 #define beePin ENABLE_PIN_IO +#define LOUDNESS_SENSOR 0 +#define LIGHT_SENSOR 2 +#define WATER_SENSOR 6 + +int loudness; + void BLUE() { digitalWrite(LED_RED, HIGH); digitalWrite(LED_GREEN, HIGH); @@ -73,6 +79,10 @@ void setupLED() { pinMode(LED_BLUE, OUTPUT); } +void setupWater() { + pinMode(WATER_SENSOR, INPUT); +} + // OTAA // Random numbers chosen + device id uint8_t DevEUI[8] = { 0x9c, 0xd9, 0x0b, 0xb5, 0x2b, 0x6a, 0x1d, deviceNo }; @@ -95,6 +105,27 @@ void setupLoRaOTAA(){ } } +int readLoudness() +{ + return analogRead(LOUDNESS_SENSOR); +} + +float readLight() +{ + int sensorValue = analogRead(LIGHT_SENSOR); + return (float)(1023-sensorValue)*10/sensorValue; +} + +boolean hasWater() +{ + if(digitalRead(WATER_SENSOR) == LOW) { + return true; + } else { + return false; + } +} + + void setup() { //Power up the LoRaBEE - on loraone/sodaq one @@ -120,9 +151,13 @@ void setup() { /* used for blinking */ counter=0; + loudness = 0; + //connect to the LoRa Network setupLoRa(); + setupWater(); + } void setupLoRa(){ @@ -172,14 +207,33 @@ void sendPacket(String packet){ } void loop() { + loudness = readLoudness(); + + String data_loudness = String("loudness=" + String(loudness, DEC)); + debugSerial.println(data_loudness); + + String data_light = String("light=" + String(readLight(), 3)); + debugSerial.println(data_light); + + String data_water; + if(hasWater()) { + data_water = String("water=true"); + } else { + data_water = String("water=false"); + } + debugSerial.println(data_water); - // put your main code here, to run repeatedly: - String packet = "SODAQ"; /* Blink long after sending packet */ - if(counter >= 60) { - sendPacket(packet); + if(counter >= 10) { + blink(20); + delay(10); + blink(20); + sendPacket(data_loudness); blink(500); + sendPacket(data_light); + blink(500); + sendPacket(data_water); counter = 0; } else { blink(30); diff --git a/web-to-db.py b/web-to-db.py index 4926099..a5e02a1 100644 --- a/web-to-db.py +++ b/web-to-db.py @@ -34,7 +34,7 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler): # And insert into the db self.insert_xml(post_data) - def insert_xml(self, data): + def insert_xml(self, data2): try: conn = psycopg2.connect("dbname=hackzurich") cursor = conn.cursor()