esp_mqtt/user/demo_script

50 wiersze
1.1 KiB
Plaintext

% Config params, overwrite any previous settings from the commandline
config ap_ssid MyAP
config ap_password stupidPassword
config ntp_server 1.pool.ntp.org
config mqtt_host 192.168.1.20
% Now the initialization, this is done once after booting
on init
do
println "MQTT Script 1.0 starting"
subscribe local /test/#
settimer 1 1000 % once per second
setvar $1 0
setvar $2 0
% Now the events, checked whenever something happens
% Here a remote republish, of any local topic starting with "/test/"
on topic local /test/#
do
publish remote $this_topic $this_data
% When timer 1 expires, do some stuff
on timer 1
do
% publish a timestamp locally
publish local /t/time $timestamp
% Let the LED on GPIO 2 blink
gpio_out 2 $1
setvar $1 not $1
% Count occurences in var $2
setvar $2 $2 add 1
% And if we have reached 10, print that to the console
if $2 gte 10 then
print "We have reached "
println $2
setvar $2 0
endif
% Reload the timer
settimer 1 1000
% Here a local publication once each day at noon
on clock 12:00:00
do
publish local /t/2 "High Noon"