This commit is contained in:
Nico Schottelius 2017-02-19 11:07:05 +01:00
parent 5c29282196
commit b96e09f3e7
9 changed files with 36 additions and 65 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ libraries/
a.out a.out
/venv/ /venv/
/sodaq_one/internal.h /sodaq_one/internal.h
/swisscom-pricing.png

View File

@ -29,6 +29,8 @@ log.setLevel(logging.DEBUG)
known_devices = [ "0018B20000000C58", "0018B20000000C37", "0018B20000000C59", "0018B20000000CD0", "0018B200000001C5" ] known_devices = [ "0018B20000000C58", "0018B20000000C37", "0018B20000000C59", "0018B20000000CD0", "0018B200000001C5" ]
def convert_gps_from_stdin(): def convert_gps_from_stdin():
for line in sys.stdin: for line in sys.stdin:
res = get_gps("", line) res = get_gps("", line)
@ -37,7 +39,8 @@ def convert_gps_from_stdin():
def get_gps(deveui, payload): def get_gps(deveui, payload):
res = [] res = []
if not int(payload[0:2], 16) & (2**7): if not int(payload[0:2], 16) & (2**4):
log.debug("No GPS information present")
return res return res
try: try:
@ -84,7 +87,7 @@ def decode_adeunis(provider, pkg):
# ttn -> base64 encoded # ttn -> base64 encoded
if provider == "ttn": if provider == "ttn":
binascii.b2a_hex(binascii.a2b_base64(payload)) payload = binascii.b2a_hex(binascii.a2b_base64(payload))
res = [] res = []

View File

@ -1,15 +0,0 @@
#include <Arduino.h>
#define ADC_AREF 3.3f
#define BATVOLT_R1 2.0f
#define BATVOLT_R2 2.0f
#define BATVOLT_PIN BAT_VOLT
// uint16_t getBatteryVoltage()
int getB()
{
uint16_t voltage = (uint16_t)((ADC_AREF / 1.023) * (BATVOLT_R1 + BATVOLT_R2) / BATVOLT_R2 * (float)analogRead(BATVOLT_PIN));
return voltage;
}

View File

@ -1,20 +0,0 @@
#include <Arduino.h>
void setupBuzzer(int pin)
{
pinMode(pin, OUTPUT);
}
void buzzerOn(int pin) {
digitalWrite(pin, HIGH);
}
void buzzerOff(int pin) {
digitalWrite(pin, LOW);
}
void buzz(int pin, int ms) {
buzzerOn(pin);
delay(ms);
buzzerOff(pin);
}

View File

