General

Sending TCP to WifiBee

userHead judohippo 2024-01-14 20:51:28 118 Views0 Replies

Hey all,
I rather green to all this so apologies if this is straightforward.


I have a DFRduino UNO R3 with IO Expansion Shield and an ESP8266 WiFi Bee. I'm trying to start a TCP server and send messages do it.  

I'm trying to base my changes of this tutorial: https://wiki.dfrobot.com/SKU_TEL0092_WiFi_Bee-ESP8266_Wirelss_module#target_5

Here's what I have: 

```
//Same as tutorial until this point

….

 

void loop()
{
 int state = wifi.getState();
 switch (state)
 {
 case WIFI_NEW_MESSAGE:
   Serial.println("new message!");
   incomingData = wifi.getMessage();
   wifi.sendMessage(incomingData); // send the message to TCP server what it has received
   wifi.setState(WIFI_IDLE);
   break;
 case WIFI_CLOSED: // reconnet to the TCP server
   Serial.println("server is closed! and trying to reconnect it!");

   break;
 case WIFI_IDLE:
   if (!serverStarted)
   {
     if (wifi.openTCPServer(8668, 3))
     {
       serverStarted = true;
       Serial.println("server started!");
       wifi.setState(WIFI_IDLE);
     }
     else
     {
       serverStarted = false;
       Serial.println("server failed to start");
       wifi.setState(WIFI_CLOSED);
     }
   }

   int sta = wifi.checkMessage();
   Serial.println(sta);
   wifi.setState(sta);
   break;
 }
}
```

If I throw a println in `checkMessage` in the esp8266 class it just keeps returning `ERROR` message 

Here's my logs : 


```
AT+CWMODE?
AT+CWJAP="***","***"
connect ap sucessful !
AT+CIFSR
esp8266 ip:192.168.1.206
AT+CIPMUX=1
AT+CIPSERVER=1,8668
AT+CIPSTO=3
server started!
server started!
ERROR

1
server started!
ERROR
ERROR
ERROR

ERROR
1
ERROR

1
server started!
ERROR
ERROR
ERROR
ERROR
ERROR
ERROR
ERROR

ERROR
ERROR
ERROR
```

This all may be related to how Im sending messages though is which by using netcat with commands like 

```
echo 1 | nc 192.168.1.206 8668
```


I am totally lost. Any help would be great!