Signed-off-by: Nico Schottelius <nico@wurzel.schottelius.org>
This commit is contained in:
Nico Schottelius 2016-10-27 18:14:29 +02:00
parent 2b37c75c15
commit 95d8e8bfe5
8 changed files with 109 additions and 51 deletions

View file

@ -19,9 +19,12 @@ class Loriot():
while True: while True:
result = self.ws.recv() result = self.ws.recv()
print(result) print(result)
jdata = jsonToDict(result)
eui = devEUI(jdata) jdata = self.jsonToDict(result)
payload = get_payloan(jdata) eui = self.devEUI(jdata)
self.insert_json("loriot", result, deveui=eui)
# payload = self.get_payload(jdata)
def jsonToDict(self, data): def jsonToDict(self, data):
@ -30,8 +33,9 @@ class Loriot():
def devEUI(self, data): def devEUI(self, data):
return data['EUI'] return data['EUI']
def get_payload(self, ): def get_payload(self, data):
return data['EUI'] return ""
# return data['EUI']
def insert_json(self, provider, data, payload='', deveui=''): def insert_json(self, provider, data, payload='', deveui=''):
try: try:

View file

@ -3,8 +3,6 @@
LSM303 compass; LSM303 compass;
char compassReport[80];
void setupCompass() void setupCompass()
{ {
Wire.begin(); Wire.begin();
@ -21,13 +19,10 @@ String getCompass()
String(" compass.a.y=" ) + compass.a.y + String(" compass.a.y=" ) + compass.a.y +
String(" compass.a.z=" ) + compass.a.z + String(" compass.a.z=" ) + compass.a.z +
String(" compass.m.x=" ) + compass.m.x + 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; String(" compass.m.z=" ) + compass.m.z;
debugSerial.println(tmps); debugSerial.println(tmps);
/* snprintf(compassReport, sizeof(compassReport), "A: %6d %6d %6d M: %6d %6d %6d", */ return tmps;
/* compass.a.x, compass.a.y, compass.a.z, */
/* compass.m.x, compass.m.y, compass.m.z); */
} }

View file

@ -1,14 +1,20 @@
#include <Arduino.h> #include <Arduino.h>
#include <Sodaq_UBlox_GPS.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 * Find a GPS fix, but first wait a while
*/ */
String gpsGetPostion(long waittime) String gpsGetPostion(long waittime)
{ {
String res; String res = "";
uint32_t timeout = waittime * 1000; uint32_t timeout = waittime * 1000;
debugSerial.println(String("waiting for fix ..., timeout=") + timeout + String("ms")); debugSerial.println(String("waiting for fix ..., timeout=") + timeout + String("ms"));
@ -24,7 +30,6 @@ String gpsGetPostion(long waittime)
debugSerial.println(res); debugSerial.println(res);
} else { } else {
debugSerial.println("GPS: No Fix"); debugSerial.println("GPS: No Fix");
return "";
} }
return res; return res;
} }
@ -35,6 +40,8 @@ String gpsGetDateTime(long waittime) {
if (sodaq_gps.scan(false, timeout)) { if (sodaq_gps.scan(false, timeout)) {
res= String("datetime =") + sodaq_gps.getDateTimeString(); res= String("datetime =") + sodaq_gps.getDateTimeString();
debugSerial.println(res); debugSerial.println(res);
} else {
debugSerial.println("GPS: No Fix");
} }
return res; return res;

View file

@ -37,20 +37,15 @@ void CLEAR() {
} }
void blink(int length) { void blink(int length) {
switch(deviceNo) { #if LORADEV == 1
case 1:
BLUE(); BLUE();
break; #elif LORADEV == 2
case 2:
RED(); RED();
break; #elif LORADEV == 3
case 3:
GREEN(); GREEN();
break; #elif LORADEV == 4
case 4:
WHITE(); WHITE();
break; #endif
}
delay(length); delay(length);
CLEAR(); CLEAR();
} }

View file

@ -87,4 +87,7 @@ void loraSend(String packet){
default: default:
break; break;
} }
/* Delay some time to give avoid keeping the device busy */
delay(2000);
} }

View file

@ -1,6 +1,6 @@
#include <Arduino.h> #include <Arduino.h>
int readLoudness() int readLoudness(int pin)
{ {
return analogRead(LOUDNESS_SENSOR); return analogRead(pin);
} }

View file

@ -1,14 +1,17 @@
#include <Arduino.h> #include <Arduino.h>
#include <Wire.h> #include <Wire.h>
#include <math.h>
#include "nsarduino.h" #include "nsarduino.h"
#define debugSerial SerialUSB #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 #define BUZZER_PIN 2
void signal_loop_start() void signal_loop_start()
@ -18,10 +21,8 @@ void signal_loop_start()
blink(30); delay(50); blink(30); delay(50);
} }
void signal_loop_end()
{ int sleepcnt;
blink(1000); delay(29000);
}
void setup() { void setup() {
while ((!SerialUSB) && (millis() < 10000)){ while ((!SerialUSB) && (millis() < 10000)){
@ -34,10 +35,17 @@ void setup() {
setupLED(); setupLED();
gpsSetup(); gpsSetup();
setupBuzzer();
// setupBuzzer();
setupCompass(); setupCompass();
setupSunLight(); setupSunLight();
loraSetup(); 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); loraSend(tmp);
} }
void sendFloatAsString(String prefix, float value) {
String tmp = prefix + String(value);
debugSerial.println(tmp);
loraSend(tmp);
}
String tmps; String tmps;
#define TEMP_PIN 2
#define LOUDNESS_PIN 0
#define SLEEPTIME 5*60*1000
void loop() { void loop() {
signal_loop_start(); signal_loop_start();
loraSend(String("node=") + String(deviceNo)); sendFloatAsString("temperature=", getTemperature(TEMP_PIN));
/* loraSend(String("node=") + String(deviceNo)); */
sendIntAsString("battery=", getBatteryVoltage()); sendIntAsString("battery=", getBatteryVoltage());
sendIntAsString("loudness=", readLoudness()); sendIntAsString("loudness=", readLoudness(LOUDNESS_PIN));
loraSend(getSunLight()); loraSend(getSunLight());
loraSend(getCompass()); loraSend(getCompass());
/* if((tmps = gpsGetPostion(120)) != "") { */ if((tmps = gpsGetPostion(120)) != "") {
/* loraSend(tmps); */ loraSend(tmps);
/* } */ }
signal_loop_end(); if(sleepcnt < 10) {
sleepcnt++;
delay(10000);
} else {
delay(SLEEPTIME);
}
} }
@ -83,17 +110,22 @@ hex: 3030303441333042
/* humid / temperature */ /* humid / temperature */
/* /*
#include <HDC1000.h>
HDC1000 hdc;
float temperature;
float humidity;
*/ */
// temperature = hdc.getTemperature(); /* #include <Wire.h> */
// humidity = hdc.getHumidity(); /* #include <HDC1000.h> */
// String msg_tmphumid = String("tmp=") + temperature + String(" humid=") + humidity;
// debugSerial.println(msg_tmphumid); /* 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
View 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;
}