-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInit.json
More file actions
32 lines (29 loc) · 1.01 KB
/
Init.json
File metadata and controls
32 lines (29 loc) · 1.01 KB
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
load('api_gpio.js');
load('api_mqtt.js');
load('api_sys.js');
load('api_timer.js');
let led = 13;
GPIO.set_mode(led, GPIO.MODE_OUTPUT);
// Subscription to MQTT
MQTT.sub('my/topic/#', function(conn, topic, message) {
print('MQTT Income Message: ', 'topic:', topic, 'message:', message);
let value = GPIO.toggle(led);
topic = 'Actuation response:';
message = JSON.stringify({
Led: value,
Input: message
});
let ok = MQTT.pub(topic, message, message.length);
print('Published:', ok ? 'yes' : 'no', 'topic:', topic, message);
}, null);
// Publish to MQTT topic on a button press. Button is wired to GPIO pin 0
GPIO.set_button_handler(0, GPIO.PULL_UP, GPIO.INT_EDGE_NEG, 200, function() {
let topic = 'mOS/topic1';
let message = JSON.stringify({
total_ram: Sys.total_ram(),
free_ram: Sys.free_ram(),
uptime: Sys.uptime()
});
let ok = MQTT.pub(topic, message, message.length);
print('Published:', ok ? 'yes' : 'no', 'topic:', topic, 'message:', message);
}, null);