Guten Tag,
ich möchte mit meinem Pretzelboard eine TCP - Verbindung zu einem Python Programm herstellen. Folgender Code:
/*
TCP-Server
Change SSID and PASSWORD.
*/
#define SSID "FRITZ_4040"
#define PASSWORD "pwd"
#define DEBUG true
#define LED_WLAN 13
#include <Arduino.h>
#include <NanoESP.h>
#include <SoftwareSerial.h>
char receivedChars[1024];
NanoESP esp8266 = NanoESP();
SoftwareSerial NanoESP(11, 12); // RX, TX
void setup() {
Serial.begin(19200);
esp8266.begin(19200);
if (!espConfig()) serialDebug();
else digitalWrite(LED_WLAN, HIGH);
}
int rr;
String snd;
String rec;
int clientId;
void loop() {
if (esp8266.available())
{
rec = esp8266.readString();
debug(rec);
delay(10);
}
clientId = esp8266.getId();
if (clientId >=0)
{
String webpage = "Hello World!";
esp8266.sendData(clientId, webpage);
}
//debug(sendCom("AT+CIPSTATUS"));
}
//-----------------------------------------Config ESP8266------------------------------------
boolean espConfig()
{
boolean succes = true;
esp8266.setTimeout(5000);
succes &= sendCom("AT+RST", "ready");
esp8266.setTimeout(1000);
if (configStation(SSID, PASSWORD)) {
succes &= true;
debug("WLAN Connected");
debug("My IP is:");
debug(sendCom("AT+CIFSR"));
}
else
{
succes &= false;
}
//shorter Timeout for faster wrong UPD-Comands handling
succes &= sendCom("AT+CIPMODE=0", "OK");
succes &= sendCom("AT+CIPMUX=0", "OK");
configTCPServer();
return succes;
}
boolean configTCPServer()
{
boolean succes = true;
succes &= (sendCom("AT+CIPMUX=1", "OK"));
succes &= (sendCom("AT+CIPSERVER=1,50006", "OK"));
return succes;
}
boolean configStation(String vSSID, String vPASSWORT)
{
boolean succes = true;
succes &= (sendCom("AT+CWMODE=1", "OK"));
esp8266.setTimeout(20000);
succes &= (sendCom("AT+CWJAP=\"" + String(vSSID) + "\",\"" + String(vPASSWORT) + "\"", "OK"));
esp8266.setTimeout(1000);
return succes;
}
//-----------------------------------------------Controll ESP-----------------------------------------------------
boolean sendCom(String command, char respond[])
{
esp8266.println(command);
if (esp8266.findUntil(respond, "ERROR"))
{
return true;
}
else
{
debug("ESP SEND ERROR: " + command);
return false;
}
}
String sendCom(String command)
{
esp8266.println(command);
return esp8266.readString();
}
//-------------------------------------------------Debug Functions------------------------------------------------------
void serialDebug() {
while (true)
{
if (esp8266.available())
Serial.write(esp8266.read());
if (Serial.available())
esp8266.write(Serial.read());
}
}
void debug(String Msg)
{
if (DEBUG)
{
Serial.println(Msg);
}
}
Das Problem:
Ich empfange daten vom Python - Programm, nur das Senden klappt nicht, weil die clientId = -1 ist.
Woran liegt das?