From 5a98367e43dcea7b3c584c9d91e64639da314f5e Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 15 Nov 2016 11:32:51 +0100 Subject: [PATCH] Add nodered-receiver --- python/nodered-receiver.py | 32 ++++++++++++++++++++++++++++++++ sodaq_one/gps.ino | 4 ++++ sodaq_one/ledcolours.ino | 1 - sodaq_one/lora.ino | 2 ++ sodaq_one/sodaq_one.ino | 3 --- 5 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 python/nodered-receiver.py diff --git a/python/nodered-receiver.py b/python/nodered-receiver.py new file mode 100644 index 0000000..4f6a503 --- /dev/null +++ b/python/nodered-receiver.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +# Nico Schottelius +# 2016-11-15 +# GPLv3+ + +import urllib +import psycopg2 +import websocket +from http.server import BaseHTTPRequestHandler, HTTPServer +import re +import json +import lorautil +import logging + + +class RequestHandler(BaseHTTPRequestHandler): + def do_POST(self): + length = int(self.headers['Content-Length']) + post_data = self.rfile.read(length).decode('utf-8') + + print(post_data) + + # And insert into the db + #lorautil.db_insert_json("swisscom", post_data, payload, deveui) + #lorautil.db_notify("swisscom", payload, deveui) + + +if __name__ == '__main__': + server_address = ('0.0.0.0', 1900) + httpd = HTTPServer(server_address, RequestHandler) + httpd.serve_forever() diff --git a/sodaq_one/gps.ino b/sodaq_one/gps.ino index 495f1f8..d1516a1 100644 --- a/sodaq_one/gps.ino +++ b/sodaq_one/gps.ino @@ -17,6 +17,7 @@ String gpsGetPostion(long waittime) String res = ""; uint32_t timeout = waittime * 1000; + YELLOW(); debugSerial.println(String("waiting for fix ..., timeout=") + timeout + String("ms")); uint32_t start = millis(); @@ -31,6 +32,9 @@ String gpsGetPostion(long waittime) } else { debugSerial.println("GPS: No Fix"); } + + CLEAR(); + return res; } diff --git a/sodaq_one/ledcolours.ino b/sodaq_one/ledcolours.ino index fd95cea..38d2e22 100644 --- a/sodaq_one/ledcolours.ino +++ b/sodaq_one/ledcolours.ino @@ -45,7 +45,6 @@ void blink(int length) { YELLOW(); #elif LORADEV == 4 RED(); - #else GREEN(); #endif diff --git a/sodaq_one/lora.ino b/sodaq_one/lora.ino index 25355a5..73096e2 100644 --- a/sodaq_one/lora.ino +++ b/sodaq_one/lora.ino @@ -49,6 +49,7 @@ void loraSetup() void loraSend(String packet){ debugSerial.println("Trying to send: " + packet); + BLUE(); /* with ack */ //switch (LoRaBee.sendReqAck(1, (uint8_t*)packet.c_str(), packet.length(), 8)) @@ -94,6 +95,7 @@ void loraSend(String packet){ /* Delay some time to give avoid keeping the device busy */ delay(2000); + CLEAR(); } void sendIntAsString(String prefix, int value) { diff --git a/sodaq_one/sodaq_one.ino b/sodaq_one/sodaq_one.ino index 9c2fa34..f65e208 100644 --- a/sodaq_one/sodaq_one.ino +++ b/sodaq_one/sodaq_one.ino @@ -76,9 +76,6 @@ void loop() { loraSend(tmps); } - - - /* if(cnt < LOUDNESS_AVG) { */ /* loudnesses[cnt] = readLoudness(LOUDNESS_PIN); */ /* debugSerial.println("temploudness=" + String(loudnesses[cnt])); */