Servus zusammen,
ich versuche Aktuell in meinem Projekt, eine Rangierhilfe für meinen Wohnwagen zu basteln,
leider komme ich nicht weiter, da meine Kommunikation zwischen Sender und Empfänger nicht ordnungsgemäß klappt.
Auf der Empfänger Seite, würde ich gerne die gesendeten Daten mit client.read() auslesen.
Ich weiß nicht, wo genau mein Wissen über Streams kaputt ist, da ich dies einfach nicht zum laufen bekomme.
Er schmeißt mir immer folgende Fehlermeldung:
Exception (29):
epc1=0x4000e01a epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
>>>stack>>>
ctx: cont
sp: 3ffffd80 end: 3fffffc0 offset: 01a0
3fffff20: 40202185 3ffee4bc 3ffe8514 3ffee4bc
3fffff30: 00000000 3ffee464 402030ec 3fffefa0
3fffff40: 4020368e 00000190 00000190 3ffee464
3fffff50: 3ffee3f8 3ffee3c4 000023aa 40201218
3fffff60: 40205098 00000000 00001388 40202b18
3fffff70: 00000000 3fff043c 40205098 00000000
3fffff80: 00001388 0104a8c0 00000000 3fff043c
3fffff90: 00000000 00000000 00000001 3ffee464
3fffffa0: 3fffdad0 00000000 3ffee430 4020319c
3fffffb0: feefeffe feefeffe 3ffe8514 40100461
<<<stack<<
Bzw:
Exception 29: StoreProhibited: A store referenced a page mapped with an attribute that does not permit stores
PC: 0x4000e01a
EXCVADDR: 0x00000000
Decoding stack results
0x40202185: WiFiClient::WiFiClient() at … Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\ESP8266WiFi\src/include/slist.h line 13
0x402030ec: uart_write_char_d(char) at Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\core_esp8266_postmortem.cpp line 207
0x4020368e: __pinMode(uint8_t, uint8_t) at Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\core_esp8266_wiring_digital.cpp line 44
0x40201218: loop() at \Empfaenger/Empfaenger.ino line 91
0x40202b18: Print::println(unsigned char, int) at Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\Print.cpp line 198
0x4020319c: print_stack(uint32_t, uint32_t) at Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\core_esp8266_postmortem.cpp line 189
Code auch nochmal im Anhang
Empfänger (ESP8266):
#include <ESP8266WiFi.h>
/* Your WiFi Soft Access Point settings */
/* SERVER */
#define LEFTDIRECTION 12 // ESP8266 pin 5 or D1 is connected to MDDS30 pin IN1.
#define RIGHTDIRECTION 13 // ESP8266 pin 0 or D2 is connected to MDDS30 pin IN2.
#define LEFTPWM 0 // ESP8266 pin 4 or D3 is connected to MDDS30 pin AN1.
#define RIGHTPWM 2 // ESP8266 pin 2 or D4 is connected to MDDS30 pin AN2.
const char* ssid = "WIFISSID"; //this will be the network name
const char* password = "LAZYPASSWORD"; //this will be the network password
uint8_t memory[4];
uint8_t* msg;
const uint16_t port = 1337;
const char * host = "192.168.1.83";
WiFiServer server(port);
void setup() {
//pinMode(LEFTDIRECTION, OUTPUT);
//pinMode(RIGHTDIRECTION, OUTPUT);
//pinMode(LEFTPWM, OUTPUT);
//pinMode(RIGHTPWM, OUTPUT);
//pinMode(LED_BUILTIN, OUTPUT);
delay(1000);
Serial.begin(9600);
Serial.println();
Serial.println();
Serial.print("Configuring WiFi access point...");
/* You can remove the password parameter if you want the AP to be open. */
WiFi.mode(WIFI_AP);
boolean result = WiFi.softAP(ssid, password);
if(result==true) {
IPAddress myIP = WiFi.softAPIP();
Serial.println("done!");
Serial.println("");
Serial.print("WiFi network name: ");
Serial.println(ssid);
Serial.print("WiFi network password: ");
Serial.println(password);
Serial.print("Host IP Address: ");
Serial.println(myIP);
Serial.println("");
// Start the server
server.begin();
Serial.println("Server started");
}
else {
Serial.println("error! Something went wrong...");
}
}
void loop() {
// Check if a client has connected
WiFiClient client = WiFiClient();
client = server.available();
if(!client) {
return;
}
// Wait until the client sends some data
unsigned long timeout = millis() + 3000;
while (!client.available() && millis() < timeout) {
delay(1);
//Serial.println("wait for data");
}
//Serial.println("new client");
if (millis() > timeout) {
Serial.println("timeout");
client.flush();
//client.stop();
return;
}
while(client.connected()){
delay(400);
if(!client.available()) continue;
delay(400);
int got = client.read(msg, 4);
//String line = client.readStringUntil('\r');
client.flush();
Serial.println("after Read");
for(int i = 0; i < got;i++ ){
Serial.println(*(msg+i));
}
/*
for(int i = 0; i < sizeof(line); i++)
{
Serial.println((uint8_t)line[i]);
}
*/
}
client.stopAll();
if(!client.available())
{
client.stop();
Serial.println("Client disconnected");
}
}
void bewegeWohnwagen(int speedLinks, int speedRechts) {
if (speedLinks > 0){
digitalWrite(LEFTDIRECTION, HIGH);
}
else {
digitalWrite(LEFTDIRECTION, LOW);
}
if (speedRechts > 0){
digitalWrite(RIGHTDIRECTION, HIGH);
}
else {
digitalWrite(RIGHTDIRECTION, LOW);
}
analogWrite(LEFTPWM,abs(speedLinks));
analogWrite(RIGHTPWM,abs(speedRechts));
}
Sender (ESP32):
#include <WiFi.h>
int middleRead = 1918;
int maxRead = 4096;
const char* ssid = "WIFISSID"; //replace this with your WiFi network name
const char* password = "LAZYPASSWORD"; //replace this with your WiFi network password
const uint16_t port = 1337;
const char * host = "192.168.4.1";
uint16_t sensorValueX = 0;
uint16_t sensorValueY = 0;
uint8_t sensorValues[4];
WiFiClient client;
void connectToNetwork() {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Establishing connection to WiFi..");
//WiFi.begin(ssid, password);
}
Serial.println("Connected to network");
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
connectToNetwork();
Serial.println(WiFi.localIP());
}
float mapForPWM(int value) {
if(value < middleRead - 30) {
value = map(value,0,middleRead,-1000,0);
} else if(value > middleRead + 30) {
value = map(value,middleRead,maxRead,0,1000);
} else {
value = 0;
}
return (float)value/1000;
}
void loop() {
if (!WiFi.isConnected()) connectToNetwork();
if(!client.connected()) {
if (!client.connect(host,port)){
Serial.println("Connection to host failed");
delay(1000);
return;
}
}
// put your main code here, to run repeatedly:
sensorValueX = analogRead(A4);
sensorValues[0] = sensorValueX & 0xff;
sensorValues[1] = (sensorValueX >> 8);
sensorValueY = analogRead(A5);
sensorValues[2] = sensorValueY & 0xff;
sensorValues[3] = (sensorValueY >> 8);
//sensorValues[4] = (uint8_t) '\r';
Serial.print("X:");
Serial.print(sensorValueX);
Serial.print(" X2:");
Serial.print(sensorValues[0]);
Serial.print(",");
Serial.print(sensorValues[1]);
Serial.print(" Y:");
Serial.print(sensorValueY);
Serial.print(" Y2:");
Serial.print(sensorValues[2]);
Serial.print(",");
Serial.println(sensorValues[3]);
int size = sizeof(sensorValues);
client.write(sensorValues, sizeof(size));
//client.println((char*) sensorValues);
Serial.println((char*) sensorValues);
Serial.print("Size: ");
Serial.println(size);
client.stop();
delay(100);
}
Empfaenger.ino (3.13 KB)
Sender.ino (2.22 KB)