@ -36,11 +36,13 @@ void CLEAR() {
digitalWrite(LED_BLUE, HIGH); digitalWrite(LED_BLUE, HIGH);
} }
void blink(int length) { void led_on() {
#if LORADEV == 1 #if LORADEV == 1
BLUE(); BLUE();
#elif LORADEV == 2 #elif LORADEV == 2
WHITE(); WHITE();
#elif LORADEV == 0xA2
WHITE();
#elif LORADEV == 3 #elif LORADEV == 3
YELLOW(); YELLOW();
#elif LORADEV == 4 #elif LORADEV == 4
@ -48,6 +50,14 @@ void blink(int length) {
#else #else
GREEN(); GREEN();
#endif #endif
}
void led_off() {
CLEAR();
}
void blink(int length) {
led_on();
delay(length); delay(length);
CLEAR(); CLEAR();
} }

View File

@ -49,7 +49,7 @@ void loraSetup()
void loraSend(String packet){ void loraSend(String packet){
debugSerial.println("Trying to send: " + packet); debugSerial.println("Trying to send: " + packet);
BLUE(); led_on();
/* with ack */ /* with ack */
//switch (LoRaBee.sendReqAck(1, (uint8_t*)packet.c_str(), packet.length(), 8)) //switch (LoRaBee.sendReqAck(1, (uint8_t*)packet.c_str(), packet.length(), 8))
@ -95,7 +95,7 @@ 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);
CLEAR(); led_off();
} }
void sendIntAsString(String prefix, int value) { void sendIntAsString(String prefix, int value) {

View File

@ -1,11 +0,0 @@
#include <Arduino.h>
#define ADC_AREF 3.3f
#define BATVOLT_R1 2.0f
#define BATVOLT_R2 2.0f
#define BATVOLT_PIN BAT_VOLT
int getB()
{
return ((ADC_AREF / 1.023) * (BATVOLT_R1 + BATVOLT_R2) / BATVOLT_R2 * (float)analogRead(BATVOLT_PIN));
}

View File

@ -2,13 +2,18 @@
/* battery.ino */ /* battery.ino */
// uint16_t getBatteryVoltage(); // uint16_t getBatteryVoltage();
int getB(); int getBattery();
void blink(int length); void blink(int length);
void led_on();
void led_off();
void setupBuzzer(int pin);
void buzzerOn(); void buzzerOn();
void buzzerOff(); void buzzerOff();
void buzz(int ms); void buzz(int pin, int ms);
/* compass.ino */ /* compass.ino */
extern char compassReport[80]; extern char compassReport[80];

View File

@ -3,6 +3,7 @@
#include <math.h> #include <math.h>
#include <Sodaq_UBlox_GPS.h> #include <Sodaq_UBlox_GPS.h>
#include "nsarduino.h" #include "nsarduino.h"
#include "internal.h"
#define debugSerial SerialUSB #define debugSerial SerialUSB
@ -15,7 +16,7 @@ void signal_loop_start()
#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 WATER_SENSOR_PIN 6 #define WATER_SENSOR_PIN 6
int cnt; int cnt;
@ -25,6 +26,8 @@ void setup() {
// Wait 10 seconds for the Serial Monitor // Wait 10 seconds for the Serial Monitor
} }
loraSetup();
/* Enable the pins 2/3, 6/7 and 8/9 */ /* Enable the pins 2/3, 6/7 and 8/9 */
pinMode(11, OUTPUT); pinMode(11, OUTPUT);
digitalWrite(11, HIGH); digitalWrite(11, HIGH);
@ -32,7 +35,7 @@ void setup() {
setupLED(); setupLED();
// setupWater(WATER_SENSOR_PIN); // setupWater(WATER_SENSOR_PIN);
// setupBuzzer(BUZZER_PIN); setupBuzzer(BUZZER_PIN);
// gpsSetup(); // gpsSetup();
@ -40,8 +43,8 @@ void setup() {
// setupCompass(); // setupCompass();
// setupSunLight(); // setupSunLight();
loraSetup();
buzz(BUZZER_PIN, 100);
cnt = 0; cnt = 0;
} }
@ -53,9 +56,10 @@ float tmp;
#define LOUDNESS_AVG 60 #define LOUDNESS_AVG 60
int loudnesses[LOUDNESS_AVG]; int loudnesses[LOUDNESS_AVG];
void loop() { void loop() {
// signal_loop_start(); signal_loop_start();
debugSerial.println("Deveui=" + String(LORADEV) + " => " + String(LORA_ADDR));
/* if(hasWater(WATER_SENSOR_PIN)) { */ /* if(hasWater(WATER_SENSOR_PIN)) { */
/* debugSerial.println("Having water"); */ /* debugSerial.println("Having water"); */
@ -66,15 +70,11 @@ void loop() {
/* debugSerial.println("it's dry"); */ /* debugSerial.println("it's dry"); */
/* } */ /* } */
// loraSend(getSunLight()); // loraSend(getSunLight());
// loraSend(getTempHumidHDC1000()); // loraSend(getTempHumidHDC1000());
// loraSend(getCompass()); // loraSend(getCompass());
sendIntAsString("battery=", getBattery());
// sendIntAsString("battery=", getBatteryVoltage());
getB();
/* Tracker code */ /* Tracker code */
/* if((tmps = gpsGetPostion(120)) != "") { */ /* if((tmps = gpsGetPostion(120)) != "") { */
@ -93,13 +93,11 @@ void loop() {
} }
tmp = tmp / (float) (cnt+1); tmp = tmp / (float) (cnt+1);
// sendIntAsString("battery=", getBatteryVoltage());
sendFloatAsString("loudness=", tmp); sendFloatAsString("loudness=", tmp);
sendFloatAsString("temperature=", getTemperature(TEMP_PIN)); sendFloatAsString("temperature=", getTemperature(TEMP_PIN));
cnt = 0; cnt = 0;
} }
delay(SLEEPTIME); delay(SLEEPTIME);
} }