diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..4fc120f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "buttonhandler.h": "c" + } +} \ No newline at end of file diff --git a/README.md b/README.md index ae5bf7f..bd4cccd 100644 --- a/README.md +++ b/README.md @@ -26,4 +26,8 @@

-

\ No newline at end of file +

+ +## Functionality + +- Button on device: Push toggles the relay. LED is on for about 2 seconds to signal, push button has been recognized. diff --git a/mos.yml b/mos.yml index cc2ee86..626d307 100644 --- a/mos.yml +++ b/mos.yml @@ -45,9 +45,9 @@ config_schema: # - ["http.document_root", "/"] # - ["http.hidden_files", "s_*"] # - ["http.auth_file", "s_pass"] - # - ["wifi.ap.enable", true] - # - ["wifi.ap.ssid", "SONOFF_??????"] - # - ["wifi.ap.pass", "MySonoff"] + - ["wifi.ap.enable", true] + - ["wifi.ap.ssid", "SONOFF_??????"] + - ["wifi.ap.pass", "MySonoff"] - ["wifi.sta.enable", true] - ["wifi.sta.ssid", "Pinguin"] - ["wifi.sta.pass", "PaulchenAufmKlo34"] @@ -60,7 +60,7 @@ config_schema: build_vars: # sonoff basic has 1MBytes flash only - # FLASH_SIZE: 1048576 + FLASH_SIZE: 1048576 tags: - c diff --git a/src/main.c b/src/main.c index 599e875..86e9a71 100644 --- a/src/main.c +++ b/src/main.c @@ -11,6 +11,7 @@ static void buttonPressOne(int pressCount) { LOG(LL_DEBUG, ("buttonPressOne called with pressCount=%d", pressCount)); set_relay(RELAY_TOGGLE); + set_led_status(LED_ONCE); } static void buttonPressTwo(int pressCount) { @@ -21,6 +22,10 @@ static void buttonPressThree(int pressCount) { LOG(LL_DEBUG, ("buttonPressThree called with pressCount=%d", pressCount)); } +static void on_board_led_off_cb(void *arg) { + (void) arg; + set_led_status(LED_OFF); +} enum mgos_app_init_result mgos_app_init(void) { init_led_handler(); set_led_status(LED_BLINK_FAST); @@ -30,5 +35,6 @@ enum mgos_app_init_result mgos_app_init(void) { add_button_press_callback(3, buttonPressThree); init_mqtt_handler(); LOG(LL_INFO, ("SONOFF app initialized")); + mgos_set_timer(5000, 0, on_board_led_off_cb, NULL); return MGOS_APP_INIT_SUCCESS; } diff --git a/src/mqttHandler.c b/src/mqttHandler.c index f1ad9ae..2ac3dba 100644 --- a/src/mqttHandler.c +++ b/src/mqttHandler.c @@ -56,7 +56,7 @@ static void pubMqttStatus(char *event) { event, mgos_get_free_heap_size(), relay_is_on() ? "true" : "false"); - mgos_mqtt_pub(pubTopic, msg, strlen(msg), MG_MQTT_QOS(0)); + mgos_mqtt_pub(pubTopic, msg, strlen(msg), MG_MQTT_QOS(0), true); //mg_mqtt_publish(c, get_cfg()->mqtt.pub, 0, MG_MQTT_QOS(0), msg, n); LOG(LL_DEBUG, ("MQTT pub topic=%s -> %s", pubTopic, msg)); }