-->
Page 1 of 1

Connecting to an IP address (not hostname) directly

PostPosted: Sun Feb 22, 2015 11:19 am
by rith87
Hello folks,

This question is a more accurately worded version of this other question (viewtopic.php?f=6&t=1682) I posted; hopefully, it will receive more love from the community here. Or if it really is a silly question, please let me know too.

I'm trying to write some firmware to connect to a server on the local network. Here's my initial stab at it:

Code: Select allvoid ICACHE_FLASH_ATTR httpclientFetchIP(ip_addr_t *ip) {
...
  struct espconn *pespconn = (struct espconn *)os_zalloc(sizeof(struct espconn));
  pespconn->type = ESPCONN_TCP;
  pespconn->state = ESPCONN_NONE;
  pespconn->proto.tcp = (esp_tcp *)os_zalloc(sizeof(esp_tcp));
  pespconn->proto.tcp->local_port = espconn_port();
  pespconn->proto.tcp->remote_port = 80;

  *((uint8 *) &pespconn->proto.tcp->remote_ip)     = (ip->addr >> 24) & 0xff;
  *((uint8 *) &pespconn->proto.tcp->remote_ip + 1) = (ip->addr >> 16) & 0xff;
  *((uint8 *) &pespconn->proto.tcp->remote_ip + 2) = (ip->addr >> 8) & 0xff;
  *((uint8 *) &pespconn->proto.tcp->remote_ip + 3) = (ip->addr) & 0xff;

  espconn_regist_connectcb(pespconn, httpclientConnectedCb);
  espconn_regist_disconcb(&conn, httpclientDisconCb);
  // espconn_regist_reconcb(pespconn, httpclientDisconCb);
  int8_t res = espconn_connect(pespconn);
  os_printf("espconn_connect() returned %d", res);   
}


This code seems pretty similar to the IOT sample code at http://www.electrodragon.com/w/ESP8266_IoT in the "procedure for sending data to the PC" code snippet. Unfortunately, I'm hitting an error ESPCONN_RTE, which according to the header file, means that there was a routing problem. Does anyone know what that means?

I don't believe that the code is too far off because the code seems to work fine (successfully establish an http connection) if I move the espconn_connect() code into the callback function for espconn_gethostbyname().

I guess another logical question is how is everyone else doing development testing? What sample code is everyone else working off of when connecting to an IP address?

PS: I'm not using the AT commands approach because I need the esp-httpd functionality for this project. But I'm open to any logical suggestions.

Re: Connecting to an IP address (not hostname) directly

PostPosted: Sun Feb 22, 2015 9:12 pm
by rith87
Ok, so, a few more basic questions:

1. Is everyone able to connect to a local IP address (via espconn_connect(), without espconn_gethostbyname()) fine?
2. Or does everyone test with hostnames rather than IP addresses?

Re: Connecting to an IP address (not hostname) directly

PostPosted: Mon Feb 23, 2015 5:11 am
by rith87
Not sure how many folks are following this thread but I've been messing around with the IoT demo from Espressif and it seems to be able to connect to an IP address directly (following the tutorial at http://www.electrodragon.com/w/ESP8266_IoT). In other words, using the same code to connect to a server, the ESP8266 is able to connect using the IoT demo stack but not the esphttpd stack.