Blink statusled on recv/xmit MQTT messages; debounce 200ms; trigger button on release; Prime for sonoff-basic // sonoff-sv
This commit is contained in:
8
mos.yml
8
mos.yml
@ -1,6 +1,6 @@
|
|||||||
author: Pim van Pelt <pim@ipng.nl>
|
author: Pim van Pelt <pim@ipng.nl>
|
||||||
description: A Mongoose-OS Light Switch
|
description: A Mongoose-OS Light Switch
|
||||||
version: 1.0
|
version: 1.1
|
||||||
platform: esp8266
|
platform: esp8266
|
||||||
|
|
||||||
libs_version: ${mos.version}
|
libs_version: ${mos.version}
|
||||||
@ -31,7 +31,7 @@ config_schema:
|
|||||||
- ["wifi.sta.pass", "marielle"]
|
- ["wifi.sta.pass", "marielle"]
|
||||||
- ["debug.stderr_uart", -1]
|
- ["debug.stderr_uart", -1]
|
||||||
- ["debug.stdout_uart", -1]
|
- ["debug.stdout_uart", -1]
|
||||||
- ["debug.udp_log_addr", "192.168.2.176:1234"]
|
- ["debug.udp_log_addr", "192.168.1.1:1025"]
|
||||||
- ["mqtt.enable", true]
|
- ["mqtt.enable", true]
|
||||||
- ["http.enable", true]
|
- ["http.enable", true]
|
||||||
- ["mqtt.server", "mqtt.ipng.nl:8883"]
|
- ["mqtt.server", "mqtt.ipng.nl:8883"]
|
||||||
@ -39,9 +39,9 @@ config_schema:
|
|||||||
- ["rpc.mqtt.enable", true]
|
- ["rpc.mqtt.enable", true]
|
||||||
- ["app", "o", {title: "APP settings"}]
|
- ["app", "o", {title: "APP settings"}]
|
||||||
- ["app.hostname", "s", {title: "Device hostname"}]
|
- ["app.hostname", "s", {title: "Device hostname"}]
|
||||||
- ["app.hostname", "lightswitch0"]
|
- ["app.hostname", "sonoff-sv"]
|
||||||
- ["app.config", "s", {title: "Application specific config file"}]
|
- ["app.config", "s", {title: "Application specific config file"}]
|
||||||
- ["app.config", "3gang.json"]
|
- ["app.config", "sonoff-basic.json"]
|
||||||
|
|
||||||
|
|
||||||
build_vars:
|
build_vars:
|
||||||
|
@ -109,7 +109,7 @@ exit:
|
|||||||
|
|
||||||
if (s_channels[idx].button_gpio!=GPIO_INVALID) {
|
if (s_channels[idx].button_gpio!=GPIO_INVALID) {
|
||||||
mgos_gpio_set_mode(s_channels[idx].button_gpio, MGOS_GPIO_MODE_INPUT);
|
mgos_gpio_set_mode(s_channels[idx].button_gpio, MGOS_GPIO_MODE_INPUT);
|
||||||
mgos_gpio_set_button_handler(s_channels[idx].button_gpio, MGOS_GPIO_PULL_NONE, MGOS_GPIO_INT_EDGE_ANY, 10, channel_handler, NULL);
|
mgos_gpio_set_button_handler(s_channels[idx].button_gpio, MGOS_GPIO_PULL_UP, MGOS_GPIO_INT_EDGE_POS, 200, channel_handler, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ static void mqtt_publish_broadcast_stat(const char *stat, const char *msg) {
|
|||||||
snprintf(topic, sizeof(topic)-1, "%s/%s", MQTT_TOPIC_BROADCAST_STAT, stat);
|
snprintf(topic, sizeof(topic)-1, "%s/%s", MQTT_TOPIC_BROADCAST_STAT, stat);
|
||||||
mgos_mqtt_pub((char*)topic, (char*)msg, strlen(msg), 0, false);
|
mgos_mqtt_pub((char*)topic, (char*)msg, strlen(msg), 0, false);
|
||||||
LOG(LL_INFO, ("Sent topic='%s' msg='%s'", topic, msg));
|
LOG(LL_INFO, ("Sent topic='%s' msg='%s'", topic, msg));
|
||||||
|
statusled_blink();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mqtt_broadcast_cmd_id() {
|
static void mqtt_broadcast_cmd_id() {
|
||||||
@ -41,6 +42,7 @@ static void mqtt_broadcast_cmd_id() {
|
|||||||
|
|
||||||
static void mqtt_cb(struct mg_connection *nc, const char *topic, int topic_len, const char *msg, int msg_len, void *ud) {
|
static void mqtt_cb(struct mg_connection *nc, const char *topic, int topic_len, const char *msg, int msg_len, void *ud) {
|
||||||
LOG(LL_INFO, ("Received topic='%.*s' msg='%.*s'", topic_len, topic, msg_len, msg));
|
LOG(LL_INFO, ("Received topic='%.*s' msg='%.*s'", topic_len, topic, msg_len, msg));
|
||||||
|
statusled_blink();
|
||||||
|
|
||||||
if (topic_len >= (int) strlen(MQTT_TOPIC_BROADCAST_CMD) && 0 == strncmp(MQTT_TOPIC_BROADCAST_CMD, topic, strlen(MQTT_TOPIC_BROADCAST_CMD)))
|
if (topic_len >= (int) strlen(MQTT_TOPIC_BROADCAST_CMD) && 0 == strncmp(MQTT_TOPIC_BROADCAST_CMD, topic, strlen(MQTT_TOPIC_BROADCAST_CMD)))
|
||||||
mqtt_broadcast_cmd_id();
|
mqtt_broadcast_cmd_id();
|
||||||
@ -66,7 +68,6 @@ void mqtt_publish_stat(const char *stat, const char *fmt, ...) {
|
|||||||
struct json_out out = JSON_OUT_BUF(msg, 200);
|
struct json_out out = JSON_OUT_BUF(msg, 200);
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
statusled_blink();
|
|
||||||
|
|
||||||
snprintf(topic, sizeof(topic)-1, "%s%s/stat/%s", MQTT_TOPIC_PREFIX, mgos_sys_config_get_device_id(), stat);
|
snprintf(topic, sizeof(topic)-1, "%s%s/stat/%s", MQTT_TOPIC_PREFIX, mgos_sys_config_get_device_id(), stat);
|
||||||
|
|
||||||
@ -76,6 +77,7 @@ void mqtt_publish_stat(const char *stat, const char *fmt, ...) {
|
|||||||
|
|
||||||
mgos_mqtt_pub((char*)topic, (char*)msg, strlen(msg), 0, false);
|
mgos_mqtt_pub((char*)topic, (char*)msg, strlen(msg), 0, false);
|
||||||
LOG(LL_INFO, ("Sent topic='%s' msg='%s'", topic, msg));
|
LOG(LL_INFO, ("Sent topic='%s' msg='%s'", topic, msg));
|
||||||
|
statusled_blink();
|
||||||
}
|
}
|
||||||
|
|
||||||
void mqtt_init() {
|
void mqtt_init() {
|
||||||
|
Reference in New Issue
Block a user