Commit 796dcba9 authored by Yongjia Niu's avatar Yongjia Niu
Browse files

Add a blinky on/off IoTConnect command handler to enable/disable the on-board led blinky

parent f48296cd
......@@ -37,6 +37,28 @@ LSM6DSLSensor* acc_gyro = NULL;
HumTempAttr* hum_temp_attr = NULL;
GyroAttr *gyro_attr = NULL;
volatile int blinky_onoff = 0;
void cmd_blinky_onoff(int argc, char* argv[]) {
if (argc < 2) {
return;
}
const char* cmd = argv[0];
const char* onoff = argv[1];
if (cmd && onoff) {
tr_info("New command[%s %s] received and handled.", cmd, onoff);
if (strcmp(onoff, "on") == 0) {
blinky_onoff = 1;
} else {
blinky_onoff = 0;
}
}
}
NetworkInterface* connect_network() {
NetworkInterface* net = NULL;
......@@ -110,6 +132,9 @@ int main() {
cJSON_AddItemToObject(attr, "temperature", hum_temp_attr->get_temp());
cJSON_AddItemReferenceToObject(attr, "gyro", gyro_attr->get_gyro());
blinky_onoff = 1;
stm32_dev->register_cmd("blinky", cmd_blinky_onoff);
hum_temp_attr->sensor_init();
hum_temp_attr->start_sensor_update(SENSOR_UPDATE_RATE_MS);
......@@ -158,7 +183,10 @@ int main() {
client->pub();
for(int i = 0; i < PUB_PERIOD_MS; i += BLINKING_RATE_MS) {
led = !led;
if (blinky_onoff) {
led = !led;
}
ThisThread::sleep_for(BLINKING_RATE_MS);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment