lorawan/sodaq_one/sodaq_one.ino

132 lines
2.2 KiB
Arduino
Raw Normal View History

2016-10-24 19:34:02 +00:00
#include <Arduino.h>
#include <Wire.h>
#include <math.h>
2016-10-24 19:34:02 +00:00
#include "nsarduino.h"
#define debugSerial SerialUSB
/* Which network to use */
#define LORADEV 1
// #define SWISSCOM 1
// #define LORIOT 1
#define TTN 1
2016-10-24 19:34:02 +00:00
#define BUZZER_PIN 2
void signal_loop_start()
{
blink(30); delay(50);
blink(30); delay(50);
blink(30); delay(50);
}
int sleepcnt;
2016-10-24 19:34:02 +00:00
void setup() {
while ((!SerialUSB) && (millis() < 10000)){
// Wait 10 seconds for the Serial Monitor
}
/* Enable the pins 2/3, 6/7 and 8/9 */
pinMode(11, OUTPUT);
digitalWrite(11, HIGH);
setupLED();
gpsSetup();
// setupBuzzer();
2016-10-24 19:34:02 +00:00
setupCompass();
setupSunLight();
loraSetup();
/* sleep little in the beginning, longer the longer we run */
sleepcnt = 0;
2016-10-24 19:34:02 +00:00
}
void sendIntAsString(String prefix, int value) {
String tmp = prefix + String(value);
debugSerial.println(tmp);
loraSend(tmp);
}
void sendFloatAsString(String prefix, float value) {
String tmp = prefix + String(value);
debugSerial.println(tmp);
loraSend(tmp);
}
2016-10-24 19:34:02 +00:00
String tmps;
#define TEMP_PIN 2
#define LOUDNESS_PIN 0
#define SLEEPTIME 5*60*1000
2016-10-24 19:34:02 +00:00
void loop() {
signal_loop_start();
sendFloatAsString("temperature=", getTemperature(TEMP_PIN));
/* loraSend(String("node=") + String(deviceNo)); */
2016-10-24 19:34:02 +00:00
sendIntAsString("battery=", getBatteryVoltage());
sendIntAsString("loudness=", readLoudness(LOUDNESS_PIN));
2016-10-24 19:43:59 +00:00
loraSend(getSunLight());
loraSend(getCompass());
2016-10-24 19:34:02 +00:00
if((tmps = gpsGetPostion(120)) != "") {
loraSend(tmps);
}
2016-10-24 19:34:02 +00:00
if(sleepcnt < 10) {
sleepcnt++;
delay(10000);
} else {
delay(SLEEPTIME);
}
2016-10-24 19:34:02 +00:00
}
/* Node = 2
48
48
48
52
65
51
48
66
hex: 3030303441333042
*/
/* temp / humidity code (not functional)
/* humid / temperature */
/*
*/
2016-10-24 19:34:02 +00:00
/* #include <Wire.h> */
/* #include <HDC1000.h> */
2016-10-24 19:34:02 +00:00
/* HDC1000 hdc; */
/* float temperature; */
/* float humidity; */
2016-10-24 19:34:02 +00:00
/* 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); */