update
Signed-off-by: Nico Schottelius <nico@wurzel.schottelius.org>
This commit is contained in:
parent
2b37c75c15
commit
95d8e8bfe5
8 changed files with 109 additions and 51 deletions
|
@ -19,9 +19,12 @@ class Loriot():
|
|||
while True:
|
||||
result = self.ws.recv()
|
||||
print(result)
|
||||
jdata = jsonToDict(result)
|
||||
eui = devEUI(jdata)
|
||||
payload = get_payloan(jdata)
|
||||
|
||||
jdata = self.jsonToDict(result)
|
||||
eui = self.devEUI(jdata)
|
||||
self.insert_json("loriot", result, deveui=eui)
|
||||
|
||||
# payload = self.get_payload(jdata)
|
||||
|
||||
|
||||
def jsonToDict(self, data):
|
||||
|
@ -30,8 +33,9 @@ class Loriot():
|
|||
def devEUI(self, data):
|
||||
return data['EUI']
|
||||
|
||||
def get_payload(self, ):
|
||||
return data['EUI']
|
||||
def get_payload(self, data):
|
||||
return ""
|
||||
# return data['EUI']
|
||||
|
||||
def insert_json(self, provider, data, payload='', deveui=''):
|
||||
try:
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
|
||||
LSM303 compass;
|
||||
|
||||
char compassReport[80];
|
||||
|
||||
void setupCompass()
|
||||
{
|
||||
Wire.begin();
|
||||
|
@ -21,13 +19,10 @@ String getCompass()
|
|||
String(" compass.a.y=" ) + compass.a.y +
|
||||
String(" compass.a.z=" ) + compass.a.z +
|
||||
String(" compass.m.x=" ) + compass.m.x +
|
||||
String(" compass.m.y" ) + compass.m.y +
|
||||
String(" compass.m.y=" ) + compass.m.y +
|
||||
String(" compass.m.z=" ) + compass.m.z;
|
||||
|
||||
debugSerial.println(tmps);
|
||||
|
||||
/* snprintf(compassReport, sizeof(compassReport), "A: %6d %6d %6d M: %6d %6d %6d", */
|
||||
/* compass.a.x, compass.a.y, compass.a.z, */
|
||||
/* compass.m.x, compass.m.y, compass.m.z); */
|
||||
|
||||
return tmps;
|
||||
}
|
||||
|
|
|
@ -1,14 +1,20 @@
|
|||
#include <Arduino.h>
|
||||
#include <Sodaq_UBlox_GPS.h>
|
||||
|
||||
void gpsSetup() { sodaq_gps.init(GPS_ENABLE); }
|
||||
void gpsSetup() {
|
||||
sodaq_gps.init(GPS_ENABLE);
|
||||
}
|
||||
|
||||
/* FIXME: find out power consumption if turned off */
|
||||
// void gpsStop() { sodaq_gps.off(); }
|
||||
|
||||
|
||||
/*!
|
||||
* Find a GPS fix, but first wait a while
|
||||
*/
|
||||
String gpsGetPostion(long waittime)
|
||||
{
|
||||
String res;
|
||||
String res = "";
|
||||
uint32_t timeout = waittime * 1000;
|
||||
|
||||
debugSerial.println(String("waiting for fix ..., timeout=") + timeout + String("ms"));
|
||||
|
@ -24,7 +30,6 @@ String gpsGetPostion(long waittime)
|
|||
debugSerial.println(res);
|
||||
} else {
|
||||
debugSerial.println("GPS: No Fix");
|
||||
return "";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -35,6 +40,8 @@ String gpsGetDateTime(long waittime) {
|
|||
if (sodaq_gps.scan(false, timeout)) {
|
||||
res= String("datetime =") + sodaq_gps.getDateTimeString();
|
||||
debugSerial.println(res);
|
||||
} else {
|
||||
debugSerial.println("GPS: No Fix");
|
||||
}
|
||||
|
||||
return res;
|
||||
|
|
|
@ -37,20 +37,15 @@ void CLEAR() {
|
|||
}
|
||||
|
||||
void blink(int length) {
|
||||
switch(deviceNo) {
|
||||
case 1:
|
||||
#if LORADEV == 1
|
||||
BLUE();
|
||||
break;
|
||||
case 2:
|
||||
#elif LORADEV == 2
|
||||
RED();
|
||||
break;
|
||||
case 3:
|
||||
#elif LORADEV == 3
|
||||
GREEN();
|
||||
break;
|
||||
case 4:
|
||||
#elif LORADEV == 4
|
||||
WHITE();
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
delay(length);
|
||||
CLEAR();
|
||||
}
|
||||
|
|
|
@ -87,4 +87,7 @@ void loraSend(String packet){
|
|||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* Delay some time to give avoid keeping the device busy */
|
||||
delay(2000);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include <Arduino.h>
|
||||
|
||||
int readLoudness()
|
||||
int readLoudness(int pin)
|
||||
{
|
||||
return analogRead(LOUDNESS_SENSOR);
|
||||
return analogRead(pin);
|
||||
}
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "nsarduino.h"
|
||||
|
||||
#define debugSerial SerialUSB
|
||||
|
||||
#define deviceNo 2
|
||||
/* Which network to use */
|
||||
#define LORADEV 1
|
||||
// #define SWISSCOM 1
|
||||
// #define LORIOT 1
|
||||
#define TTN 1
|
||||
|
||||
#define LOUDNESS_SENSOR 0
|
||||
#define USE_LOUDNESS 1
|
||||
#define BUZZER_PIN 2
|
||||
|
||||
void signal_loop_start()
|
||||
|
@ -18,10 +21,8 @@ void signal_loop_start()
|
|||
blink(30); delay(50);
|
||||
}
|
||||
|
||||
void signal_loop_end()
|
||||
{
|
||||
blink(1000); delay(29000);
|
||||
}
|
||||
|
||||
int sleepcnt;
|
||||
|
||||
void setup() {
|
||||
while ((!SerialUSB) && (millis() < 10000)){
|
||||
|
@ -34,10 +35,17 @@ void setup() {
|
|||
|
||||
setupLED();
|
||||
gpsSetup();
|
||||
setupBuzzer();
|
||||
|
||||
// setupBuzzer();
|
||||
|
||||
setupCompass();
|
||||
setupSunLight();
|
||||
loraSetup();
|
||||
|
||||
|
||||
/* sleep little in the beginning, longer the longer we run */
|
||||
sleepcnt = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -47,22 +55,41 @@ void sendIntAsString(String prefix, int value) {
|
|||
loraSend(tmp);
|
||||
}
|
||||
|
||||
void sendFloatAsString(String prefix, float value) {
|
||||
String tmp = prefix + String(value);
|
||||
debugSerial.println(tmp);
|
||||
loraSend(tmp);
|
||||
}
|
||||
|
||||
|
||||
String tmps;
|
||||
|
||||
#define TEMP_PIN 2
|
||||
#define LOUDNESS_PIN 0
|
||||
|
||||
#define SLEEPTIME 5*60*1000
|
||||
|
||||
void loop() {
|
||||
signal_loop_start();
|
||||
|
||||
loraSend(String("node=") + String(deviceNo));
|
||||
sendFloatAsString("temperature=", getTemperature(TEMP_PIN));
|
||||
|
||||
/* loraSend(String("node=") + String(deviceNo)); */
|
||||
sendIntAsString("battery=", getBatteryVoltage());
|
||||
sendIntAsString("loudness=", readLoudness());
|
||||
sendIntAsString("loudness=", readLoudness(LOUDNESS_PIN));
|
||||
loraSend(getSunLight());
|
||||
loraSend(getCompass());
|
||||
|
||||
/* if((tmps = gpsGetPostion(120)) != "") { */
|
||||
/* loraSend(tmps); */
|
||||
/* } */
|
||||
if((tmps = gpsGetPostion(120)) != "") {
|
||||
loraSend(tmps);
|
||||
}
|
||||
|
||||
signal_loop_end();
|
||||
if(sleepcnt < 10) {
|
||||
sleepcnt++;
|
||||
delay(10000);
|
||||
} else {
|
||||
delay(SLEEPTIME);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -83,17 +110,22 @@ hex: 3030303441333042
|
|||
|
||||
/* humid / temperature */
|
||||
/*
|
||||
#include <HDC1000.h>
|
||||
|
||||
HDC1000 hdc;
|
||||
|
||||
float temperature;
|
||||
float humidity;
|
||||
|
||||
|
||||
*/
|
||||
|
||||
// temperature = hdc.getTemperature();
|
||||
// humidity = hdc.getHumidity();
|
||||
// String msg_tmphumid = String("tmp=") + temperature + String(" humid=") + humidity;
|
||||
// debugSerial.println(msg_tmphumid);
|
||||
/* #include <Wire.h> */
|
||||
/* #include <HDC1000.h> */
|
||||
|
||||
/* HDC1000 hdc; */
|
||||
|
||||
/* float temperature; */
|
||||
/* float humidity; */
|
||||
|
||||
/* hdc.begin(); delay(500); */
|
||||
/* temperature = hdc.getTemperature(); */
|
||||
/* delay(500); */
|
||||
/* hdc.begin(); delay(500); */
|
||||
/* humidity = hdc.getHumidity(); */
|
||||
/* String msg_tmphumid = String("tmp=") + temperature + String(" humid=") + humidity; */
|
||||
/* debugSerial.println(msg_tmphumid); */
|
||||
|
|
22
sodaq_one/temperature.ino
Normal file
22
sodaq_one/temperature.ino
Normal file
|
@ -0,0 +1,22 @@
|
|||
#include <Arduino.h>
|
||||
|
||||
/*
|
||||
* Temp sensor:
|
||||
* https://www.seeedstudio.com/Grove-Temperature-Sensor-p-774.html
|
||||
*
|
||||
** NCP18WF104F03RC
|
||||
*/
|
||||
|
||||
float getTemperature(int pin) {
|
||||
int a = analogRead(pin);
|
||||
|
||||
const int B=4250; // B value of the thermistor
|
||||
|
||||
float R = 1023.0/((float)a)-1.0;
|
||||
|
||||
R = 100000.0*R;
|
||||
|
||||
float temperature=1.0/(log(R/100000.0)/B+1/298.15)-273.15;
|
||||
|
||||
return temperature;
|
||||
}
|
Loading…
Reference in a new issue