Hi every one.
I want ask help for my project, may be you can answer me with comments.
My proyecto is with ESP8266 (WEMOS-MINI Wemos D1 Min) with 16 mbits, and i using the SDK 3.1 RTOS.
The main point is count a pulse on 2 ISTR, this is good.
After count need send to a wen socket only 17 bytes.
The idea is send very fast for not loose when the pulse are incomming. (this is very important on the project).
I have 3 task, 2 of them for ISR and the anohter one for send to a web socket.
The server return 2 byte for give a Acknowledgment of receipt and i make sure that reception was good the another way it will send again.
All are working but i have a doubt on the recepcion, I do not have a timeout on the reception.
I do not how put a timeout for the recepction, for example, if wait 20ms and i do have any answer from the server.
Do you have a idea ?
int sock = socket(addr_family, SOCK_STREAM, ip_protocol); // create the socket
int err = connect(sock, (struct sockaddr *)&destAddr, sizeof(destAddr)); // connect the socket
// vTaskDelay(10 / portTICK_PERIOD_MS);
err = write(sock, cad_1, 17); // strlen(cad_1) // send 17 bytes
vTaskDelay(15 / portTICK_PERIOD_MS);
uint8_t rx_buffer[3]; // buffer of data
bool ack = 0; // answer OK/NOT
ssize_t bytesRcbs; // Nº byte received
do {
errno = ERR_OK; //
// Use MSG_PEEK for take something.
bytesRcbs = recv(sock, rx_buffer, sizeof (rx_buffer) - 1, MSG_PEEK); // cambiar por MSG_PEEK | MSG_DONTWAIT
// delay
if (bytesRcbs == 0) {
vTaskDelay(25 / portTICK_PERIOD_MS);
} else {
if (bytesRcbs > 0){
if (debug==1){
printf ("\n");
printf ("rx_buffer[0]=%x", rx_buffer[0]);
printf (" - ");
printf ("rx_buffer[1]=%x\n", rx_buffer[1]);
}
if (rx_buffer[0]==0x0b && rx_buffer[1]==0x01){
if (debug==1){
printf ("OK ACK- ");
}
ack = 1;
} else {
ack = 0;
printf ("NOT ACK\n");
}
} else {
if (bytesRcbs < 0){
printf ("Er_rc0\n");
break;
}
}
}
} while ((bytesRcbs == 0) && (errno == ERR_OK));
time out waiting for the answer of the send
-
- Posts: 2
- Joined: Sun Apr 14, 2019 10:22 pm
Who is online
Users browsing this forum: Bing [Bot] and 76 guests