Stray '\302' in program, i just want to use the website to clean the code

// includes the dht library
#include "DHT.h"

// The librarys for the Time stamp
#include "RTClib.h"
#include "time.h"
#include <sys/time.h>

// The Librarys for the Internet connection
#include <WiFi.h>
#include <PubSubClient.h>

// the Time zone tells the Ds3231 what time its looking for
#define TIMEZONE "CET-1CEST,M3.5.0/02,M10.5.0/03"

// information for the DHT22
#define DHTPIN 4 // Digital pin Anschluss DHT sensor
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321

RTC_DS3231 rtc;
struct tm tdata;// lokale Zeitconstchar*

// WLAN
const char *ssid = "";
const char *password = "";

// MQTT Server
const char* mqttServer = "";
const int mqttPort = 1883;
const char* mqttUser = "";
const char* mqttPassword = "";
//MQTT Topics
WiFiClient espClient;
PubSubClient client(espClient);

int counter = 0;// Counter # runs
String jsonify;
DHT dht (DHTPIN, DHTTYPE);
void setup(){
  Serial.begin(115200);

  // start of the wifi searching
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print("\nConnecting to WiFi");
    for (int i = 0; i < 3; i++) {
      Serial.print(" .");
      delay(100);
    }
    delay(3000);
  }
  Serial.println(F("Connected to the WiFi network + DHT start!"));// MQTT Connection
  client.setServer(mqttServer, mqttPort);
  while (!client.connected()) {
    Serial.println("Connecting to MQTT");
    if (client.connect("ESP32Client", mqttUser, mqttPassword )) {
      Serial.println("Connected!");

    }
    else {
      Serial.print("failed with state ");
      Serial.print(client.state() + " ");
      delay(2000);
    }
  }
  // configure of time
  DateTime now;
  timeval tv;
  int rc;
  delay(500);// waiting for Ser. Port  
  if (! rtc.begin()) {
    Serial.println("Keine Echtzeituhr gefunden!");
    while (1);
  }
  now = rtc.now();
  tv.tv_sec = now.unixtime();
  tv.tv_usec = 0;// sets no Microseconds
  rc = settimeofday(&tv, NULL);   // NULL = no time zone settings
  setenv("TZ", TIMEZONE, 1); // here: time zone settings
  Serial.printf("Returncode beim Setzen der Systemzeit nach der RTC: %d\n\n", rc);
  dht.begin();
  Serial.println(F("DHTxx test!"));
}
// a forever loop
void loop() {
  //Connection watcher/controller
  if (!client.connected()) {
    Serial.println("Lost connection");
    while (!client.connected()) {
      Serial.println("Reconect...");
      if (client.connect("Client")) {
        Serial.println("Connected!");
        client.subscribe("weather/temperatur");
        client.subscribe("weather/humidity");
      }
      else {
        Serial.print("Failed with state");
        Serial.println(client.state());
        delay(3000);
      }
    }
  }
  client.loop();
  DateTime now = rtc.now();
  delay(3000); // waits 3 Seconds
  counter++; // counting
  float h = dht.readHumidity(); // reads value of DHT22
  float t = dht.readTemperature(); // reads value of DHT22 (celsiuse)
  float f = dht.readTemperature(true); // reads value of DHT22 (farenheit)
  if (isnan(h) || isnan(t) || isnan(f)) {   // if all values are NULL
    jsonify = "{ Error: \"Failed reading DHT sensor!\", TIME: \"" + (String)now.month() + ";" + (String)now.day() + "," + (String)now.hour() + ":" + (String)now.minute() + "." + (String)now.second() + "\", ID: \"Ryad_Mohamed\" }";
  }
  else {
    jsonify = ("{ temperatureDegree: " + (String)t + ", temperatureFahrenheit: " + (String)f + ", humidity: " + (String)h + ", count: " + (String)DEC + ", TIME: \"" + (String)now.month() + ";" + (String)now.day() + "," + (String)now.hour() + ":" + (String)now.minute() + "." + (String)now.second() + "\", ID: \"Ryad_Mohamed\" }");
  }// publisches all data with MQTT
  client.publish("test", (char*)jsonify.c_str());
  Serial.println(jsonify);
}

So you decide to contribute to climate change by making an irrelevant post here just to remove the stray characters rather than look at the line the compiler was pointing at?

Or do you have a real question??

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.