Connecting to an IP address (not hostname) directly
Posted: Sun Feb 22, 2015 11:19 am
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:
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.
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 all
void 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.