Cleanup sodaq code
This commit is contained in:
parent
ef99c3953c
commit
8e0aa77715
|
@ -15,12 +15,12 @@ String getCompass()
|
||||||
String tmps;
|
String tmps;
|
||||||
compass.read();
|
compass.read();
|
||||||
|
|
||||||
tmps = String("compass.a.x=" ) + compass.a.x +
|
tmps = String("compass a.x=" ) + compass.a.x +
|
||||||
String(" compass.a.y=" ) + compass.a.y +
|
String(" a.y=" ) + compass.a.y +
|
||||||
String(" compass.a.z=" ) + compass.a.z +
|
String(" a.z=" ) + compass.a.z +
|
||||||
String(" compass.m.x=" ) + compass.m.x +
|
String(" m.x=" ) + compass.m.x +
|
||||||
String(" compass.m.y=" ) + compass.m.y +
|
String(" m.y=" ) + compass.m.y +
|
||||||
String(" compass.m.z=" ) + compass.m.z;
|
String(" m.z=" ) + compass.m.z;
|
||||||
|
|
||||||
debugSerial.println(tmps);
|
debugSerial.println(tmps);
|
||||||
|
|
||||||
|
|
|
@ -42,9 +42,11 @@ void blink(int length) {
|
||||||
#elif LORADEV == 2
|
#elif LORADEV == 2
|
||||||
RED();
|
RED();
|
||||||
#elif LORADEV == 3
|
#elif LORADEV == 3
|
||||||
GREEN();
|
YELLOW();
|
||||||
#elif LORADEV == 4
|
#elif LORADEV == 4
|
||||||
WHITE();
|
WHITE();
|
||||||
|
#else
|
||||||
|
GREEN();
|
||||||
#endif
|
#endif
|
||||||
delay(length);
|
delay(length);
|
||||||
CLEAR();
|
CLEAR();
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#define loraSerial Serial1
|
#define loraSerial Serial1
|
||||||
#define beePin ENABLE_PIN_IO
|
#define beePin ENABLE_PIN_IO
|
||||||
|
|
||||||
|
|
||||||
#ifdef LORA_ABP
|
#ifdef LORA_ABP
|
||||||
void setupLoRaABP(){
|
void setupLoRaABP(){
|
||||||
if (LoRaBee.initABP(loraSerial, devAddr, appSKey, nwkSKey, true))
|
if (LoRaBee.initABP(loraSerial, devAddr, appSKey, nwkSKey, true))
|
||||||
|
@ -34,7 +33,7 @@ void setupLoRaOTAA(){
|
||||||
|
|
||||||
void loraSetup()
|
void loraSetup()
|
||||||
{
|
{
|
||||||
pinMode(ENABLE_PIN_IO, OUTPUT); // ONE
|
pinMode(beePin, OUTPUT); // ONE
|
||||||
digitalWrite(beePin, HIGH); // Lorawan
|
digitalWrite(beePin, HIGH); // Lorawan
|
||||||
loraSerial.begin(LoRaBee.getDefaultBaudRate());
|
loraSerial.begin(LoRaBee.getDefaultBaudRate());
|
||||||
|
|
||||||
|
@ -48,6 +47,7 @@ void loraSetup()
|
||||||
}
|
}
|
||||||
|
|
||||||
void loraSend(String packet){
|
void loraSend(String packet){
|
||||||
|
debugSerial.println("Trying to send: " + packet);
|
||||||
switch (LoRaBee.sendReqAck(1, (uint8_t*)packet.c_str(), packet.length(), 8))
|
switch (LoRaBee.sendReqAck(1, (uint8_t*)packet.c_str(), packet.length(), 8))
|
||||||
{
|
{
|
||||||
case NoError:
|
case NoError:
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "nsarduino.h"
|
#include "nsarduino.h"
|
||||||
|
|
||||||
|
#define DEBUG 1
|
||||||
|
|
||||||
#define debugSerial SerialUSB
|
#define debugSerial SerialUSB
|
||||||
|
|
||||||
/* Which network to use */
|
/* Which network to use, which device it is (internal only) */
|
||||||
#define LORADEV 1
|
#define LORADEV 1
|
||||||
// #define SWISSCOM 1
|
#define SWISSCOM 1
|
||||||
// #define LORIOT 1
|
// #define LORIOT 1
|
||||||
#define TTN 1
|
// #define TTN 1
|
||||||
|
|
||||||
#define BUZZER_PIN 2
|
|
||||||
|
|
||||||
void signal_loop_start()
|
void signal_loop_start()
|
||||||
{
|
{
|
||||||
|
@ -21,8 +20,7 @@ void signal_loop_start()
|
||||||
blink(30); delay(50);
|
blink(30); delay(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int cnt;
|
||||||
int sleepcnt;
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
while ((!SerialUSB) && (millis() < 10000)){
|
while ((!SerialUSB) && (millis() < 10000)){
|
||||||
|
@ -34,18 +32,15 @@ void setup() {
|
||||||
digitalWrite(11, HIGH);
|
digitalWrite(11, HIGH);
|
||||||
|
|
||||||
setupLED();
|
setupLED();
|
||||||
gpsSetup();
|
// gpsSetup();
|
||||||
|
|
||||||
// setupBuzzer();
|
// setupBuzzer();
|
||||||
|
|
||||||
setupCompass();
|
// setupCompass();
|
||||||
setupSunLight();
|
// setupSunLight();
|
||||||
loraSetup();
|
loraSetup();
|
||||||
|
|
||||||
|
cnt = 0;
|
||||||
/* sleep little in the beginning, longer the longer we run */
|
|
||||||
sleepcnt = 0;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,33 +58,48 @@ void sendFloatAsString(String prefix, float value) {
|
||||||
|
|
||||||
|
|
||||||
String tmps;
|
String tmps;
|
||||||
|
float tmp;
|
||||||
|
|
||||||
#define TEMP_PIN 2
|
#define TEMP_PIN 2
|
||||||
#define LOUDNESS_PIN 0
|
#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() {
|
void loop() {
|
||||||
signal_loop_start();
|
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)) != "") {
|
// sendIntAsString("loudness=", readLoudness(LOUDNESS_PIN));
|
||||||
loraSend(tmps);
|
// loraSend(getSunLight());
|
||||||
}
|
// loraSend(getTempHumidHDC1000());
|
||||||
|
// loraSend(getCompass());
|
||||||
|
|
||||||
if(sleepcnt < 10) {
|
/* if((tmps = gpsGetPostion(120)) != "") { */
|
||||||
sleepcnt++;
|
/* loraSend(tmps); */
|
||||||
delay(10000);
|
/* } */
|
||||||
|
|
||||||
|
if(cnt < LOUDNESS_AVG) {
|
||||||
|
loudnesses[cnt] = readLoudness(LOUDNESS_PIN);
|
||||||
|
debugSerial.println("temploudness=" + String(loudnesses[cnt]));
|
||||||
|
cnt++;
|
||||||
} else {
|
} 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); */
|
|
||||||
|
|
Loading…
Reference in New Issue