Make code web compatible
This commit is contained in:
parent
ab6eed60e4
commit
01fbd097a6
2 changed files with 15 additions and 8 deletions
|
@ -252,23 +252,24 @@ void loop() {
|
|||
|
||||
String data_water;
|
||||
if(hasWater()) {
|
||||
data_water = String("water=true");
|
||||
data_water = String("water=1");
|
||||
} else {
|
||||
data_water = String("water=false");
|
||||
data_water = String("water=0");
|
||||
}
|
||||
debugSerial.println(data_water);
|
||||
|
||||
String data_magnet;
|
||||
if(isMagnetic()) {
|
||||
data_magnet = String("magnet=true");
|
||||
data_magnet = String("magnet=1");
|
||||
} else {
|
||||
data_magnet = String("magnet=false");
|
||||
data_magnet = String("magnet=0");
|
||||
}
|
||||
debugSerial.println(data_magnet);
|
||||
|
||||
/* Blink long after sending packet */
|
||||
if(counter >= 10) {
|
||||
// beep(20);
|
||||
sendPacket("Teststring");
|
||||
// Beep(20);
|
||||
blink(20);
|
||||
delay(10);
|
||||
blink(20);
|
||||
|
|
12
web-to-db.py
12
web-to-db.py
|
@ -5,6 +5,7 @@ import psycopg2
|
|||
import websocket
|
||||
import xml.etree.ElementTree as ET
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
import re
|
||||
|
||||
|
||||
from websocket import create_connection
|
||||
|
@ -48,12 +49,17 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
|||
self.to_dashboard(post_data)
|
||||
|
||||
def to_dashboard(self, data):
|
||||
ws = websocket.create_connection("wss://home-safety-visual.eu-gb.mybluemix.net/alarmsocket")
|
||||
|
||||
dev = self.devEUI(data)
|
||||
text = self.payload(data)
|
||||
|
||||
ws.send("%s:%s" % (dev, text))
|
||||
ws.close()
|
||||
# Working lora node
|
||||
if dev == "9CD90BB52B6A1D01":
|
||||
key, value = text.split("=")
|
||||
ws = websocket.create_connection("wss://home-safety-visual.eu-gb.mybluemix.net/%s" % (key))
|
||||
|
||||
ws.send("%s:%s" % (dev, text))
|
||||
ws.close()
|
||||
|
||||
def devEUI(self, data):
|
||||
root = ET.fromstring(data)
|
||||
|
|
Loading…
Reference in a new issue