<commit_before>/*
 * 31 mar 2015
 * This sketch display UDP packets coming from an UDP client.
 * On a Mac the NC command can be used to send UDP. (nc -u 192.168.1.101 2390).
 *
 * Configuration : Enter the ssid and password of your Wifi AP. Enter the port number your server is listening on.
 *
 */

#include <ESP8266WiFi.h>
#include <WiFiUDP.h>
#include <ArduinoJson.h>

extern "C" {  //required for read Vdd Voltage
#include "user_interface.h"
  // uint16 readvdd33(void);
}

int status = WL_IDLE_STATUS;
const char* ssid = "matrix";  //  your network SSID (name)
const char* pass = "<PASSWORD>";       // your network password

byte packetBuffer[512]; //buffer to hold incoming and outgoing packets

// A UDP instance to let us send and receive packets over UDP
WiFiUDP Udp;
//IPAddress ipMulti(239, 255, 255, 250);
//IPAddress ipMulti(224, 0, 0, 1);
IPAddress ipMulti(239, 0, 0, 57);
unsigned int portMulti = 2525;

const char* serverAddress = "";
bool hasIP = false;
bool multicastServerIsStarted = false;
bool isInitialized = false;
WiFiClient client;


void WiFiEvent(WiFiEvent_t event) {
  Serial.println("");
  Serial.printf("[WiFi-event] event: %d\n", event);

  switch(event) {
    case WIFI_EVENT_STAMODE_GOT_IP:
      Serial.println("WiFi connected");
      hasIP = true;
      break;
    case WIFI_EVENT_STAMODE_DISCONNECTED:
      Serial.println("WiFi lost connection");
      break;
  }
}
void setup()
{
  Serial.begin(115200);

  WiFi.disconnect(true);

  delay(1000);
  WiFi.onEvent(WiFiEvent);
  WiFi.begin(ssid, pass);

  Serial.println();
  Serial.println();
  Serial.println("Wait for WiFi... ");
  Serial.println();
}

void loop()
{
  if (!hasIP) {
    Serial.print(".");
    delay(500);
  } else if (isInitialized) {
    handleLEDs();
  } else if (serverAddress == "") { // has server data received
    if (multicastServerIsStarted) {
      startMulticastServer();
    } else {
      listenForServer();
    }
  } else {
    if (!lightIsRegistered()) {
      registerLight();
    } else {
      isInitialized = true;
    }
  }
}

void startMulticastServer() {
  Serial.println("> startMulticastServer()");<commit_msg>fixed logic issue in esp handler<commit_after>/*
 * 31 mar 2015
 * This sketch display UDP packets coming from an UDP client.
 * On a Mac the NC command can be used to send UDP. (nc -u 192.168.1.101 2390).
 *
 * Configuration : Enter the ssid and password of your Wifi AP. Enter the port number your server is listening on.
 *
 */

#include <ESP8266WiFi.h>
#include <WiFiUDP.h>
#include <ArduinoJson.h>

extern "C" {  //required for read Vdd Voltage
#include "user_interface.h"
  // uint16 readvdd33(void);
}

int status = WL_IDLE_STATUS;
const char* ssid = "matrix";  //  your network SSID (name)
const char* pass = "<PASSWORD>";       // your network password

byte packetBuffer[512]; //buffer to hold incoming and outgoing packets

// A UDP instance to let us send and receive packets over UDP
WiFiUDP Udp;
//IPAddress ipMulti(239, 255, 255, 250);
//IPAddress ipMulti(224, 0, 0, 1);
IPAddress ipMulti(239, 0, 0, 57);
unsigned int portMulti = 2525;

const char* serverAddress = "";
bool hasIP = false;
bool multicastServerIsStarted = false;
bool isInitialized = false;
WiFiClient client;


void WiFiEvent(WiFiEvent_t event) {
  Serial.println("");
  Serial.printf("[WiFi-event] event: %d\n", event);

  switch(event) {
    case WIFI_EVENT_STAMODE_GOT_IP:
      Serial.println("WiFi connected");
      hasIP = true;
      break;
    case WIFI_EVENT_STAMODE_DISCONNECTED:
      Serial.println("WiFi lost connection");
      break;
  }
}
void setup()
{
  Serial.begin(115200);

  WiFi.disconnect(true);

  delay(1000);
  WiFi.onEvent(WiFiEvent);
  WiFi.begin(ssid, pass);

  Serial.println();
  Serial.println();
  Serial.println("Wait for WiFi... ");
  Serial.println();
}

void loop()
{
  if (!hasIP) {
    Serial.print(".");
    delay(500);
  } else if (isInitialized) {
    handleLEDs();
  } else if (serverAddress == "") { // has server data received
    if (!multicastServerIsStarted) {
      startMulticastServer();
    } else {
      listenForServer();
      delay(100);
    }
  } else {
    if (!lightIsRegistered()) {
      registerLight();
    } else {
      isInitialized = true;
    }
  }
}

void startMulticastServer() {
  Serial.println("> startMulticastServer()");
{'fraction_non_alphanumeric': 0.13148148148148148, 'fraction_numerical': 0.03449074074074074, 'mean_word_length': 3.4136874361593463, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5917493', 'n_tokens_mistral': 1600, 'n_tokens_neox': 1471, 'n_words': 423}