i have a python script using sockets sending data to my wemos d1 mini clone (esp8266). i noticed that even though the led is set to low its on actually. i dont know why it is crashing. i basically stole the code from when i used it for usb serial and tried to change things around for wifi communication. i can set up python as server or client sending messages i have both scripts at the ready for whatever works better on arduino
error is-
ets Jan 8 2013,rst cause:4, boot mode:(3,7)
wdt reset
load 0x4010f000, len 3460, room 16
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4
tail 4
chksum 0xc9
csum 0xc9
v00044680
~ld
code
#include <WiFi.h>
#include <AccelStepper.h>
#include <MultiStepper.h>
#define ENABLE 8
AccelStepper Motor1(1, 4, 3);
AccelStepper Motor2(1, 1, 2);
AccelStepper Motor3(1, 6, 7);
AccelStepper Motor4(1, 0, 5);
boolean newData = false;
const byte numChars = 26;
char receivedChars[numChars];
char tempChars[numChars];
int Motor1Data = 0;
int Motor2Data = 0;
int Motor3Data = 0;
int Motor4Data = 0;
int Motor1Receive = 15000;
int Motor2Receive = 15000;
int Motor3Receive = 15000;
int Motor4Receive = 15000;
char* ssid = "FoxFi";
char* password = "password";
const uint16_t port = 1324;
const char* host = "192.168.0.165";
WiFiClient client;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println("Connecting to WiFi...");
}
Serial.print("WiFi connected with IP: ");
Serial.println(WiFi.localIP());
pinMode(ENABLE, OUTPUT);
digitalWrite(ENABLE, LOW);
Motor1.setMaxSpeed(20000);
Motor2.setMaxSpeed(20000);
}
void loop() {
WiFiClient client;
if (!client.connect(host, port)) {
Serial.println("Connection to host failed");
delay(500);
return;
}
Serial.println("Connected to server successful!");
recvWithStartEndMarkers();
Motor1.runSpeed();
Motor2.runSpeed();
Motor1Data = map(Motor1Receive, 0, 30000, -15000, 15000);
Motor2Data = map(Motor2Receive, 0, 30000, -15000, 15000);
if (newData == true) {
strcpy(tempChars, receivedChars);
parseData();
if (Motor1Data > 2){
Motor1.setSpeed(Motor1Data);
}
else if (Motor1Data < - 2){
Motor1.setSpeed(Motor1Data);
}
else{
Motor1.setSpeed(0);
}
if (Motor2Data > 2){
Motor2.setSpeed(Motor2Data);
}
else if (Motor2Data < -2){
Motor2.setSpeed(Motor2Data);
}
else{
Motor2.setSpeed(0);
}
if (Motor3Data > 2){
Motor3.setSpeed(Motor3Data);
}
else if (Motor3Data < - 2){
Motor3.setSpeed(Motor3Data);
}
else{
Motor3.setSpeed(0);
}
if (Motor2Data > 4){
Motor4.setSpeed(Motor4Data);
}
else if (Motor4Data < -2){
Motor4.setSpeed(Motor4Data);
}
else{
Motor4.setSpeed(0);
}
newData = false;
}
}
void recvWithStartEndMarkers() {
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char PythonRead;
while (client.available() > 0 && newData == false) {
PythonRead = client.read();
Serial.println(PythonRead);
if (recvInProgress == true) {
if (PythonRead != endMarker) {
receivedChars[ndx] = PythonRead;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (PythonRead == startMarker) {
recvInProgress = true;
}
}
}
void parseData() { // split the data into its parts
char * strtokIndex; // this is used by strtok() as an index
strtokIndex = strtok(tempChars,",");
Motor1Receive = atoi(strtokIndex);
strtokIndex = strtok(NULL, ",");
Motor2Receive = atoi(strtokIndex);
strtokIndex = strtok(NULL, ",");
Motor3Receive = atoi(strtokIndex);
strtokIndex = strtok(NULL, ",");
Motor4Receive = atoi(strtokIndex);
}