While I can personally use a deep_sleep mode myself,
I’m currently breaking my head over the following process:
- Receiving a MQTT value
- Store the MQTT value in a global int <----
- Recall the int, and apply to the deep_sleep_duration
I think I’m doing something wrong storing the MQTT value in the global int.
Therefore I’m storing it in a global int and string for testing:
globals:
id: global_deepsleep_time_int
type: int
restore_value: no
initial_value: ‘60’id: global_deepsleep_time_str
type: std::string
restore_value: no
initial_value: ‘“60”’
The MQTT part, writing to both global int and str:
mqtt:
on_message:
- topic: sensor02/deepsleep/time
then:
Saving it to the Global STR
- globals.set: id: global_deepsleep_time_str value: !lambda |- return x.c_str(); - logger.log: format: "1_str: MQTT Received sleep time %s seconds" args: ['id(global_deepsleep_time_str).c_str()']
Saving it to the Global INT
- globals.set: id: global_deepsleep_time_int value: !lambda |- return int(x.c_str()); - logger.log: format: "2_int MQTT Received sleep time %d seconds" args: ['id(global_deepsleep_time_int)']
And painfully watching the unexpected int value of 1070199900 seconds:
[01:56:37][D][main:089]: 1_str: MQTT Received sleep time 22 seconds
[01:56:37][D][main:097]: 2_int MQTT Received sleep time 1070199900 seconds
[01:56:39][D][main:089]: 1_str: MQTT Received sleep time 36 seconds
[01:56:39][D][main:097]: 2_int MQTT Received sleep time 1070199900 seconds
[01:56:43][D][main:089]: 1_str: MQTT Received sleep time 57 seconds
[01:56:43][D][main:097]: 2_int MQTT Received sleep time 1070199900 seconds
Recalling initial data from the global int works fine.
It’s only when I write MQTT data to the global int, the number goes 1070199900
Question: How can I write the correct global int with the received MQTT data?