<commit_before>#include <ESP8266WiFi.h>
#include <DHT.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"


#define WLAN_SSID  ""
#define WLAN_PASS  ""

#define arduino_pubsub " #1 SUBSCRIPTION"         //
#define arduino_response " #1 RESPONSE"           //
#define arduino_temp "#2 PUBLISH "                //  PUB-SUB
#define arduino_hum "#2 PUBLISH"                  //
#define arduino_watt "#2 PUBLISH"                 //

#define MQTT_SERVER "MQTT"                                            // MQTT Server
#define mqtt_port  1883


void MQTT_connect();
/************ Global State (you don't need to change this!) ******************/
WiFiClient client;
DHT dht(2  , DHT11, 15);


int doReset =0;
const char* host = "";
String urlon = "STRING FOR ON";
String urloff = "STRING FOR OFF";
long previousMillis = 0;
long interval = 60000*5;   // 5 minutes delay
boolean gotMessage = false;
char c;

// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, mqtt_port );
/****************************** Feeds ***************************************/
Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, arduino_pubsub, 1);
/*************************** Sketch Code ************************************/


void setup() {
  Serial.begin(115200);
  delay(10);
  dht.begin();                                            // Humidity-Temp Sensor
  WiFi.begin(WLAN_SSID, WLAN_PASS);                       // Start wifi
  while (WiFi.status() != WL_CONNECTED) {                 // Connect
    delay(500);
  }
  // Setup MQTT subscription for onoff & slider feed.
  mqtt.subscribe(&onoffbutton);                           // Subscription #1
  //mqtt.subscribe(&statusreport);                        // Subscription #2
}


// LOOP ----------------
void loop() {

  if (!mqtt.connected()) {                                // connect to broker
    MQTT_connect();
  }

  Adafruit_MQTT_Subscribe *subscription;                  // Subscribe again

  while ((subscription = mqtt.readSubscription(3000))) {  // if message arrived
    if (subscription == &onoffbutton) {
      if (strcmp((char *)onoffbutton.lastread, "connect") == 0) {
        mqtt.publish(arduino_response, "connected", 1);
        iscon(5);
      } else if (strcmp((char *)onoffbutton.lastread, "disconnect") == 0) {
      } else if (strcmp((char *)onoffbutton.lastread, "AC1") == 0) {
        Serial.print("AC1");
        delay(50);
        calcWatt(1);
      } else if (strcmp((char *)onoffbutton.lastread, "AC0") == 0) {
        Serial.print("AC0");
        delay(50);
        calcWatt(0);
      } else if (!(strcmp((char *)onoffbutton.lastread, "done") == 0)) {
        Serial.print((char *)onoffbutton.lastread);
        mqtt.publish(arduino_response, "done", 1);
      }
    }
  }

 A change
  // ping the server to keep the mqtt connection alive
  if (! mqtt.ping()) {
    mqtt.disconnect();
  }

  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis > interval) {
    Serial.println("Success");
    previousMillis = currentMillis;
    calcWatt(4);
    if(doReset>=50){
        doReset=0;
        Serial.println("Reset");
    }
  }
}




void iscon(int mode) {
  float h = dht.readHumidity();
  char hum[1];<commit_msg>Latest<commit_after>#include <ESP8266WiFi.h>
#include <DHT.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"


#define WLAN_SSID  ""
#define WLAN_PASS  ""

#define arduino_pubsub " #1 SUBSCRIPTION"         //
#define arduino_response " #1 RESPONSE"           //
#define arduino_temp "#2 PUBLISH "                //  PUB-SUB
#define arduino_hum "#2 PUBLISH"                  //
#define arduino_watt "#2 PUBLISH"                 //

#define MQTT_SERVER "MQTT"                                            // MQTT Server
#define mqtt_port  1883


void MQTT_connect();
/************ Global State (you don't need to change this!) ******************/
WiFiClient client;
DHT dht(2  , DHT11, 15);


int doReset =0;
const char* host = "";
String urlon = "STRING FOR ON";
String urloff = "STRING FOR OFF";
long previousMillis = 0;
long interval = 60000*5;   // 5 minutes delay
boolean gotMessage = false;
char c;

// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, mqtt_port );
/****************************** Feeds ***************************************/
Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, arduino_pubsub, 1);
/*************************** Sketch Code ************************************/


void setup() {
  Serial.begin(115200);
  delay(10);
  dht.begin();                                            // Humidity-Temp Sensor
  WiFi.begin(WLAN_SSID, WLAN_PASS);                       // Start wifi
  while (WiFi.status() != WL_CONNECTED) {                 // Connect
    delay(500);
  }
  // Setup MQTT subscription for onoff & slider feed.
  mqtt.subscribe(&onoffbutton);                           // Subscription #1
  //mqtt.subscribe(&statusreport);                        // Subscription #2
}


// LOOP ----------------
void loop() {

  if (!mqtt.connected()) {                                // connect to broker
    MQTT_connect();
  }

  Adafruit_MQTT_Subscribe *subscription;                  // Subscribe again

  while ((subscription = mqtt.readSubscription(3000))) {  // if message arrived
    if (subscription == &onoffbutton) {
      if (strcmp((char *)onoffbutton.lastread, "connect") == 0) {
        mqtt.publish(arduino_response, "connected", 1);
        iscon(5);
      } else if (strcmp((char *)onoffbutton.lastread, "disconnect") == 0) {
      } else if (strcmp((char *)onoffbutton.lastread, "AC1") == 0) {
        Serial.print("AC1");
        delay(50);
        calcWatt(1);
      } else if (strcmp((char *)onoffbutton.lastread, "AC0") == 0) {
        Serial.print("AC0");
        delay(50);
        calcWatt(0);
      } else if (!(strcmp((char *)onoffbutton.lastread, "done") == 0)) {
        Serial.print((char *)onoffbutton.lastread);
        mqtt.publish(arduino_response, "done", 1);
      }
    }
  }

  // ping the server to keep the mqtt connection alive
  if (! mqtt.ping()) {
    mqtt.disconnect();
  }

  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis > interval) {
    Serial.println("Success");
    previousMillis = currentMillis;
    calcWatt(4);
    if(doReset>=50){
        doReset=0;
        Serial.println("Reset");
    }
  }
}




void iscon(int mode) {
  float h = dht.readHumidity();
  char hum[1];
{'fraction_non_alphanumeric': 0.17898715041572186, 'fraction_numerical': 0.02055933484504913, 'mean_word_length': 2.449426485922836, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2676734', 'n_tokens_mistral': 2231, 'n_tokens_neox': 2058, 'n_words': 493}