Add new ttn2 receiver
This commit is contained in:
parent
58ffb0fbc6
commit
5c29282196
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import urllib
|
||||
import psycopg2
|
||||
import websocket
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
import re
|
||||
import json
|
||||
import pprint
|
||||
import lorautil
|
||||
|
||||
# HTTPRequestHandler class
|
||||
class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
||||
def do_POST(self):
|
||||
length = int(self.headers['Content-Length'])
|
||||
post_data = self.rfile.read(length).decode('utf-8')
|
||||
|
||||
payload = self.payload_hex(post_data)
|
||||
deveui = self.get_deveui(post_data)
|
||||
|
||||
# Try to decode to unicode
|
||||
try:
|
||||
payload = self.data_to_unicode(payload)
|
||||
except UnicodeDecodeError:
|
||||
pass
|
||||
|
||||
print("deveui/payload: {}:{}".format(deveui, payload))
|
||||
|
||||
# And insert into the db
|
||||
lorautil.db_insert_json("ttn", post_data, payload, deveui)
|
||||
lorautil.db_notify("ttn", payload, deveui)
|
||||
|
||||
def payload_hex(self, data):
|
||||
mydict = lorautil.jsonToDict(data)
|
||||
return mydict['DevEUI_uplink']['payload_hex']
|
||||
|
||||
def data_to_unicode(self, myhex):
|
||||
return bytes.fromhex(myhex).decode('utf-8')
|
||||
|
||||
def get_deveui(self, data):
|
||||
mydict = lorautil.jsonToDict(data)
|
||||
eui = mydict['DevEUI_uplink']['DevEUI']
|
||||
return eui
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
server_address = ('0.0.0.0', 7000)
|
||||
httpd = HTTPServer(server_address, testHTTPServer_RequestHandler)
|
||||
print('running server...')
|
||||
httpd.serve_forever()
|
|
@ -0,0 +1,11 @@
|
|||
#include <Arduino.h>
|
||||
|
||||
#define ADC_AREF 3.3f
|
||||
#define BATVOLT_R1 2.0f
|
||||
#define BATVOLT_R2 2.0f
|
||||
#define BATVOLT_PIN BAT_VOLT
|
||||
|
||||
int getBattery()
|
||||
{
|
||||
return ((ADC_AREF / 1.023) * (BATVOLT_R1 + BATVOLT_R2) / BATVOLT_R2 * (float)analogRead(BATVOLT_PIN));
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
#include <Arduino.h>
|
||||
|
||||
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);
|
||||
}
|
Loading…
Reference in New Issue