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
/venv/
/sodaq_one/internal.h
/swisscom-pricing.png

View file

@ -29,6 +29,8 @@ log.setLevel(logging.DEBUG)
known_devices = [ "0018B20000000C58", "0018B20000000C37", "0018B20000000C59", "0018B20000000CD0", "0018B200000001C5" ]
def convert_gps_from_stdin():
for line in sys.stdin:
res = get_gps("", line)
@ -37,7 +39,8 @@ def convert_gps_from_stdin():
def get_gps(deveui, payload):
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
try:
@ -84,7 +87,7 @@ def decode_adeunis(provider, pkg):
# ttn -> base64 encoded
if provider == "ttn":
binascii.b2a_hex(binascii.a2b_base64(payload))
payload = binascii.b2a_hex(binascii.a2b_base64(payload))
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);
}
void blink(int length) {
void led_on() {
#if LORADEV == 1
BLUE();
#elif LORADEV == 2
WHITE();
#elif LORADEV == 0xA2
WHITE();
#elif LORADEV == 3
YELLOW();
#elif LORADEV == 4
@ -48,6 +50,14 @@ void blink(int length) {
#else
GREEN();
#endif
}
void led_off() {
CLEAR();
}
void blink(int length) {
led_on();
delay(length);
CLEAR();
}

View file

@ -49,7 +49,7 @@ void loraSetup()
void loraSend(String packet){
debugSerial.println("Trying to send: " + packet);
BLUE();
led_on();
/* with ack */
//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(2000);
CLEAR();
led_off();
}
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 */
// uint16_t getBatteryVoltage();
int getB();
int getBattery();
void blink(int length);
void led_on();
void led_off();
void setupBuzzer(int pin);
void buzzerOn();
void buzzerOff();
void buzz(int ms);
void buzz(int pin, int ms);
/* compass.ino */
extern char compassReport[80];

View file

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