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.

Using PPPOS as default communication channel

kosmo_dekosmo_de kosmo_de
edited December 2018 in Mongoose OS

Hi again, I am trying to use pppos dep to communicate with server (wifi disabled). Modem gives some feedback to debugging console, and receives ip address from operator.
But when I use mg_connect_http, request fails

mgos_net_on_change_c PPP: ready, IP 10.19.XXX.XXX, GW 10.64.64.64, DNS default
mgos_event_trigger ev NET3 triggered 1 handlers
mgos_pppos_send_cb >> 22 (av 1500)
mgos_pppos_send_cb >> 16 (av 1500)
mgos_pppos_uart_disp << 27
send_request Sending request...
mg_lwip_if_init Mongoose 6.13, LwIP 2.0.3
mg_connect_http_base http://{ip}:{port}/ use_ssl? 0 tcp://{ip}:{port}
mg_connect_opt 0x3ffbb04c tcp://{ip}:{port} -,-,-
mg_do_connect 0x3ffbb04c tcp://{ip}:{port}
mgos_pppos_send_cb >> 49 (av 1500)
send_request Starting http client against http://{ip}:{port}/

mgos_pppos_send_cb >> 22 (av 1451)
mgos_pppos_send_cb >> 49 (av 1429)
mgos_pppos_send_cb >> 49 (av 1380)
mgos_pppos_send_cb >> 22 (av 1331)
mgos_pppos_send_cb >> 49 (av 1309)
mgos_pppos_send_cb >> 16 (av 1260)
mgos_pppos_send_cb >> 49 (av 1244)
mgos_pppos_send_cb >> 22 (av 1195)
mgos_pppos_send_cb >> 49 (av 1173)
mgos_pppos_send_cb >> 49 (av 1124)
mg_if_connect_cb 0x3ffbb04c tcp://{ip}:{port} -> -13
Error connecting to http://{ip}:{port}/:

should I somehow configure network to use pppos interface by default?
is there any pppos/net connection callback to start my request from it?

my code:

static const char *s_url =   
    "http://{ip}:{port}/"
    ;

static int s_exit_flag = 0;

static void ev_handler(struct mg_connection *nc, int ev, void *ev_data, void *user_data) {
  struct http_message *hm = (struct http_message *) ev_data;
  int connect_status;

  switch (ev) {
    case MG_EV_CONNECT:
      connect_status = *(int *) ev_data;
      if (connect_status != 0) {
        printf("Error connecting to %s: %s\n", s_url, strerror(connect_status));
        s_exit_flag = 1;
      }
      break;
    case MG_EV_HTTP_REPLY:
      printf("Got reply:\n%.*s\n", (int) hm->body.len, hm->body.p);
      nc->flags |= MG_F_SEND_AND_CLOSE;
      s_exit_flag = 1;
      break;
    case MG_EV_CLOSE:
      if (s_exit_flag == 0) {
        printf("Server closed connection\n");
        s_exit_flag = 1;
      };
      break;
    default:
      break;
  }
}

void send_request(void *pvoid) {

  LOG(LL_INFO, ("Sending request..."));

  struct mg_mgr mgr;
  struct mg_connection *nc;

  mg_mgr_init(&mgr, NULL);
  nc = mg_connect_http(&mgr, ev_handler, NULL, s_url, NULL, NULL);
  mg_set_protocol_http_websocket(nc);

  LOG(LL_INFO, ("Starting http client against %s\n", s_url));
  while (s_exit_flag == 0) {
    mg_mgr_poll(&mgr, 1000);
  }
  mg_mgr_free(&mgr);
}

enum mgos_app_init_result mgos_app_init(void) {

  mgos_set_timer(15000, 0, send_request, NULL);

  return MGOS_APP_INIT_SUCCESS;
}
Thanked by 10xBoa

Comments

Sign In or Register to comment.