Skip to content

unstable websocket connection when use the software serial  #105

Closed
@mkeyno

Description

@mkeyno

Hi @Links2004 Markus , I have no problem with websocket unless try read the software serial data and pass it over the websocket link . its kinda some buffer full and overflow, because after couple of try the connection is sever
following is the loop function

#include <SoftwareSerial.h>
#define RxD 15  
#define TxD 13 
SoftwareSerial SIM(RxD, TxD, false, 256);
WebSocketsServer webSocket = WebSocketsServer(81);
ESP8266WebServer server(80);
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght) {
 client_num=num;
 switch(type) {
        case WStype_DISCONNECTED:
                                 Serial.printf("[WS:%u Disconnected!]\n", num); 
                 ACCESS=false;
        break;
        case WStype_CONNECTED:   { 
                       IPAddress ip = webSocket.remoteIP(num);
                   ACCESS=true;
                  Serial.print("[WS:]Clinet "); Serial.print(num); Serial.print(" CONNECTED with IP: ");Serial.println(ip);

                 } 
        break;
        case WStype_TEXT:    // this for  webSocket request          
                String text = String((char *) &payload[0]);
                Serial.print("[WS:"); Serial.print(num);Serial.print("]");Serial.println(text);

               SIM.print(text+"\r\n");
        break;


      }

}

String read_sim(void)
{
   String sim_buf="";
  while (SIM.available() > 0) 
                           { 
                           char c = (char)SIM.read();
                            sim_buf+=c;
                           Serial.print(c);
                           }
 return sim_buf;
}

void loop() 
{
 server.handleClient();  
 webSocket.loop(); 
if(SIM.available() > 0) webSocket.sendTXT(client_num,read_sim().c_str()); 
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions