所以我有一个espressif芯片连接到两个发光二极管上,猫鼬在上面运行。
我想从互联网/计算机上获得时间,并在特定的时间启动led。
例如:在10:00打开/关闭led 1连接到引脚2,在16:00打开/关闭led 2连接到C中的引脚3。
发布于 2018-06-28 12:05:27
步骤1:将wifi设置添加到您的mos.yml中,以便它可以连接到您的无线AP:
config_schema:
- ["wifi.sta.enable", true]
- ["wifi.sta.ssid", "MyAP"]
- ["wifi.sta.pass", "Passwd"]步骤2:将这些添加到您的mos.yml中。如果您无意在UART上进行rpc调用,请关闭rpc-uart。
libs:
- origin: https://github.com/mongoose-os-libs/sntp
- origin: https://github.com/mongoose-os-libs/crontab
- origin: https://github.com/mongoose-os-libs/rpc-service-cron
- origin: https://github.com/mongoose-os-libs/rpc-service-config
- origin: https://github.com/mongoose-os-libs/wifi
- origin: https://github.com/mongoose-os-libs/rpc-uart步骤3:为LED打开和关闭添加crontab处理程序:
enum mgos_app_init_result mgos_app_init(void) {
/* Set LED GPIOs as outputs */
mgos_gpio_set_mode(YOUR_LED_GPIO, MGOS_GPIO_MODE_OUTPUT);
/* Register crontab handler - LED OFF */
mgos_crontab_register_handler(mg_mk_str("ledoff"), ledoff, NULL);
/* Register crontab handler - LED ON */
mgos_crontab_register_handler(mg_mk_str("ledon"), ledon, NULL);
return MGOS_APP_INIT_SUCCESS;
}步骤4:添加回调:
void ledoff(struct mg_str action, struct mg_str payload, void *userdata) {
mgos_gpio_write(YOUR_LED_GPIO, 0);
(void) payload;
(void) userdata;
(void) action;
}
void ledon(struct mg_str action, struct mg_str payload, void *userdata) {
mgos_gpio_write(YOUR_LED_GPIO, 1);
(void) payload;
(void) userdata;
(void) action;
}步骤5:来自Web或UART:
call Cron.Add '{"at":"0 0 10 00 * *", "action":"ledon"}'
call Cron.Add '{"at":"0 0 16 00 * *", "action":"ledoff"}'请参阅https://github.com/mongoose-os-libs/cron作为mgos上cron表达式语法的参考。
发布于 2020-05-21 04:12:35
从解决方案中找不到:
步骤2a:在main.c中添加:
#include "mgos_crontab.h"https://stackoverflow.com/questions/51081508
复制相似问题