Cleanup sodaq code

This commit is contained in:
Nico Schottelius 2016-11-02 17:38:56 +01:00
parent ef99c3953c
commit 8e0aa77715
4 changed files with 50 additions and 54 deletions

View file

@ -15,12 +15,12 @@ String getCompass()
String tmps;
compass.read();
tmps = String("compass.a.x=" ) + compass.a.x +
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.z=" ) + compass.m.z;
tmps = String("compass a.x=" ) + compass.a.x +
String(" a.y=" ) + compass.a.y +
String(" a.z=" ) + compass.a.z +
String(" m.x=" ) + compass.m.x +
String(" m.y=" ) + compass.m.y +
String(" m.z=" ) + compass.m.z;
debugSerial.println(tmps);

View file

@ -42,9 +42,11 @@ void blink(int length) {
#elif LORADEV == 2
RED();
#elif LORADEV == 3
GREEN();
YELLOW();
#elif LORADEV == 4
WHITE();
#else
GREEN();
#endif
delay(length);
CLEAR();

View file

@ -4,7 +4,6 @@
#define loraSerial Serial1
#define beePin ENABLE_PIN_IO
#ifdef LORA_ABP
void setupLoRaABP(){
if (LoRaBee.initABP(loraSerial, devAddr, appSKey, nwkSKey, true))
@ -34,7 +33,7 @@ void setupLoRaOTAA(){
void loraSetup()
{
pinMode(ENABLE_PIN_IO, OUTPUT); // ONE
pinMode(beePin, OUTPUT); // ONE
digitalWrite(beePin, HIGH); // Lorawan
loraSerial.begin(LoRaBee.getDefaultBaudRate());
@ -48,6 +47,7 @@ void loraSetup()
}
void loraSend(String packet){
debugSerial.println("Trying to send: " + packet);
switch (LoRaBee.sendReqAck(1, (uint8_t*)packet.c_str(), packet.length(), 8))
{
case NoError:

View file

@ -1,18 +1,17 @@
#include <Arduino.h>
#include <Wire.h>
#include <math.h>
#include "nsarduino.h"
#define DEBUG 1
#define debugSerial SerialUSB
/* Which network to use */
/* Which network to use, which device it is (internal only) */
#define LORADEV 1
// #define SWISSCOM 1
#define SWISSCOM 1
// #define LORIOT 1
#define TTN 1
#define BUZZER_PIN 2
// #define TTN 1
void signal_loop_start()
{
@ -21,8 +20,7 @@ void signal_loop_start()
blink(30); delay(50);
}
int sleepcnt;
int cnt;
void setup() {
while ((!SerialUSB) && (millis() < 10000)){
@ -34,18 +32,15 @@ void setup() {
digitalWrite(11, HIGH);
setupLED();
gpsSetup();
// gpsSetup();
// setupBuzzer();
setupCompass();
setupSunLight();
// setupCompass();
// setupSunLight();
loraSetup();
/* sleep little in the beginning, longer the longer we run */
sleepcnt = 0;
cnt = 0;
}
@ -63,33 +58,48 @@ void sendFloatAsString(String prefix, float value) {
String tmps;
float tmp;
#define TEMP_PIN 2
#define LOUDNESS_PIN 0
#define BUZZER_PIN 2
#define SLEEPTIME 5*60*1000
#define SLEEPTIME 10000
#define LOUDNESS_AVG 6
int loudnesses[LOUDNESS_AVG];
void loop() {
signal_loop_start();
sendFloatAsString("temperature=", getTemperature(TEMP_PIN));
/* loraSend(String("node=") + String(deviceNo)); */
sendIntAsString("battery=", getBatteryVoltage());
sendIntAsString("loudness=", readLoudness(LOUDNESS_PIN));
loraSend(getSunLight());
loraSend(getCompass());
if((tmps = gpsGetPostion(120)) != "") {
loraSend(tmps);
}
// sendIntAsString("loudness=", readLoudness(LOUDNESS_PIN));
// loraSend(getSunLight());
// loraSend(getTempHumidHDC1000());
// loraSend(getCompass());
if(sleepcnt < 10) {
sleepcnt++;
delay(10000);
/* if((tmps = gpsGetPostion(120)) != "") { */
/* loraSend(tmps); */
/* } */
if(cnt < LOUDNESS_AVG) {
loudnesses[cnt] = readLoudness(LOUDNESS_PIN);
debugSerial.println("temploudness=" + String(loudnesses[cnt]));
cnt++;
} else {
delay(SLEEPTIME);
tmp = 0;
for(cnt = 0; cnt < LOUDNESS_AVG; cnt++) {
tmp += loudnesses[cnt];
}
tmp = tmp / (float) (cnt+1);
sendFloatAsString("loudness=", tmp);
sendIntAsString( "battery=", getBatteryVoltage());
// sendFloatAsString("temperature=", getTemperature(TEMP_PIN));
cnt = 0;
}
delay(SLEEPTIME);
}
@ -113,19 +123,3 @@ hex: 3030303441333042
*/
/* #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); */