Compare commits
5 Commits
67bc9b9d23
...
7fffd33e3a
Author | SHA1 | Date | |
---|---|---|---|
7fffd33e3a | |||
71410fee91 | |||
9dbf9be428 | |||
0ea78abf4c | |||
a342ff6815 |
BIN
docs/LightSwitch-Base.png
Normal file
BIN
docs/LightSwitch-Base.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 229 KiB |
BIN
docs/LightSwitch-Base.stl
Normal file
BIN
docs/LightSwitch-Base.stl
Normal file
Binary file not shown.
BIN
docs/LightSwitch-Button.png
Normal file
BIN
docs/LightSwitch-Button.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 104 KiB |
BIN
docs/LightSwitch-Button.stl
Normal file
BIN
docs/LightSwitch-Button.stl
Normal file
Binary file not shown.
@ -19,7 +19,7 @@
|
|||||||
"h": 56,
|
"h": 56,
|
||||||
"label": "On",
|
"label": "On",
|
||||||
"type": 1,
|
"type": 1,
|
||||||
"mqtt": [ "/s/cmnd/5C:CF:7F:20:29:6E/Power On" ]
|
"mqtt": [ {"topic": "/s/cmnd/5C:CF:7F:20:29:6E/Power", "message": "On"} ]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "heli_led_off",
|
"name": "heli_led_off",
|
||||||
@ -29,7 +29,7 @@
|
|||||||
"h": 56,
|
"h": 56,
|
||||||
"label": "Off",
|
"label": "Off",
|
||||||
"type": 1,
|
"type": 1,
|
||||||
"mqtt": [ "/s/cmnd/5C:CF:7F:20:29:6E/Power Off" ]
|
"mqtt": [ {"topic": "/s/cmnd/5C:CF:7F:20:29:6E/Power", "message": "Off"} ]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "heli_led_toggle",
|
"name": "heli_led_toggle",
|
||||||
@ -39,7 +39,7 @@
|
|||||||
"h": 56,
|
"h": 56,
|
||||||
"label": "Toggle",
|
"label": "Toggle",
|
||||||
"type": 1,
|
"type": 1,
|
||||||
"mqtt": [ "/s/cmnd/5C:CF:7F:20:29:6E/Power Toggle" ]
|
"mqtt": [ {"topic": "/s/cmnd/5C:CF:7F:20:29:6E/Power", "message": "Toggle"} ]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,8 @@
|
|||||||
"w": 48,
|
"w": 48,
|
||||||
"h": 48,
|
"h": 48,
|
||||||
"label": "Two",
|
"label": "Two",
|
||||||
"type": 0
|
"type": 1,
|
||||||
|
"mqtt": [ {"topic": "esp32_XXXXXX/rpc/Button.Touch", "message": {"args": {"idx":0}}} ]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
1
mos.yml
1
mos.yml
@ -99,7 +99,6 @@ libs:
|
|||||||
- origin: https://github.com/mongoose-os-libs/rpc-service-fs
|
- origin: https://github.com/mongoose-os-libs/rpc-service-fs
|
||||||
- origin: https://github.com/mongoose-os-libs/prometheus-metrics
|
- origin: https://github.com/mongoose-os-libs/prometheus-metrics
|
||||||
- origin: https://github.com/mongoose-os-libs/rpc-common
|
- origin: https://github.com/mongoose-os-libs/rpc-common
|
||||||
- origin: https://github.com/mongoose-os-libs/rpc-service-config
|
|
||||||
- origin: https://github.com/mongoose-os-libs/rpc-mqtt
|
- origin: https://github.com/mongoose-os-libs/rpc-mqtt
|
||||||
- origin: https://github.com/mongoose-os-libs/mqtt
|
- origin: https://github.com/mongoose-os-libs/mqtt
|
||||||
- origin: https://github.com/mongoose-os-libs/pwm
|
- origin: https://github.com/mongoose-os-libs/pwm
|
||||||
|
@ -49,7 +49,7 @@ int buttons_init(const char *flag) {
|
|||||||
s_buttons[next_button].gpio=gpio;
|
s_buttons[next_button].gpio=gpio;
|
||||||
s_buttons[next_button].last_change=-1;
|
s_buttons[next_button].last_change=-1;
|
||||||
mgos_gpio_set_mode(gpio, MGOS_GPIO_MODE_INPUT);
|
mgos_gpio_set_mode(gpio, MGOS_GPIO_MODE_INPUT);
|
||||||
mgos_gpio_set_button_handler(gpio, MGOS_GPIO_PULL_UP, MGOS_GPIO_INT_EDGE_NEG, 100, buttons_cb, NULL);
|
mgos_gpio_set_button_handler(gpio, MGOS_GPIO_PULL_NONE, MGOS_GPIO_INT_EDGE_POS, 300, buttons_cb, NULL);
|
||||||
|
|
||||||
next_button++;
|
next_button++;
|
||||||
if (next_button>MAX_BUTTONS) {
|
if (next_button>MAX_BUTTONS) {
|
||||||
|
@ -90,7 +90,7 @@ static void rpc_relay_set_handler(struct mg_rpc_request_info *ri, void *cb_arg,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
relays_set_by_idx(idx, state);
|
relays_set_by_idx(idx, (bool) state);
|
||||||
mg_rpc_send_responsef(ri, "{idx: %d, gpio: %d, state: %d}", idx, gpio, state);
|
mg_rpc_send_responsef(ri, "{idx: %d, gpio: %d, state: %d}", idx, gpio, state);
|
||||||
|
|
||||||
(void) cb_arg;
|
(void) cb_arg;
|
||||||
|
@ -124,30 +124,23 @@ static void widget_default_mqtt_send(struct widget_t *w, void *ev_data) {
|
|||||||
// LOG(LL_DEBUG, ("MQTT string: '%s'", (char *)w->user_data));
|
// LOG(LL_DEBUG, ("MQTT string: '%s'", (char *)w->user_data));
|
||||||
// Traverse Array
|
// Traverse Array
|
||||||
for (idx = 0; json_scanf_array_elem(w->user_data, strlen(w->user_data), "", idx, &val) > 0; idx++) {
|
for (idx = 0; json_scanf_array_elem(w->user_data, strlen(w->user_data), "", idx, &val) > 0; idx++) {
|
||||||
char *t=NULL, *m=NULL;
|
char *topic, *message;
|
||||||
uint16_t t_len=0, m_len=0;
|
|
||||||
char *topic;
|
|
||||||
|
|
||||||
LOG(LL_DEBUG, ("Index %d, token [%.*s]", idx, val.len, val.ptr));
|
LOG(LL_DEBUG, ("Index %d, token [%.*s]", idx, val.len, val.ptr));
|
||||||
t=(char*)val.ptr;
|
if (val.len==0) {
|
||||||
m=strstr(val.ptr, " ");
|
LOG(LL_ERROR, ("mqtt element %d is empty token", idx));
|
||||||
if (m-val.ptr <= val.len) {
|
continue;
|
||||||
t_len=m-t;
|
|
||||||
m++;
|
|
||||||
m_len=val.len-t_len-1;
|
|
||||||
} else {
|
|
||||||
t_len=val.len;
|
|
||||||
m_len=0;
|
|
||||||
m=NULL;
|
|
||||||
}
|
}
|
||||||
if ((topic=malloc(t_len+1))) {
|
if (json_scanf(val.ptr, val.len, "{topic:%Q, message:%Q}", &topic, &message) != 2) {
|
||||||
memcpy(topic, t, t_len);
|
LOG(LL_ERROR, ("mqtt element %d ('%.*s'), required fields 'topic' and 'message'", idx, val.len, val.ptr));
|
||||||
topic[t_len]=0;
|
continue;
|
||||||
LOG(LL_INFO, ("Sending topic='%s', message='%.*s'", topic, m_len, m));
|
}
|
||||||
mgos_mqtt_pub(topic, m, m_len, 0, false);
|
LOG(LL_INFO, ("Sending topic='%s', message='%s'", topic, message));
|
||||||
free(topic);
|
mgos_mqtt_pub(topic, message, strlen(message), 0, false);
|
||||||
widget_network_send();
|
widget_network_send();
|
||||||
}
|
|
||||||
|
if (topic) free(topic);
|
||||||
|
if (message) free(message);
|
||||||
}
|
}
|
||||||
(void) ev_data;
|
(void) ev_data;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user