Copyright © https://mongoose-os.com

Mongoose OS Forum

frame
ATTENTION! This forum has moved to:

https://community.mongoose-os.com

Do not post any new messages.

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 https://github.com/mongoose-os-apps/aws-uart 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

Comments

  • 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) {
          ucfg.dev.rx_gpio = uart_pin;
        }
        LOG(LL_INFO, ("UART %d, pin %d", sti_uart_no, ucfg.dev.rx_gpio));
    
        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.