Created
July 2, 2018 18:11
-
-
Save rac2030/cad175b2b7370aac7197be80f413b6d1 to your computer and use it in GitHub Desktop.
PakMan project done during the last few hours of the MakeZurich hackathon using a Teensy 3.6, a HC05 BT module and interfacing a FMLR LoRa button from MiroMico emulating button presses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include <ArduinoJson.h> | |
#include <EEPROM.h> | |
#include <Snooze.h> | |
#include <Wire.h> | |
#include <sensirion_ess.h> | |
#define INTERVAL 1000 | |
#define PIN_BT_EN 2 | |
#define PIN_ISR 7 | |
#define PIN_LORA 8 | |
SensirionESS ess; | |
SnoozeDigital digital; | |
SnoozeTimer timer; | |
SnoozeBlock config(digital, timer); | |
void setup() { | |
Serial.begin(115200); | |
Serial.setTimeout(1000); | |
Serial1.begin(9600); | |
Serial2.begin(9600); | |
Serial2.setTimeout(1000); | |
pinMode(PIN_BT_EN, OUTPUT); | |
digitalWrite(PIN_BT_EN, HIGH); | |
pinMode(PIN_LORA, OUTPUT); | |
timer.setTimer(INTERVAL); | |
digital.pinMode(PIN_ISR, INPUT_PULLUP, FALLING); | |
// digital.pinMode(BT_ISR_PIN, INPUT_PULLUP, FALLING); | |
delay(1000); | |
Serial.print("Welcome to pakman\r\n"); | |
ess.initSensors(); | |
Serial.print(ess.getError()); | |
Serial.println(); | |
} | |
void loop() { | |
measure(); | |
bt_loop(); | |
Serial2.flush(); | |
} | |
void measure() { | |
float temp, humidity, tvoc; | |
ess.measureIAQ(); | |
ess.measureRHT(); | |
temp = ess.getTemperature(); | |
humidity = ess.getHumidity(); | |
tvoc = ess.getTVOC(); | |
Serial.print(temp); | |
Serial.print(" "); | |
Serial.print(humidity); | |
Serial.print(" "); | |
Serial.println(tvoc); | |
Serial2.println(tvoc); | |
if (humidity > 65.0f) { | |
lora(5000); | |
} else if (humidity > 45.0f) { | |
lora(200); | |
} | |
} | |
void lora(uint32_t d) { | |
digitalWrite(PIN_LORA, LOW); | |
delay(d); | |
digitalWrite(PIN_LORA, HIGH); | |
delay(10000); | |
} | |
void bt_loop() { | |
uint32_t start_time = millis(); | |
for (;;) { | |
StaticJsonBuffer<512> jsonBuffer; | |
char buffer[128]; | |
int len = Serial2.readBytesUntil('\n', buffer, sizeof(buffer)); | |
if (len == 0) { | |
Serial2.readBytesUntil('\n', buffer, sizeof(buffer)); | |
} | |
JsonObject &object = jsonBuffer.parseObject(buffer); | |
if (!object.success()) { | |
// Serial2.printf("waiting for json\r\n"); | |
return; | |
} | |
const char *cmd = object["command"]; | |
Serial2.println(cmd); | |
if (strcmp(cmd, "lora") == 0) { | |
lora(200); | |
} | |
if (millis() - start_time > INTERVAL) { | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment