Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By Mario Mikočević
#23236 Heya,

did some testing with -
Code: Select allvoid loop() {
  if ( WiFi.status() == WL_CONNECTED ) {
    server.handleClient();
    counter++;
    if ( ( counter % 1000000 ) == 0 ) { // around 10 sec
      ElapsedStr( tmpstr ); // form str with hh:mm:ss
      Serial.println( tmpstr );
    }
    if ( ( counter % 500000000 ) == 0 ) { //around 1h30min
      Serial.println("Restarting ESP");
      ESP.restart();
    }
  } else {
    Serial.println("Disconnected");
    delay(2000);
  }
}


If I regularly visit web page in periods shorter than 10mins I can always get a proper http response (and handle_root() executed), but after around 10min of *inactivity* http part stops responding.
Serial printing do keeps running until predefined ESP.restart(). All that with NeoPixel code removed and strip disconnected.
Next step is trying /staging/ code from github ..

--
Mozz
User avatar
By SwiCago
#23237 Enable debugging in ESP8266WebServer.cpp
#define DEBUG //uncomment this line, I believe it is line 26
#define DEBUG_OUTPUT Serial

Maybe this will show what is going on with the webserver
User avatar
By folny82
#23239 Hi

Error is not on the server side, I think I have the sketch on which web server is not running and random restart is still going on.

Code: Select all#include <Artnet.h>
#include <ESP8266WiFi.h>
#include "WiFiUdp.h"
#include <SPI.h>
#include <NeoPixelBus.h>

// Neopixel settings
const int numLeds = 512; // change for your setup
const int numberOfChannels = numLeds * 3; // Total number of channels you want to receive (1 led = 3 channels)
const byte dataPin = 2;
NeoPixelBus leds = NeoPixelBus(numLeds, dataPin, NEO_GRB + NEO_KHZ800);

// Artnet settings
Artnet artnet;
const int startUniverse = 0; // CHANGE FOR YOUR SETUP most software this is 1, some software send out artnet first universe as 0.

// Check if we got all universes
const int maxUniverses = numberOfChannels / 512 + ((numberOfChannels % 512) ? 1 : 0);
bool universesReceived[maxUniverses];
bool sendFrame = 1;
int previousDataLength = 0;

// Change ip and mac address for your setup
uint8_t ip[] = {192, 168, 2, 100};
uint8_t gw[] = {192, 168, 2, 2};
uint8_t mask[] = {255, 255, 255, 0};
uint8_t mac[] = {0x04, 0xE9, 0xE5, 0x00, 0x69, 0xEC};

void setup()
{
  WiFi.config(ip, gw, mask);
  artnet.begin(mac, ip);
  leds.Begin();

// this will be called for each packet received
  artnet.setArtDmxCallback(onDmxFrame);
}

void loop()
{
  // we call the read function inside the loop
  artnet.read();
}

void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data)
{
  sendFrame = 1;
  // set brightness of the whole strip
  if (universe == 15)
  {
        leds.Show();
  }
  // Store which universe has got in
  if ((universe - startUniverse) < maxUniverses)
    universesReceived[universe - startUniverse] = 1;

  for (int i = 0 ; i < maxUniverses ; i++)
  {
    if (universesReceived[i] == 0)
    {
      sendFrame = 0;
      break;
    }
  }
  // read universe and put into the right part of the display buffer
  for (int i = 0; i < length / 3; i++)
  {
    int led = i + (universe - startUniverse) * (previousDataLength / 3);
    if (led < numLeds)
      leds.SetPixelColor(led, data[i * 3], data[i * 3 + 1], data[i * 3 + 2]);
  }
  previousDataLength = length;     
 
  if (sendFrame)
  {
    leds.Show();
    // Reset universeReceived to 0
    memset(universesReceived, 0, maxUniverses);
  }
}