# This program depends on the https://chiselapp.com/user/schelte/repository/mqtt/home MQT library being installed at the /home/folk/mqtt directory Start process mqtt { Wish $::thisProcess receives statements like \ [list /someone/ wishes MQTT publish /...anything/] Wish $::thisProcess receives statements like \ [list $::thisNode has step count /...anything/] Wish $::thisProcess shares statements like \ [list MQTT claims message /message/ topic /topic/ timestamp /timestamp/] ::tcl::tm::path add /home/folk/mqtt package require mqtt set client [mqtt new] set ::mqttclient $client proc cb {topic content status} { set message [encoding convertfrom utf-8 $content] puts "MQTT CALLBACK: $topic: $message" set now [clock milliseconds] Assert MQTT claims message $message topic $topic timestamp $now # Retract all events that are more than 5 seconds old. set events [Statements::findMatches [list MQTT claims message /message/ topic /topic/ timestamp /timestamp/]] foreach event $events { dict with event { if {$now - $timestamp > 5000} { Retract MQTT claims message $message topic $topic timestamp $timestamp } } } } $client connect test-client localhost 1883 $client subscribe "#" cb When /someone/ wishes MQTT publish /m/ on topic /t/ at timestamp /ts/ { # puts "publishing $m on $t at $ts" $::mqttclient publish "$t" "$m" } while true { # Step for folk, update for TCL and MQTT Step update } }