accelstepper and watchdog

wanti00
Posts: 4
Joined: Thu Jul 02, 2020 3:06 pm

accelstepper and watchdog

Postby wanti00 » Thu Jul 02, 2020 3:09 pm

Hi i have a code like this. I am sending step values via mqtt.
İf i dont use disable watchdog then i get crash around step no 100 and if i use watchdog i get error around step no 1300.



ets Jan 8 2013,rst cause:4, boot mode:(3,6)

wdt reset
load 0x4010f000, len 3456, room 16
tail 0
chksum 0x84
csum 0x84
va5432625
~ld

Code: Select all

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <AccelStepper.h>

#define Motor1_Dir 5
#define Motor1_Step 4

const char* ssid = "xxx";
const char* password = "xxx";
const char* mqtt_server = "xxx";
const char* mqttUser = "xxx";
const char* mqttPassword = "xxx";

int value;
bool flag1;

AccelStepper stepper(1, Motor1_Step, Motor1_Dir); 

WiFiClient espClient;
PubSubClient client(espClient);


void setup_wifi() 
{
  delay(10);
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) 
  {
    delay(500);
    Serial.print(".");
  }
  randomSeed(micros());
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}


void callback(char* topic, byte* payload, unsigned int length) 
{
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");

value = 0;
  int tensValue = 1;
  for (int i = length - 1; i >=0; i--) // iterate backwards
  {
    value += (payload[i] - '0') * tensValue ;
    tensValue = tensValue * 10;
  }
  flag1 = true;



  
//  for (int i = 0; i < length; i++) 
//  {
//   Serial.print((char)payload[i]);
 // value = (char)payload [length -1];
 //   flag1 = true;
//  }
//  Serial.println();
//  Serial.print("Mesaj Geldi");
}


void reconnect() 
{
  while (!client.connected()) 
  {
    Serial.print("Attempting MQTT connection...");
   
    if (client.connect("alkan")) 
    {
      Serial.println("connected");
      client.subscribe("Alkan/perde");
    } 
    else 
    {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 3 seconds");
      delay(3000);
    }
  }
}


void setup() 
{
  Serial.begin(115200);
  
  setup_wifi();
  
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback); 

  stepper.setMaxSpeed(200);
  stepper.setAcceleration(100);  
//  stepper.setSpeed(200);    
}



void loop() 
{
  if (!client.connected()) 
  {
    reconnect();
  }
  client.loop();
  {

     if( flag1 ==  true )
        {
//        stepper.enableOutputs();
//        Serial.println("1");
//        ESP.wdtFeed();
//        yield();
        ESP.wdtDisable();
        stepper.moveTo(value);
        stepper.runToPosition();
//        yield();
//        ESP.wdtFeed();                       
//        Serial.println("2");
        Serial.println();
        Serial.println("Stop at:");
        delay(100);
        Serial.print(value);
        Serial.println();
        flag1 = false; 
//        stepper.disableOutputs();
//        Serial.println("3");
        ESP.wdtEnable(1000);
        }
  }
}

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: accelstepper and watchdog

Postby ESP_Sprite » Fri Jul 03, 2020 6:47 am

That's on an ESP8266, and as this is an ESP32 forum, I'm not sure you'll get the answer you're looking for, sorry.

wanti00
Posts: 4
Joined: Thu Jul 02, 2020 3:06 pm

Re: accelstepper and watchdog

Postby wanti00 » Sat Jul 04, 2020 8:06 am

Sorry. Esp8266 forum seems dead. So i write he thinking they ara smilar.

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: accelstepper and watchdog

Postby ESP_Sprite » Sat Jul 04, 2020 11:33 am

Suggest trying any support places for Arduino on the ESP8266 then, as you're using that platform.

User avatar
martinayotte
Posts: 141
Joined: Fri Nov 13, 2015 4:27 pm

Re: accelstepper and watchdog

Postby martinayotte » Sun Jul 05, 2020 2:21 pm

The ESP8266 forum is not dead : https://www.esp8266.com/index.php

Who is online

Users browsing this forum: No registered users and 269 guests