aboutsummaryrefslogtreecommitdiff
path: root/app.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'app.cpp')
-rw-r--r--app.cpp46
1 files changed, 39 insertions, 7 deletions
diff --git a/app.cpp b/app.cpp
index b72b07d..19d7285 100644
--- a/app.cpp
+++ b/app.cpp
@@ -9,24 +9,37 @@
#define SENSOR_COUNT 1
-// See http://redbearlab.com/blendmicro/
+// See http://redbearlab.com/blendmicro/ for pins.
struct sm_sensor {
uint8_t pin;
uint8_t value;
uint16_t warning_value;
+ uint16_t update_interval;
uint8_t name_length;
uint8_t name[SENSOR_NAME_LEN];
} sensors[SENSOR_COUNT] = {
- {9, 0, 10, 9, 'sensor #1'},
+ // Pin, Value, Warning Value, Update Interval, Length of Name, Name
+ { 9, 0, 10, 0, 9, 'sensor #1'},
};
-void on_loop() {
+static unsigned long next_update[SENSOR_COUNT];
+
+void sm_on_connect() {
+ // Disable all updates until enabled.
+ for (int i = 0; i < SENSOR_COUNT; i++) {
+ next_update[i] = 0;
+ }
+}
+
+void sm_on_loop() {
static unsigned long last = 0, now;
static uint8_t x = 10;
now = millis();
- if (now - last > 3000) {
+
+ // TODO: implement proper notification
+ if (false || now - last > 3000) {
last = now;
struct sm_res res;
@@ -43,6 +56,7 @@ void on_loop() {
// } else {
// notify_battery_level(x);
// }
+
notify_soil_moisture(res, sizeof(sm_get_value_res));
}
}
@@ -97,6 +111,12 @@ void write_req(struct sm_req const& req) {
Serial.print("SM_CMD_GET_SENSOR_NAME");
break;
+ case SM_CMD_SET_UPDATE_INTERVAL:
+ Serial.print("SM_CMD_SET_UPDATE_INTERVAL");
+ Serial.print(": interval_in_seconds=");
+ Serial.print(req.set_update_interval.interval_in_seconds, DEC);
+ break;
+
default:
Serial.print("Unknown command!");
}
@@ -141,6 +161,10 @@ void write_res(struct sm_res const& res) {
write_name(res.get_sensor_name.name, res.get_sensor_name.length);
break;
+ case SM_CMD_SET_UPDATE_INTERVAL:
+ Serial.print("SM_CMD_SET_UPDATE_INTERVAL");
+ break;
+
default:
Serial.print("Unknown command!");
}
@@ -215,7 +239,6 @@ void on_soil_moisture_ctrl(uint8_t *data, uint8_t len) {
case SM_CMD_GET_SENSOR_NAME:
body_len = sizeof(sm_get_sensor_name_res);
sensor = req->get_sensor_name.sensor;
- Serial.print("sensor="); Serial.print(sensor, DEC);
if (sensor < SENSOR_COUNT) {
res.get_sensor_name.length = sensors[sensor].name_length;
@@ -225,13 +248,22 @@ void on_soil_moisture_ctrl(uint8_t *data, uint8_t len) {
}
break;
+ case SM_CMD_SET_UPDATE_INTERVAL:
+ body_len = sizeof(sm_set_update_interval_res);
+ sensor = req->set_update_interval.sensor;
+
+ if (sensor < SENSOR_COUNT) {
+ sensors[sensor].update_interval = req->set_update_interval.interval_in_seconds;
+ } else {
+ res.code = SM_CMD_FAIL;
+ }
+ break;
+
default:
res.code = SM_CMD_FAIL;
break;
}
- Serial.println();
-
if (res.code == SM_CMD_FAIL) {
body_len = 0;
}