lorawan/sodaq_one/sodaq_one.ino

139 lines
2.7 KiB
Arduino
Raw Normal View History

2016-10-24 19:34:02 +00:00
#include <Arduino.h>
#include <Wire.h>
#include <math.h>
2017-01-04 08:33:19 +00:00
#include <Sodaq_UBlox_GPS.h>
2016-10-24 19:34:02 +00:00
#include "nsarduino.h"
2017-02-19 10:07:05 +00:00
#include "internal.h"
2016-10-24 19:34:02 +00:00
#define debugSerial SerialUSB
void signal_loop_start()
{
blink(30); delay(50);
blink(30); delay(50);
blink(30); delay(50);
}
2016-11-12 19:01:48 +00:00
#define TEMP_PIN 2
#define LOUDNESS_PIN 0
2017-02-19 10:07:05 +00:00
#define BUZZER_PIN 6
2016-11-12 19:01:48 +00:00
#define WATER_SENSOR_PIN 6
2016-11-02 16:38:56 +00:00
int cnt;
2016-10-24 19:34:02 +00:00
void setup() {
while ((!SerialUSB) && (millis() < 10000)){
// Wait 10 seconds for the Serial Monitor
}
}
String tmps;
2016-11-02 16:38:56 +00:00
float tmp;
2016-10-24 19:34:02 +00:00
2016-11-02 16:38:56 +00:00
#define SLEEPTIME 10000
#define LOUDNESS_AVG 3
2016-11-02 16:38:56 +00:00
int loudnesses[LOUDNESS_AVG];
2016-10-24 19:34:02 +00:00
void loop() {
2017-02-19 10:07:05 +00:00
signal_loop_start();
debugSerial.println("Deveui = " + String(LORADEV) + " => " + String(LORA_ADDR));
2016-10-24 19:34:02 +00:00
2016-11-12 19:01:48 +00:00
/* if(hasWater(WATER_SENSOR_PIN)) { */
/* debugSerial.println("Having water"); */
/* loraSend(getWater(WATER_SENSOR_PIN)); */
/* buzz(BUZZER_PIN, 5000); */
/* } else { */
/* loraSend(getWater(WATER_SENSOR_PIN)); */
/* debugSerial.println("it's dry"); */
/* } */
2016-11-02 16:38:56 +00:00
// loraSend(getSunLight());
// loraSend(getTempHumidHDC1000());
// loraSend(getCompass());
2016-10-24 19:34:02 +00:00
2017-01-04 08:33:19 +00:00
/* Tracker code */
/* if((tmps = gpsGetPostion(120)) != "") { */
/* loraSend(tmps); */
2016-11-12 19:01:48 +00:00
/* } */
2016-11-03 07:08:08 +00:00
sendIntAsString("battery=", getBattery());
2017-01-04 08:33:19 +00:00
/* Temp & loudness code */
if(cnt < LOUDNESS_AVG) {
loudnesses[cnt] = readLoudness(LOUDNESS_PIN);
debugSerial.println("temploudness=" + String(loudnesses[cnt]));
cnt++;
} else {
tmp = 0;
for(cnt = 0; cnt < LOUDNESS_AVG; cnt++) {
tmp += loudnesses[cnt];
}
tmp = tmp / (float) (cnt+1);
sendFloatAsString("temperature=", getTemperature(TEMP_PIN));
sendFloatAsString("loudness=", tmp);
/* audio representation of temperature */
tmp = getTemperature(TEMP_PIN);
if(tmp < 0) {
buzz(BUZZER_PIN, 50);
}
if(tmp > 0 && tmp <= 20) {
buzz(BUZZER_PIN, 100);
delay(50);
buzz(BUZZER_PIN, 100);
}
if(tmp > 20 && tmp <= 30) {
buzz(BUZZER_PIN, 100);
delay(50);
buzz(BUZZER_PIN, 100);
delay(50);
buzz(BUZZER_PIN, 100);
}
if(tmp > 30 && tmp <= 40) {
buzz(BUZZER_PIN, 100);
delay(50);
buzz(BUZZER_PIN, 100);
delay(50);
buzz(BUZZER_PIN, 100);
delay(50);
buzz(BUZZER_PIN, 100);
}
if(tmp > 40) {
buzz(BUZZER_PIN, 3000);
delay(50);
}
2017-01-04 08:33:19 +00:00
cnt = 0;
}
2016-11-02 16:38:56 +00:00
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)