<commit_before>#include <ESPert.h>

ESPert espert;

//IPAddress mqtt_server(192,168,77,1);
const char* mqtt_server = "mqtt.espert.io";

unsigned long loopTime = 0;

int currentSwitch = true;
String outTopic = "ESPert/" + String(espert.info.getChipId()) + "/Status";

String inTopic = "ESPert/" + String(espert.info.getChipId()) + "/Command";;

int currentSwitch2 = true;
ESPert_Button button2;

const char *host = "maker.ifttt.com";
const int httpPort = 80;

String ifttt_key;

void callback(char* topic, byte* payload, unsigned int length) {
  byte* p = (byte*)malloc(length+1);
  // Copy the payload to the new buffer
  memcpy(p,payload,length);
  p[length] = 0;
  String strPayload = String((char *)p);
  free(p);
  
  espert.println("Receive: " + strPayload);
  if (espert.json.init(strPayload) && espert.json.containsKey("LED")) {
  
    String value = espert.json.get("LED");

    if (value == "0") {
      espert.led.off();
      espert.println("LED: Off");
    } else if (value == "1") {
      espert.led.on();
      espert.println("LED: On");
    } else if (value == "2") {
      if( espert.led.isOn() ) {
        espert.led.off();
        espert.println("LED (Toglle): off");
      }
      else {
        espert.led.on();
        espert.println("LED (Toglle): On");
      }
    }

    String outString  = "{\"LED\":\"" + String(espert.led.isOn() ? 1 : 0) + "\", ";
    outString += "\"name\":\"" + String(espert.info.getId()) + "\"}";
    espert.println("Send...: " + outString);
    espert.mqtt.publish(outTopic, outString);
  }
  if (espert.json.init(strPayload) && espert.json.containsKey("Buzzer")) {
  
    String value = espert.json.get("Buzzer");
    int l = value.toInt();
    for( int i=0; i<l; i++ ) {
      delay( 200 );
      espert.buzzer.beep( 60, 200 );
    }
  }
  if (espert.json.init(strPayload) && espert.json.containsKey("OLED")) {
  
    String value = espert.json.get("OLED");
    espert.oled.clear();
    espert.oled.println(value);

  }
  if (espert.json.init(strPayload) && espert.json.containsKey("IFTTT")) {
  
    String value = espert.json.get("IFTTT");
    ifttt_key = value;
    espert.eeprom.write( 200, ifttt_key );
  }
}

void setup() {
  espert.init();
  delay( 100 );
  espert.buzzer.init( 15 );
  espert.dht.init();
  espert.mqtt.init(mqtt_server, 1883, callback);

  ifttt_key = espert.eeprom.read( 200, 32 );

  button2.init( 0 );

  espert.oled.init();
  delay(2000);

  espert.println("Press USER button to turn on LED.");

  espert.oled.clear();
  espert.oled.println(espert.info.getId());
  espert.oled.println();
<commit_msg>IFTT name length<commit_after>#include <ESPert.h>

ESPert espert;

//IPAddress mqtt_server(192,168,77,1);
const char* mqtt_server = "mqtt.espert.io";

unsigned long loopTime = 0;

int currentSwitch = true;
String outTopic = "ESPert/" + String(espert.info.getChipId()) + "/Status";

String inTopic = "ESPert/" + String(espert.info.getChipId()) + "/Command";;

int currentSwitch2 = true;
ESPert_Button button2;

const char *host = "maker.ifttt.com";
const int httpPort = 80;

String ifttt_key;

void callback(char* topic, byte* payload, unsigned int length) {
  byte* p = (byte*)malloc(length+1);
  // Copy the payload to the new buffer
  memcpy(p,payload,length);
  p[length] = 0;
  String strPayload = String((char *)p);
  free(p);
  
  espert.println("Receive: " + strPayload);
  if (espert.json.init(strPayload) && espert.json.containsKey("LED")) {
  
    String value = espert.json.get("LED");

    if (value == "0") {
      espert.led.off();
      espert.println("LED: Off");
    } else if (value == "1") {
      espert.led.on();
      espert.println("LED: On");
    } else if (value == "2") {
      if( espert.led.isOn() ) {
        espert.led.off();
        espert.println("LED (Toglle): off");
      }
      else {
        espert.led.on();
        espert.println("LED (Toglle): On");
      }
    }

    String outString  = "{\"LED\":\"" + String(espert.led.isOn() ? 1 : 0) + "\", ";
    outString += "\"name\":\"" + String(espert.info.getId()) + "\"}";
    espert.println("Send...: " + outString);
    espert.mqtt.publish(outTopic, outString);
  }
  if (espert.json.init(strPayload) && espert.json.containsKey("Buzzer")) {
  
    String value = espert.json.get("Buzzer");
    int l = value.toInt();
    for( int i=0; i<l; i++ ) {
      delay( 200 );
      espert.buzzer.beep( 60, 200 );
    }
  }
  if (espert.json.init(strPayload) && espert.json.containsKey("OLED")) {
  
    String value = espert.json.get("OLED");
    espert.oled.clear();
    espert.oled.println(value);

  }
  if (espert.json.init(strPayload) && espert.json.containsKey("IFTTT")) {
  
    String value = espert.json.get("IFTTT");
    ifttt_key = value;
    espert.eeprom.write( 150, ifttt_key );
  }
}

void setup() {
  espert.init();
  delay( 100 );
  espert.buzzer.init( 15 );
  espert.dht.init();
  espert.mqtt.init(mqtt_server, 1883, callback);

  ifttt_key = espert.eeprom.read( 150, 80 );

  button2.init( 0 );

  espert.oled.init();
  delay(2000);

  espert.println("Press USER button to turn on LED.");

  espert.oled.clear();
  espert.oled.println(espert.info.getId());
  espert.oled.println();

{'fraction_non_alphanumeric': 0.1875605502809533, 'fraction_numerical': 0.020538655299360588, 'mean_word_length': 3.1262989608313347, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '7484097', 'n_tokens_mistral': 2056, 'n_tokens_neox': 1951, 'n_words': 370}