ArtnetWifi icon indicating copy to clipboard operation
ArtnetWifi copied to clipboard

artnet stopping

Open Protezhe opened this issue 6 years ago • 1 comments

Hi. I have a problem using this sceetch:

/*
This example will transmit a universe via Art-Net into the `Network.
  This example may be copied under the terms of the MIT license, see the LICENSE file for details
*/

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <ArtnetWifi.h>
#include <MIDI.h>

float britnes = 0;
int cha = 0;
float britnesm[520];



int i;



unsigned long currentMillis;
unsigned long previousMillis;

//Wifi settings
const char* ssid = "louna"; // CHANGE FOR YOUR SETUP
const char* password = "woolstreet"; // CHANGE FOR YOUR SETUP

MIDI_CREATE_DEFAULT_INSTANCE();

// Artnet settings
ArtnetWifi artnet;

const int startUniverse = 2;
const char host[] = "192.168.0.255";


// connect to wifi – returns true if successful or false if not
boolean ConnectWifi(void)
{
  boolean state = true;
  int i = 0;

  WiFi.begin(ssid, password);
  //Serial.println("");
  //Serial.println("Connecting to WiFi");

  // Wait for connection
  //Serial.print("Connecting");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    //Serial.print(".");
    if (i > 20) {
      state = false;
      break;
    }
    i++;
  }
  if (state) {
    // Serial.println("");
    //Serial.print("Connected to ");
    //Serial.println(ssid);
    //Serial.print("IP address: ");
    //Serial.println(WiFi.localIP());
  } else {
    //Serial.println("");
    //Serial.println("Connection failed.");
    digitalWrite(12,LOW);
  }

  return state;
}

void setup()
{
 
   pinMode(12, OUTPUT);
 digitalWrite(12,HIGH);


  //Serial.begin(115200);
  ConnectWifi();
  artnet.begin(host);
  artnet.setLength(512);
  artnet.setUniverse(startUniverse);

  MIDI.begin(MIDI_CHANNEL_OMNI);
  MIDI.setHandleControlChange(MyHandleNoteOn);


 
}
  


void loop()
{

  currentMillis = millis();

  if (currentMillis - previousMillis >= 5000) {

    previousMillis = currentMillis;


    for (i = 0; i <= 511; i++) {

     
      artnet.setByte(i, britnesm[i]);

      artnet.write();
    }
    }
    
  MIDI.read();
  
  if (WiFi.status() == 6) {
  digitalWrite(12,LOW);
 }
 
  yield();

}

void MyHandleNoteOn(byte channel, byte number, byte value) {

  if (channel = 1) {

    cha = number - 1;
    britnes = value * (255.0 / 127.0);
   

    artnet.setByte(cha, britnes);

   artnet.write();
  
 
britnesm[cha] = britnes;

  }

  }

When ESP 07 working for 1 - 12 hours artnet sending stoped. Wifi connection is good. But artnet don't send something (And artnet node is not show in net)

When i add this code problem is out. But it's not good to begin host every loop:

yield();

  artnet.begin(host);
  artnet.setLength(512);
  artnet.setUniverse(startUniverse);

}

Protezhe avatar Apr 11 '18 22:04 Protezhe

Sorry for the late reply, I am a bit busy.

First guess, your WiFi connection is not stable enough. The ESP is reconnecting and all open connections are closed. This would explains why artnet.begin(host) is working.

Try something like this:

At the beginning of the file

// Artnet settings
ArtnetWifi artnet;
int status = WL_IDLE_STATUS;
int status_old = status;

In loop(), maybe at the end

status = WiFi.status();
if (status != status_old && status == WL_CONNECTED) {
  artnet.begin(host);
}
status_old = status;

This will start the ArtNet communication only if status changes to CONNECTED and not all the time.

rstephan avatar Apr 21 '18 19:04 rstephan