Compare commits

...

5 Commits

Author SHA1 Message Date
7fffd33e3a Remove dup library in mos.yml; cast 'value' to bool in Relay.Set() 2018-01-05 01:43:38 +01:00
71410fee91 Update screens to use new MQTT format. 2018-01-02 00:21:38 +01:00
9dbf9be428 Simplify MQTT messaging
Simply add the entire mosquitto message as a JSON entity, not a string.
The simple case now looks like:
      "mqtt": [ {"topic": "/s/cmnd/5C:CF:7F:20:29:6E/Power", "message": "On"} ]

Sending an RPC to Mongoose OS looks like:
      "mqtt": [ {"topic": "esp32_XXXXXX/rpc/Button.Touch", "message": {"args": {"idx":0}}} ]
2018-01-02 00:20:15 +01:00
0ea78abf4c Add extra debounce delay in button presses. Trigger on button-up. 2018-01-02 00:19:37 +01:00
a342ff6815 Add 3D printable objects:
LightSwitch Base plate
LightSwitch Button (for duo-switches)
Add PNGs for both.
2018-01-02 00:18:32 +01:00
10 changed files with 20 additions and 27 deletions

BIN
docs/LightSwitch-Base.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 KiB

BIN
docs/LightSwitch-Base.stl Normal file

Binary file not shown.

BIN
docs/LightSwitch-Button.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

BIN
docs/LightSwitch-Button.stl Normal file

Binary file not shown.

View File

@ -19,7 +19,7 @@
"h": 56,
"label": "On",
"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",
@ -29,7 +29,7 @@
"h": 56,
"label": "Off",
"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",
@ -39,7 +39,7 @@
"h": 56,
"label": "Toggle",
"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"} ]
}
]
}

View File

@ -18,7 +18,8 @@
"w": 48,
"h": 48,
"label": "Two",
"type": 0
"type": 1,
"mqtt": [ {"topic": "esp32_XXXXXX/rpc/Button.Touch", "message": {"args": {"idx":0}}} ]
}
]
}

View File

@ -99,7 +99,6 @@ libs:
- 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/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/mqtt
- origin: https://github.com/mongoose-os-libs/pwm

View File

@ -49,7 +49,7 @@ int buttons_init(const char *flag) {
s_buttons[next_button].gpio=gpio;
s_buttons[next_button].last_change=-1;
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++;
if (next_button>MAX_BUTTONS) {

View File

@ -90,7 +90,7 @@ static void rpc_relay_set_handler(struct mg_rpc_request_info *ri, void *cb_arg,
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);
(void) cb_arg;

View File

@ -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));
// Traverse Array
for (idx = 0; json_scanf_array_elem(w->user_data, strlen(w->user_data), "", idx, &val) > 0; idx++) {
char *t=NULL, *m=NULL;
uint16_t t_len=0, m_len=0;
char *topic;
char *topic, *message;
LOG(LL_DEBUG, ("Index %d, token [%.*s]", idx, val.len, val.ptr));
t=(char*)val.ptr;
m=strstr(val.ptr, " ");
if (m-val.ptr <= val.len) {
t_len=m-t;
m++;
m_len=val.len-t_len-1;
} else {
t_len=val.len;
m_len=0;
m=NULL;
if (val.len==0) {
LOG(LL_ERROR, ("mqtt element %d is empty token", idx));
continue;
}
if ((topic=malloc(t_len+1))) {
memcpy(topic, t, t_len);
topic[t_len]=0;
LOG(LL_INFO, ("Sending topic='%s', message='%.*s'", topic, m_len, m));
mgos_mqtt_pub(topic, m, m_len, 0, false);
free(topic);
if (json_scanf(val.ptr, val.len, "{topic:%Q, message:%Q}", &topic, &message) != 2) {
LOG(LL_ERROR, ("mqtt element %d ('%.*s'), required fields 'topic' and 'message'", idx, val.len, val.ptr));
continue;
}
LOG(LL_INFO, ("Sending topic='%s', message='%s'", topic, message));
mgos_mqtt_pub(topic, message, strlen(message), 0, false);
widget_network_send();
}
if (topic) free(topic);
if (message) free(message);
}
(void) ev_data;
}