diff --git a/docs/README.md b/docs/README.md
index 588979a2e..9a9615334 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -16,12 +16,12 @@ Do not add anything here, as it will overwritten with next rebuild.
| [IO/Pin Roles](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/ioRoles.md) (70 total) | You can set pin roles in 'Configure Module' section or use one of predefined templates in Web App. For each pin, you also set coresponding channel value. This is needed for modules with multiple relays. If you have 3 relays and 3 buttons, you need to use channel values like 1, 2, and 3. Just enter '1' in the text field, etc. |
| [Flags](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/flags.md) (40 total) | Flags are global and allows you to alter behaviour of the device. |
| [Drivers](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/drivers.md) (35 total) | Drivers allows you to control certain peripherals or enable certain features that are off by default. |
-| [Script constants](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/constants.md) (22 total) | Every console command that takes an integer argument supports certain constant expansion. |
+| [Script constants](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/constants.md) (24 total) | Every console command that takes an integer argument supports certain constant expansion. |
| [Channel Types](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/channelTypes.md) (35 total) | Channel types are often not required and don't have to be configured, but in some cases they are required for better device control from OpenBeken web panel. Channel types describes the kind of value stored in channel, for example, if you have a Tuya Fan Controller with 3 speeds control, you can set the channel type to LowMidHigh and it will display the correct UI radiobutton on OpenBeken panel.
Some channels have '_div10' or '_div100' sufixes. This is for TuyaMCU. This is needed because TuyaMCU sends values as integers, so it sends, for example, 215 for 21.5C temperature, and we store it internally as 215 and only convert to float for display. |
| [FAQ](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/faq.md) (26 total) | Here is a detailed list of questions you may ask. Some information from docs is repeated here. |
-| [Console/Script commands](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands.md) (247 total) | There are multiple console commands that allow you to automate your devices. Commands can be entered manually in command line, can be send by HTTP (just like in Tasmota), can be send by MQTT and also can be scripted. |
+| [Console/Script commands](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands.md) (249 total) | There are multiple console commands that allow you to automate your devices. Commands can be entered manually in command line, can be send by HTTP (just like in Tasmota), can be send by MQTT and also can be scripted. |
| [Command Examples](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commandExamples.md) (10 total) | Here you can find some examples of console commands usage |
-| [Autoexec.bat examples (configs)](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/autoexecExamples.md) (10 total) | Here you can find examples of autoexec.bat configs. The autoexec.bat file can be created in Web Application, under LittleFS tab, and is run every time device reboots (unless device enters safe mode/AP mode). The autoexec.bat file allows you to create more advanced configs, setup TuyaMCU mappings, etc |
+| [Autoexec.bat examples (configs)](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/autoexecExamples.md) (12 total) | Here you can find examples of autoexec.bat configs. The autoexec.bat file can be created in Web Application, under LittleFS tab, and is run every time device reboots (unless device enters safe mode/AP mode). The autoexec.bat file allows you to create more advanced configs, setup TuyaMCU mappings, etc |
| [MQTT Topics](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/mqttTopics.md) (25 total) | MQTT topic names and content for incoming and ougoing OBK MQTT publishes |
| [Script examples](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/scriptExamples.md) (5 total) | Scripts can be put in autoexec.bat and then they will start automatically on reboot, you can also put script in other LittleFS file and use startScript [fileName] [Label] command to run them. From the firmware point of view, scripts and autoexecs are basically the same thing. There is, however, a little bit more advanced system of execution for scripts which can be written in a form of scripts threads that run over time, can have delays within then, conditional checks and jumps. |
-| [Console/Script commands [Extended Edition]](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands-extended.md) (247 total) | More details on commands. |
+| [Console/Script commands [Extended Edition]](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands-extended.md) (249 total) | More details on commands. |
diff --git a/docs/autoexecExamples.md b/docs/autoexecExamples.md
index 2f3bbbc2e..19170d266 100644
--- a/docs/autoexecExamples.md
+++ b/docs/autoexecExamples.md
@@ -273,3 +273,51 @@ addChangeHandler noPingTime > 600 reboot
```
+NTP and 'waitFor' command example. You can use 'waitFor NTPState 1' in autoexec.bat to wait for NTP sync. After that, you can be sure that correct time is set. 'waitFor' will block execution until given event.
+
+```// do anything on startup
+startDriver NTP
+startDriver SSDP
+
+
+// now you can wait for NTP to sync
+// This will block execution until NTP get correct time
+// NOTE: you can also do 'waitFor MQTTState 1' as well, if you want MQTT state 1
+waitFor NTPState 1
+
+// default setting
+Dimmer 5
+Power ON
+
+// now you can do something basing on time
+// idk, it's just a simple example, note that
+// next Dimmer setting will overwite previos setting
+if $hour<8 then Dimmer 50
+if $hour>=20 then Dimmer 50
+if $hour>=23 then Dimmer 90
+
+```
+
+
+MQTT and 'waitFor' command example. You can use 'waitFor MQTTState 1' in autoexec.bat to wait for MQTT connection. After that, you can be sure that MATT is online. 'waitFor' will block execution until given event.
+
+```// do anything on startup
+startDriver NTP
+startDriver SSDP
+
+// now wait for MQTT
+waitFor MQTTState 1
+// extra delay, to be sure
+delay_s 1
+publish myVariable 2022
+// you can publish again just to be sure
+// delay_s 1
+// publish myVariable 2022
+
+// if you have a battery powered device, you can now uncomment this line:
+// Deep sleep (shut down everything) and reboot automatically after 600 seconds
+//DeepSleep 600
+
+```
+
+
diff --git a/docs/autoexecs/waiting_for_MQTT_connect.bat b/docs/autoexecs/waiting_for_MQTT_connect.bat
new file mode 100644
index 000000000..1ebb99f32
--- /dev/null
+++ b/docs/autoexecs/waiting_for_MQTT_connect.bat
@@ -0,0 +1,16 @@
+// do anything on startup
+startDriver NTP
+startDriver SSDP
+
+// now wait for MQTT
+waitFor MQTTState 1
+// extra delay, to be sure
+delay_s 1
+publish myVariable 2022
+// you can publish again just to be sure
+// delay_s 1
+// publish myVariable 2022
+
+// if you have a battery powered device, you can now uncomment this line:
+// Deep sleep (shut down everything) and reboot automatically after 600 seconds
+//DeepSleep 600
diff --git a/docs/autoexecs/waiting_for_NTP_sync.bat b/docs/autoexecs/waiting_for_NTP_sync.bat
new file mode 100644
index 000000000..12488b790
--- /dev/null
+++ b/docs/autoexecs/waiting_for_NTP_sync.bat
@@ -0,0 +1,20 @@
+// do anything on startup
+startDriver NTP
+startDriver SSDP
+
+
+// now you can wait for NTP to sync
+// This will block execution until NTP get correct time
+// NOTE: you can also do 'waitFor MQTTState 1' as well, if you want MQTT state 1
+waitFor NTPState 1
+
+// default setting
+Dimmer 5
+Power ON
+
+// now you can do something basing on time
+// idk, it's just a simple example, note that
+// next Dimmer setting will overwite previos setting
+if $hour<8 then Dimmer 50
+if $hour>=20 then Dimmer 50
+if $hour>=23 then Dimmer 90
diff --git a/docs/commands-extended.md b/docs/commands-extended.md
index 8e9ae0e05..fd54e6f5f 100644
--- a/docs/commands-extended.md
+++ b/docs/commands-extended.md
@@ -6,6 +6,7 @@ Do not add anything here, as it will overwritten with next rebuild.
| Command | Arguments | Description | Location |
|:------------- |:-------------:|:----- | ------:|
| SetChannel | [ChannelIndex][ChannelValue] | Sets a raw channel to given value. Relay channels are using 1 and 0 values. PWM channels are within [0,100] range. Do not use this for LED control, because there is a better and more advanced LED driver with dimming and configuration memory (remembers setting after on/off), LED driver commands has 'led_' prefix. | File: cmnds/cmd_channels.c
Function: CMD_SetChannel |
+| SetChannelFloat | [ChannelIndex][ChannelValue] | Sets a raw channel to given float value. Currently only used for LED PWM channels. | File: cmnds/cmd_channels.c
Function: CMD_SetChannelFloat |
| ToggleChannel | [ChannelIndex] | Toggles given channel value. Non-zero becomes zero, zero becomes 1. | File: cmnds/cmd_channels.c
Function: CMD_ToggleChannel |
| AddChannel | [ChannelIndex][ValueToAdd][ClampMin][ClampMax][bWrapInsteadOfClamp] | Adds a given value to the channel. Can be used to change PWM brightness. Clamp min and max arguments are optional. | File: cmnds/cmd_channels.c
Function: CMD_AddChannel |
| ClampChannel | [ChannelIndex][Min][Max] | Clamps given channel value to a range. | File: cmnds/cmd_channels.c
Function: CMD_ClampChannel |
@@ -85,6 +86,7 @@ Do not add anything here, as it will overwritten with next rebuild.
| delay_ms | [ValueMS] | Script-only command. Pauses current script thread for given amount of ms. | File: cmnds/cmd_script.c
Function: CMD_Delay_ms |
| return | | Script-only command. Currently it just stops totally current script thread. | File: cmnds/cmd_script.c
Function: CMD_Return |
| resetSVM | | Resets all SVM and clears all scripts. | File: cmnds/cmd_script.c
Function: CMD_resetSVM |
+| waitFor | [EventName] [Argument] | Wait forever for event. Can be used within script. For example, you can do: waitFor MQTTState 1 or waitFor NTPState 1. You can also do waitFor NoPingTime 600 to wait for 600 seconds without ping watchdog getting successful reply | File: cmnds/cmd_script.c
Function: CMD_waitFor |
| sendGet | [TargetURL] | Sends a HTTP GET request to target URL. May include GET arguments. Can be used to control devices by Tasmota HTTP protocol. Command supports argument expansion, so $CH11 changes to value of channel 11, etc, etc. | File: cmnds/cmd_send.c
Function: CMD_SendGET |
| power | [OnorOfforToggle] | Tasmota-style POWER command. Should work for both LEDs and relay-based devices. You can write POWER0, POWER1, etc to access specific relays. | File: cmnds/cmd_tasmota.c
Function: power |
| powerAll | | set all outputs | File: cmnds/cmd_tasmota.c
Function: powerAll |
diff --git a/docs/commands.md b/docs/commands.md
index 455418872..f18af7d11 100644
--- a/docs/commands.md
+++ b/docs/commands.md
@@ -9,6 +9,7 @@ Do not add anything here, as it will overwritten with next rebuild.
| Command | Arguments | Description |
|:------------- |:------------- | -----:|
| SetChannel | [ChannelIndex][ChannelValue] | Sets a raw channel to given value. Relay channels are using 1 and 0 values. PWM channels are within [0,100] range. Do not use this for LED control, because there is a better and more advanced LED driver with dimming and configuration memory (remembers setting after on/off), LED driver commands has 'led_' prefix. |
+| SetChannelFloat | [ChannelIndex][ChannelValue] | Sets a raw channel to given float value. Currently only used for LED PWM channels. |
| ToggleChannel | [ChannelIndex] | Toggles given channel value. Non-zero becomes zero, zero becomes 1. |
| AddChannel | [ChannelIndex][ValueToAdd][ClampMin][ClampMax][bWrapInsteadOfClamp] | Adds a given value to the channel. Can be used to change PWM brightness. Clamp min and max arguments are optional. |
| ClampChannel | [ChannelIndex][Min][Max] | Clamps given channel value to a range. |
@@ -88,6 +89,7 @@ Do not add anything here, as it will overwritten with next rebuild.
| delay_ms | [ValueMS] | Script-only command. Pauses current script thread for given amount of ms. |
| return | | Script-only command. Currently it just stops totally current script thread. |
| resetSVM | | Resets all SVM and clears all scripts. |
+| waitFor | [EventName] [Argument] | Wait forever for event. Can be used within script. For example, you can do: waitFor MQTTState 1 or waitFor NTPState 1. You can also do waitFor NoPingTime 600 to wait for 600 seconds without ping watchdog getting successful reply |
| sendGet | [TargetURL] | Sends a HTTP GET request to target URL. May include GET arguments. Can be used to control devices by Tasmota HTTP protocol. Command supports argument expansion, so $CH11 changes to value of channel 11, etc, etc. |
| power | [OnorOfforToggle] | Tasmota-style POWER command. Should work for both LEDs and relay-based devices. You can write POWER0, POWER1, etc to access specific relays. |
| powerAll | | set all outputs |
diff --git a/docs/constants.md b/docs/constants.md
index a6faf1d5e..f7cbee1c5 100644
--- a/docs/constants.md
+++ b/docs/constants.md
@@ -8,6 +8,7 @@ Do not add anything here, as it will overwritten with next rebuild.
|:------------- | -----:|
| MQTTOn | Legacy variable, without $ prefix. Returns 1 if MQTT is connected, otherwise 0. |
| $MQTTOn | Returns 1 if MQTT is connected, otherwise 0. |
+| $NTPOn | Returns 1 if NTP is on and already synced (so device has correct time), otherwise 0. |
| $CH*** | Provides channel access, so you can do math expressions on channel values. $CH1 is channel 1, $CH20 is channel 20, $CH140 is channel 140, etc |
| $CH** | Provides channel access, as above. |
| $CH* | Provides channel access, as above. |
@@ -28,3 +29,4 @@ Do not add anything here, as it will overwritten with next rebuild.
| $minute | Current minute from NTP |
| $second | Current second from NTP |
| $uptime | Time since reboot in seconds |
+| $failedBoots | Get number of failed boots (too quick reboots). Remember that you can change the uptime required to mark boot as 'okay' in general/flags menu |
diff --git a/docs/flags.md b/docs/flags.md
index b7c887853..bb6eb90fa 100644
--- a/docs/flags.md
+++ b/docs/flags.md
@@ -40,8 +40,8 @@ Do not add anything here, as it will overwritten with next rebuild.
| 32 | [LED] Use old linear brightness mode, ignore gamma ramp |
| 33 | [MQTT] Apply channel type multiplier on (if any) on channel value before publishing it |
| 34 | [MQTT] In HA discovery, add relays as lights |
-| 35 | [HASS] Deactivate avty_t flag for sensor when publishing to HASS (permit to keep value) |
+| 35 | [HASS] Deactivate avty_t flag for sensor when publishing to HASS (permit to keep value). You must restart HASS discovery for change to take effect. |
| 36 | [DRV] Deactivate Autostart of all drivers |
| 37 | [WiFi] Quick connect to WiFi on reboot (TODO: check if it works for you and report on github) |
| 38 | [Power] Set power and current to zero if all relays are open |
-| 39 | undefined |
+| 39 | [MQTT] [Debug] Publish all channels (don't enable it, it will be publish all 64 possible channels on connect) |
diff --git a/docs/json/autoexecExamples.json b/docs/json/autoexecExamples.json
index 63f6f5d33..a8c177953 100644
--- a/docs/json/autoexecExamples.json
+++ b/docs/json/autoexecExamples.json
@@ -38,5 +38,13 @@
{
"title": "Basic Ping Watchdog usage. Ping given IP with given interval and run script if there was no ping reply within given time.",
"file": "autoexecs/ping_watchdog.bat"
+},
+{
+"title": "NTP and 'waitFor' command example. You can use 'waitFor NTPState 1' in autoexec.bat to wait for NTP sync. After that, you can be sure that correct time is set. 'waitFor' will block execution until given event.",
+"file": "autoexecs/waiting_for_NTP_sync.bat"
+},
+{
+"title": "MQTT and 'waitFor' command example. You can use 'waitFor MQTTState 1' in autoexec.bat to wait for MQTT connection. After that, you can be sure that MATT is online. 'waitFor' will block execution until given event.",
+"file": "autoexecs/waiting_for_MQTT_connect.bat"
}
]
diff --git a/docs/json/commands.json b/docs/json/commands.json
index f2935f5e9..4efee8560 100644
--- a/docs/json/commands.json
+++ b/docs/json/commands.json
@@ -8,6 +8,15 @@
"requires": "",
"examples": ""
},
+ {
+ "name": "SetChannelFloat",
+ "args": "[ChannelIndex][ChannelValue]",
+ "descr": "Sets a raw channel to given float value. Currently only used for LED PWM channels.",
+ "fn": "CMD_SetChannelFloat",
+ "file": "cmnds/cmd_channels.c",
+ "requires": "",
+ "examples": ""
+ },
{
"name": "ToggleChannel",
"args": "[ChannelIndex]",
@@ -719,6 +728,15 @@
"requires": "",
"examples": ""
},
+ {
+ "name": "waitFor",
+ "args": "[EventName] [Argument]",
+ "descr": "Wait forever for event. Can be used within script. For example, you can do: waitFor MQTTState 1 or waitFor NTPState 1. You can also do waitFor NoPingTime 600 to wait for 600 seconds without ping watchdog getting successful reply",
+ "fn": "CMD_waitFor",
+ "file": "cmnds/cmd_script.c",
+ "requires": "",
+ "examples": ""
+ },
{
"name": "sendGet",
"args": "[TargetURL]",
diff --git a/docs/json/constants.json b/docs/json/constants.json
index 6c1c7b498..3793c5758 100644
--- a/docs/json/constants.json
+++ b/docs/json/constants.json
@@ -11,6 +11,12 @@
"descr": "Returns 1 if MQTT is connected, otherwise 0.",
"requires": ""
},
+ {
+ "name": "$NTPOn",
+ "title": "$NTPOn",
+ "descr": "Returns 1 if NTP is on and already synced (so device has correct time), otherwise 0.",
+ "requires": ""
+ },
{
"name": "$CH***",
"title": "$CH***",
@@ -130,5 +136,11 @@
"title": "$uptime",
"descr": "Time since reboot in seconds",
"requires": ""
+ },
+ {
+ "name": "$failedBoots",
+ "title": "$failedBoots",
+ "descr": "Get number of failed boots (too quick reboots). Remember that you can change the uptime required to mark boot as 'okay' in general/flags menu",
+ "requires": ""
}
]
\ No newline at end of file
diff --git a/docs/json/flags.json b/docs/json/flags.json
index 5ed3ffbde..31e5ee1a0 100644
--- a/docs/json/flags.json
+++ b/docs/json/flags.json
@@ -249,7 +249,7 @@
"enum": "OBK_FLAG_NOT_PUBLISH_AVAILABILITY_SENSOR",
"title": "todo",
"file": "new_pins.h",
- "descr": "[HASS] Deactivate avty_t flag for sensor when publishing to HASS (permit to keep value)"
+ "descr": "[HASS] Deactivate avty_t flag for sensor when publishing to HASS (permit to keep value). You must restart HASS discovery for change to take effect."
},
{
"index": "36",
@@ -274,8 +274,9 @@
},
{
"index": "39",
- "enum": "OBK_FLAG_UNUSED_TODO",
+ "enum": "OBK_FLAG_MQTT_PUBLISH_ALL_CHANNELS",
"title": "todo",
- "file": "new_pins.h"
+ "file": "new_pins.h",
+ "descr": "[MQTT] [Debug] Publish all channels (don't enable it, it will be publish all 64 possible channels on connect)"
}
]
\ No newline at end of file
diff --git a/src/cmnds/cmd_if.c b/src/cmnds/cmd_if.c
index 14eeb15fa..c48ca6164 100644
--- a/src/cmnds/cmd_if.c
+++ b/src/cmnds/cmd_if.c
@@ -155,10 +155,6 @@ typedef struct {
float getMQTTOn(const char *s) {
return Main_HasMQTTConnected();
}
-float getNTPOn(const char *s) {
- return NTP_IsTimeSynced();
-}
-
float getChannelValue(const char *s) {
int idx = atoi(s + 3);
@@ -215,6 +211,10 @@ float getPower(const char *s) {
return DRV_GetReading(OBK_POWER);
}
+float getNTPOn(const char *s) {
+ return NTP_IsTimeSynced();
+}
+
#endif
float getFailedBoots(const char *s) {
@@ -247,11 +247,6 @@ const constant_t g_constants[] = {
//cnstdetail:"descr":"Returns 1 if MQTT is connected, otherwise 0.",
//cnstdetail:"requires":""}
{"$MQTTOn", &getMQTTOn},
- //cnstdetail:{"name":"$NTPOn",
- //cnstdetail:"title":"$NTPOn",
- //cnstdetail:"descr":"Returns 1 if NTP is on and already synced (so device has correct time), otherwise 0.",
- //cnstdetail:"requires":""}
- {"$NTPOn", &getNTPOn},
//cnstdetail:{"name":"$CH***",
//cnstdetail:"title":"$CH***",
//cnstdetail:"descr":"Provides channel access, so you can do math expressions on channel values. $CH1 is channel 1, $CH20 is channel 20, $CH140 is channel 140, etc",
@@ -348,6 +343,11 @@ const constant_t g_constants[] = {
//cnstdetail:"descr":"Current second from NTP",
//cnstdetail:"requires":""}
{ "$second", &getSecond },
+ //cnstdetail:{"name":"$NTPOn",
+ //cnstdetail:"title":"$NTPOn",
+ //cnstdetail:"descr":"Returns 1 if NTP is on and already synced (so device has correct time), otherwise 0.",
+ //cnstdetail:"requires":""}
+ { "$NTPOn", &getNTPOn },
#endif
//cnstdetail:{"name":"$uptime",
//cnstdetail:"title":"$uptime",