Cleanups in sodaq code

This commit is contained in:
Nico Schottelius 2016-11-03 08:08:08 +01:00
parent 13d434cf47
commit 73dcd8879e
6 changed files with 39 additions and 24 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@ Sodaq_UBlox_GPS/
libraries/ libraries/
a.out a.out
/venv/ /venv/
/sodaq_one/internal.h

View file

@ -40,11 +40,12 @@ void blink(int length) {
#if LORADEV == 1 #if LORADEV == 1
BLUE(); BLUE();
#elif LORADEV == 2 #elif LORADEV == 2
RED(); WHITE();
#elif LORADEV == 3 #elif LORADEV == 3
YELLOW(); YELLOW();
#elif LORADEV == 4 #elif LORADEV == 4
WHITE(); RED();
#else #else
GREEN(); GREEN();
#endif #endif

View file

@ -1,5 +1,6 @@
#include <Arduino.h> #include <Arduino.h>
#include "Sodaq_RN2483.h" #include "Sodaq_RN2483.h"
#include "internal.h"
#define loraSerial Serial1 #define loraSerial Serial1
#define beePin ENABLE_PIN_IO #define beePin ENABLE_PIN_IO
@ -91,3 +92,15 @@ void loraSend(String packet){
/* Delay some time to give avoid keeping the device busy */ /* Delay some time to give avoid keeping the device busy */
delay(2000); delay(2000);
} }
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);
}

View file

@ -1,7 +1,3 @@
#define SWISSCOM 1
#define TTN 2
#define LORIOT 3
/* battery.ino */ /* battery.ino */
uint16_t getBatteryVoltage(); uint16_t getBatteryVoltage();

View file

@ -5,7 +5,6 @@
#define debugSerial SerialUSB #define debugSerial SerialUSB
void signal_loop_start() void signal_loop_start()
{ {
blink(30); delay(50); blink(30); delay(50);
@ -36,26 +35,12 @@ void setup() {
cnt = 0; cnt = 0;
} }
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);
}
String tmps; String tmps;
float tmp; float tmp;
#define TEMP_PIN 2 #define TEMP_PIN 2
#define LOUDNESS_PIN 0 #define LOUDNESS_PIN 0
#define BUZZER_PIN 2 #define BUZZER_PIN 6
#define SLEEPTIME 10000 #define SLEEPTIME 10000
@ -66,7 +51,6 @@ void loop() {
signal_loop_start(); signal_loop_start();
// sendIntAsString("loudness=", readLoudness(LOUDNESS_PIN)); // sendIntAsString("loudness=", readLoudness(LOUDNESS_PIN));
// loraSend(getSunLight()); // loraSend(getSunLight());
// loraSend(getTempHumidHDC1000()); // loraSend(getTempHumidHDC1000());
@ -76,6 +60,8 @@ void loop() {
/* loraSend(tmps); */ /* loraSend(tmps); */
/* } */ /* } */
if(cnt < LOUDNESS_AVG) { if(cnt < LOUDNESS_AVG) {
loudnesses[cnt] = readLoudness(LOUDNESS_PIN); loudnesses[cnt] = readLoudness(LOUDNESS_PIN);
debugSerial.println("temploudness=" + String(loudnesses[cnt])); debugSerial.println("temploudness=" + String(loudnesses[cnt]));
@ -87,8 +73,8 @@ void loop() {
} }
tmp = tmp / (float) (cnt+1); tmp = tmp / (float) (cnt+1);
sendIntAsString("battery=", getBatteryVoltage());
sendFloatAsString("loudness=", tmp); sendFloatAsString("loudness=", tmp);
sendIntAsString( "battery=", getBatteryVoltage());
sendFloatAsString("temperature=", getTemperature(TEMP_PIN)); sendFloatAsString("temperature=", getTemperature(TEMP_PIN));
cnt = 0; cnt = 0;
} }

View file

@ -0,0 +1,18 @@
#include <Arduino.h>
#include <Wire.h>
#include <HDC1000.h>
HDC1000 hdc;
void setupTempHumidHDC1000() {
hdc.begin(); delay(500);
}
String getTempHumidHDC1000() {
float temperature;
float humidity;
humidity = hdc.getHumidity();
temperature = hdc.getTemperature();
return String("tmp=") + temperature + String(" humid=") + humidity;
}