PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : SDK: espconn_send liefert -12



drew
19.03.2019, 20:31
Hallo,
ich verwende das SDK V2.1.0. Ich arbeite also nicht mit Arduino.
Ich will von meinem ESP auf eine HTML-Seite im Netz zugreifen. Ich habe mir gedacht dass ich dazu TCP verwenden kann und mit espconn_send meine GET Anfrage schicken kann. Unten ist mein Code.
Leider bekomme ich -12 (=ESPCONN_ARG) als Rückgabewert. Kann mir jemand sagen, was ich falsch mache?

Besten Dank,
drewle


void init_Tcp_client(void)
{
sint8 s8_err;

os_printf("init_Tcp_client\r\n");

// Preset t_tcp. only remote_port is needed
gt_tcp2.local_ip[0] = 192; // setting the local IP seams not to be really needed
gt_tcp2.local_ip[1] = 168;
gt_tcp2.local_ip[2] = 178;
gt_tcp2.local_ip[3] = 20;
gt_tcp2.local_port = 80;
gt_tcp2.remote_ip[0] = xxx;
gt_tcp2.remote_ip[1] = xxx;
gt_tcp2.remote_ip[2] = xxx;
gt_tcp2.remote_ip[3] = xxx;
gt_tcp2.remote_port = 80;
gt_tcp2.connect_callback = NULL; // as the global variables are set to 0 this is not really needed
gt_tcp2.reconnect_callback = NULL;
gt_tcp2.disconnect_callback = NULL;
gt_tcp2.write_finish_fn = NULL;

gt_conn2.type = ESPCONN_TCP;
gt_conn2.state = ESPCONN_NONE;
gt_conn2.proto.tcp = &gt_tcp2;
gt_conn2.recv_callback = recv_Cb;
gt_conn2.sent_callback = NULL; // as the global variables are set to 0 this is not really needed
gt_conn2.link_cnt = 1;
gt_conn2.reverse = NULL;

// wait for the connection of a client
s8_err = espconn_accept(&gt_conn2);
os_printf("espconn_accept: %d\r\n",s8_err);

os_printf("gt_conn2.state: %u\r\n",gt_conn2.state);
}

void my_timer_function(void *timer_arg)
{
uint16 u16_AdcVal;
sint8 s8_err;

// if( gu8_GotIp==true )
{
// Read the ADC value
u16_AdcVal = system_adc_read();
os_printf("ADC Value: %u\n", u16_AdcVal);

os_printf("gt_conn2.type: %u\r\n",gt_conn2.type);
os_printf("gt_conn2.state: %u\r\n",gt_conn2.state);
os_printf("gt_conn2.proto: %llu\r\n",gt_conn2.proto);
os_printf("gt_conn2.recv_callback: %llu\r\n",gt_conn2.recv_callback);
os_printf("gt_conn2.sent_callback: %llu\r\n",gt_conn2.sent_callback);
os_printf("gt_conn2.link_cnt: %u\r\n",gt_conn2.link_cnt);
os_printf("gt_conn2.reverse: %llu\r\n",gt_conn2.reverse);

// send request
s8_err = espconn_send(&gt_conn2,gc_Request,strlen(gc_Request));
os_printf("espconn_send: %d\r\n",s8_err);
}
}

Ceos
21.03.2019, 06:21
Da fehlt noch reichlich Kontext um Antworten zu können, z.B. sendest du in deinem Code den Inhalt von "gc_Request"... das ist aber nirgendwo deklariert oder hat irgendwelchen Inhalt ... dein Code ist leider zu unvollständig um dir helfen zu können denn die Doku sagt nur dass du ein falsches Argument beim Aufruf geliefert hast.

"gu8_GotIp" zum Beispiel wird auch nirgendwo verändert, könnte auch Einfluss auf das Problem haben ... mit solchen Bruchstücken kann man nix anfangen sorry.

drew
28.03.2019, 11:27
Das Problem war wohl das "espconn_accept". Dadurch wird der ESP zum Server. Einfach so mal senden ist dann nicht mehr.
Ohne dem geht es dann fehlerfrei. :-)

Danke fürs Helfen
Drew