Skip to content

Commit

Permalink
simple forward from socket to serial for sertest
Browse files Browse the repository at this point in the history
  • Loading branch information
wellenvogel committed Nov 12, 2023
1 parent f885642 commit 3cc2e51
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions lib/sertesttask/SerTestTask.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
#include "SerTestTask.h"
#include "GwHardware.h"
#include <WiFi.h>
#ifdef SERTEST
WiFiServer listener(10111);
const size_t BUFSIZE=10240;
void sertest(GwApi *api){
GwLog *logger=api->getLogger();
LOG_DEBUG(GwLog::LOG,"ser test task started");
Serial2.begin(api->getConfig()->getInt(GwConfigDefinitions::serialBaud), SERIAL_8N1,-1,GWSERIAL_RX);
listener.begin();
uint8_t *buffer=new uint8_t[BUFSIZE+1];
while (true){
const char * T="SERTESTXXX";
LOG_DEBUG(GwLog::LOG,"sending %s",T);
Serial2.println(T);
delay(1000);
WiFiClient client = listener.available();
if (client) {
if (client.connected()) {
LOG_DEBUG(GwLog::LOG,"SerTest Connected to client");
while (true){
if (! client.connected()){
break;
}
int avail=client.available();
if (avail){
size_t rd=client.readBytes(buffer,avail);
if (rd > 0){
LOG_DEBUG(GwLog::DEBUG,"SerTest read %d bytes",(int)rd);
size_t wr=Serial2.write(buffer,rd);
LOG_DEBUG(GwLog::DEBUG,"SerTest written %d bytes",(int)wr);

}
else{
delay(50);
}
}
else{
delay(50);
}
}
}

// close the connection:
LOG_DEBUG(GwLog::LOG,"SerTest closing connection");
client.stop();
}
delay(50);
}
vTaskDelete(NULL);
return;
Expand Down

0 comments on commit 3cc2e51

Please sign in to comment.