-
Notifications
You must be signed in to change notification settings - Fork 1
/
mymqtt.fs
148 lines (93 loc) · 2.82 KB
/
mymqtt.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
\ include slip-esc.fs
include mmq-const.fs
include mmq-tools.fs
\ should go to lib
\ : my.stringbuf-type ( adr -- ) stringbuf-string type ;
: mymq.prefix s" heating/pressure" ;
: mymq.valve s" valve" ;
: mymq.pump s" pump" ;
: mymq.press s" press" ;
: mymq.status s" status" ;
\ domain specific concatenators
( mqtt-message -- )
: mymq.pump.on
dup MQTT-init
dup mymq.prefix mymq.pump MQTT-topic
dup MQTT-append-on
MQTT-append-q.a.r
;
: mymq.pump.off
dup MQTT-init
dup mymq.prefix mymq.pump MQTT-topic
dup MQTT-append-off
MQTT-append-q.a.r
;
: mymq.valve.on
dup MQTT-init
dup mymq.prefix mymq.valve MQTT-topic
dup MQTT-append-on
MQTT-append-q.a.r
;
: mymq.valve.off
dup MQTT-init
dup mymq.prefix mymq.valve MQTT-topic
dup MQTT-append-off
MQTT-append-q.a.r
;
: test.prefix s" home/basement" ;
: test.wash s" wasABCDher" ;
: test.msg dup MQTT-init dup test.prefix test.wash MQTT-topic dup MQTT-append-off MQTT-append-q.a.r ;
' slip-dumper SLIP-handler-ptr !
slip-ESC-activate
\ test rund
$60 stringbuffer constant mqtt-message
$80 stringbuffer constant slip1-message
$80 stringbuffer constant slip2-message
\ mqtt-message MQTT-init
\ mqtt-message mymq.prefix mymq.valve MQTT-topic
\ mqtt-message MQTT-append-off .... -on
\ mqtt-message MQTT-append-q.a.r
\ mqtt-message stringbuf-dump
\ $80 stringbuffer constant slip-message
\ mqtt-message mymq.valve.off
mqtt-message test.msg
slip1-message mqtt-message stringbuf-string SLIP-assemble
: mqtt-send slip1-message >r stringbuf-string r@ -rot SLIP-assemble r> stringbuf-type ;
slip1-message stringbuf-type
mqtt-message mymq.valve.off
mqtt-message mqtt-send
mqtt-message mymq.valve.on
mqtt-message mqtt-send
mqtt-message mymq.pump.on
mqtt-message mqtt-send
mqtt-message mymq.pump.off
mqtt-message mqtt-send
\ =====================================================================
\ test data
: foo s" foo bar tralala " ;
mqtt-message foo MQTT-dataadd
mqtt-message 2 1 MQTT-numberadd \ quos
mqtt-message 1 1 MQTT-numberadd \ retain
\ test composed headers - craft a MQTT setup
mqtt-message stringbuf-clear
mqtt-message stringbuf-dump
mqtt-message CMD_MQTT_SETUP 4 0 MQTT-cmdadd
mqtt-message stringbuf-dump
mqtt-message caret1 4 MQTT-numberadd
mqtt-message caret2 4 MQTT-numberadd
mqtt-message caret3 4 MQTT-numberadd
mqtt-message caret4 4 MQTT-numberadd
\ dummy callback functions
: ^1 ." doing one " ;
: ^2 ." doing two " ;
: ^3 ." doing three " ;
: ^4 ." doing four " ;
\ =============================================0
\ subscribe
: subscribetopic s" foo/bar" ;
mqtt-message stringbuf-clear
mqtt-message CMD_MQTT_SUBSCRIBE 2 0 MQTT-cmdadd
mqtt-message subscribetopic MQTT-stringadd
\ qos=1
mqtt-message 1 1 MQTT-numberadd
mqtt-message mqtt-send