Copyright ©

Mongoose OS Forum


Receiving data serially from another MCU into esp8266 in c language

Hi, I have an already developed code in which I want to add the functionality of receiving data serially from Arduino and posting the data to AWS IoT. The example here is in JS but the program I have is in C language. So can someone please help me to take data into esp8266 serially using C language that can be posted to AWS IoT. Thanks


  • Here is what I have in my mgos_app_init_result:

      sti_uart_no = mgos_sys_config_get_sti_uart_uartno();
      if (sti_uart_no != -1) {
        struct mgos_uart_config ucfg;
        mgos_uart_config_set_defaults(sti_uart_no, &ucfg);
        ucfg.baud_rate = 9600;
        ucfg.num_data_bits = 8;
        ucfg.parity = MGOS_UART_PARITY_NONE;
        ucfg.stop_bits = MGOS_UART_STOP_BITS_1;
        int uart_pin = mgos_sys_config_get_sti_uart_pin();
        if (uart_pin != -1) {
 = uart_pin;
        LOG(LL_INFO, ("UART %d, pin %d", sti_uart_no,;
        if (!mgos_uart_configure(sti_uart_no, &ucfg)) {
          return MGOS_APP_INIT_ERROR;
        mgos_uart_set_dispatcher(sti_uart_no, uart_dispatcher, NULL /* arg */);
        mgos_uart_set_rx_enabled(sti_uart_no, true);

    and my handler looks like this

    static void uart_dispatcher(int cb_uart_no, void *arg) {
      char * str;
      static struct mbuf lb = {0};
      assert(cb_uart_no == sti_uart_no);
      size_t rx_av = mgos_uart_read_avail(sti_uart_no);
      if (rx_av == 0) return;
      mgos_uart_read_mbuf(sti_uart_no, &lb, rx_av);
      // we got a good message, so remove the bytes
      mbuf_remove(&lb, lb.len);
Sign In or Register to comment.