<commit_before>
#define DEBUG_MODE

#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include <MqttWrapper.h>
#include <PubSubClient.h>
#include <DHT.h>
#include "dht_helper.h"

// const char* ssid     = "OpenWrt_NAT_500GP.101";
// const char* pass = "<PASSWORD>";

// const char* ssid     = "MAKERCLUB-CM";
// const char* pass = "<PASSWORD>";

// const char* ssid     = "Opendream Play";
// const char* pass = "<PASSWORD>',<PASSWORD>";

const char* ssid     = "Opendream";
const char* pass = "<PASSWORD>!!!!";



#define WIFI_MAX_RETRIES 1500
#define WIFI_CONNECT_DELAY_MS 20



MqttWrapper *mqtt;
DHT *dht;

void init_dht(DHT **dht, uint8_t pin, uint8_t dht_type);
void read_dht(DHT *dht, float *temp, float *humid);


void callback(const MQTT::Publish& pub) {
    if (pub.payload_string() == "0") {
        Serial.print(" => ");
        Serial.println(pub.payload_string());
    }
    else if(pub.payload_string() == "1") {
        Serial.print(" => ");
        Serial.println(pub.payload_string());
    }
    else {
        Serial.print(pub.topic());
        Serial.print(" => ");
        Serial.println(pub.payload_string());
    }
}

void connect_wifi()
{
    WiFi.begin(ssid, pass);

    int retries = 0;
    while ((WiFi.status() != WL_CONNECTED))
    {
        Serial.print(".");
        retries++;
        delay(500);
    }

    Serial.println("WIFI CONNECTED ");
}

void hook_before_publish(JsonObject** root) {
  JsonObject& data = (*(*root))["d"];

  static float t_dht;
  static float h_dht; 

  read_dht(dht, &t_dht, &h_dht);

  data["myName"] = "NAT";
  data["temp"] = t_dht;
  data["humid"] = h_dht;
}

void setup() {
    Serial.begin(115200);
    delay(10);

    init_dht(&dht, DHTPIN, DHTTYPE);

    connect_wifi();

    mqtt = new MqttWrapper("172.16.58.3");
    mqtt->connect(callback);
    mqtt->set_prepare_publish_data_hook(hook_before_publish, 5000);
}

void loop() {
    mqtt->loop();

    if (millis() % 12000 == 0) {
        mqtt->sync_pub(String("0"));
    }
}<commit_msg>Change order.<commit_after>
#define DEBUG_MODE

#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include <MqttWrapper.h>
#include <PubSubClient.h>
#include <DHT.h>
#include "dht_helper.h"

// const char* ssid     = "OpenWrt_NAT_500GP.101";
// const char* pass = "<PASSWORD>";

// const char* ssid     = "MAKERCLUB-CM";
// const char* pass = "<PASSWORD>";

// const char* ssid     = "Opendream Play";
// const char* pass = "<PASSWORD>',<PASSWORD>";

const char* ssid     = "Opendream";
const char* pass = "<PASSWORD>!!!!";



#define WIFI_MAX_RETRIES 1500
#define WIFI_CONNECT_DELAY_MS 20



MqttWrapper *mqtt;
DHT *dht;



void connect_wifi()
{
    WiFi.begin(ssid, pass);

    int retries = 0;
    while ((WiFi.status() != WL_CONNECTED))
    {
        Serial.print(".");
        retries++;
        delay(500);
    }

    Serial.println("WIFI CONNECTED ");
}

void callback(const MQTT::Publish& pub) {
    if (pub.payload_string() == "0") {
        Serial.print(" => ");
        Serial.println(pub.payload_string());
    }
    else if(pub.payload_string() == "1") {
        Serial.print(" => ");
        Serial.println(pub.payload_string());
    }
    else {
        Serial.print(pub.topic());
        Serial.print(" => ");
        Serial.println(pub.payload_string());
    }
}

void hook_before_publish(JsonObject** root) {
  JsonObject& data = (*(*root))["d"];

  static float t_dht;
  static float h_dht; 

  read_dht(dht, &t_dht, &h_dht);

  data["myName"] = "NAT";
  data["temp"] = t_dht;
  data["humid"] = h_dht;
}

void setup() {
    Serial.begin(115200);
    pinMode(0, INPUT_PULLUP);
    delay(10);

    connect_wifi();
    init_dht(&dht, DHTPIN, DHTTYPE);

    mqtt = new MqttWrapper("172.16.58.3");
    mqtt->connect(callback);
    mqtt->set_prepare_publish_data_hook(hook_before_publish, 5000);
}

void loop() {
    mqtt->loop();

    if (digitalRead(0) == LOW) {
        while(digitalRead(0) == LOW) { 
            mqtt->loop();
            yield(); 
        }
        mqtt->sync_pub(String("0"));
    }

}
{'fraction_non_alphanumeric': 0.17921948794432016, 'fraction_numerical': 0.02411135968182948, 'mean_word_length': 3.01998001998002, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 38, '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': '4221119', 'n_tokens_mistral': 1632, 'n_tokens_neox': 1528, 'n_words': 288}