Working version including remote access
This commit is contained in:
39
src/main.c
39
src/main.c
@@ -64,7 +64,11 @@ static void timer_cb(void *arg) {
|
||||
esp_chip_info(&ci);
|
||||
tp_print(UART_NO, "t=%.1f C, h=%ld mH, tasks=%d\n", (float) (temp-32)/1.8 - tempOffset, hall, uxTaskGetNumberOfTasks());
|
||||
#elif CS_PLATFORM == CS_P_ESP8266
|
||||
tp_print(UART_NO, "xyz\n");
|
||||
tp_print(UART_NO,
|
||||
"mem=%d kB, free=%d kB, fs=%d kB\n",
|
||||
(int) mgos_get_heap_size()/1024,
|
||||
(int) mgos_get_free_heap_size()/1024,
|
||||
(int) mgos_get_fs_size()/1024);
|
||||
#endif
|
||||
|
||||
(void) arg;
|
||||
@@ -89,6 +93,33 @@ static void printSystemInfo() {
|
||||
#endif
|
||||
}
|
||||
|
||||
// RPC Interfaces
|
||||
static void rpc_tpPrint(struct mg_rpc_request_info *ri, void *cb_arg,
|
||||
struct mg_rpc_frame_info *fi, struct mg_str args) {
|
||||
struct mbuf fb;
|
||||
struct json_out out = JSON_OUT_MBUF(&fb);
|
||||
char *text = NULL;
|
||||
|
||||
mbuf_init(&fb, 100);
|
||||
|
||||
if (json_scanf(args.p, args.len, ri->args_fmt, &text) == 1) {
|
||||
LOG(LL_INFO, ("TP print text: %s\n", text));
|
||||
json_printf(&out, "{result: 0, resultString: %Q}", "OK");
|
||||
tp_print_text(text);
|
||||
} else {
|
||||
json_printf(&out, "{error: %Q}", "text is required");
|
||||
}
|
||||
|
||||
mg_rpc_send_responsef(ri, "%.*s", fb.len, fb.buf);
|
||||
ri = NULL;
|
||||
mbuf_free(&fb);
|
||||
|
||||
(void) cb_arg;
|
||||
(void) fi;
|
||||
(void) args;
|
||||
}
|
||||
|
||||
|
||||
enum mgos_app_init_result mgos_app_init(void) {
|
||||
struct mgos_uart_config ucfg;
|
||||
mgos_uart_config_set_defaults(UART_NO, &ucfg);
|
||||
@@ -105,11 +136,15 @@ enum mgos_app_init_result mgos_app_init(void) {
|
||||
return MGOS_APP_INIT_ERROR;
|
||||
}
|
||||
|
||||
mgos_uart_set_rx_enabled(UART_NO, false);
|
||||
printf("Initial printer operation");
|
||||
tp_init(UART_NO);
|
||||
|
||||
mgos_set_timer(60000 /* ms */, true /* repeat */, timer_cb, NULL /* arg */);
|
||||
|
||||
mgos_uart_set_rx_enabled(UART_NO, false);
|
||||
// Initialize RPC interfaces
|
||||
struct mg_rpc *c = mgos_rpc_get_global();
|
||||
mg_rpc_add_handler(c, "TP.Print", "{text: %Q}", rpc_tpPrint, NULL);
|
||||
|
||||
tp_reset_mode(TP_MODE_ALL);
|
||||
tp_print(UART_NO, "TEST Print\r");
|
||||
|
||||
Reference in New Issue
Block a user