I can't solve this error in verification mode

Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: “NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200”

sketch_apr30a:36:1: error: stray ‘\200’ in program

sketch_apr30a:36:1: error: stray ‘\213’ in program

sketch_apr30a:51:1: error: stray ‘\342’ in program

^

sketch_apr30a:51:1: error: stray ‘\200’ in program

sketch_apr30a:51:1: error: stray ‘\213’ in program

sketch_apr30a:55:1: error: stray ‘\342’ in program

^

sketch_apr30a:55:1: error: stray ‘\200’ in program

sketch_apr30a:55:1: error: stray ‘\213’ in program

sketch_apr30a:60:1: error: stray ‘\342’ in program

sketch_apr30a:80:1: error: stray ‘\200’ in program

sketch_apr30a:80:1: error: stray ‘\213’ in program

exit status 1

stray ‘\342’ in program

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

There are Unicode characters in your code. This typically occurs when code is copied from a Web page

Please post your code here for examination

Please follow the advice given in the link below when posting code

Copy your sketch to a simple text editor to remove unwanted hidden characters.

#include <ESP8266WiFi.h>
​
#include <PubSubClient.h>
​
#include "DHT.h"
​
#define DHTPIN D4     // what pin we're connected to
#define wifi_ssid "xxxxx"
#define wifi_password "xxxxx"
​
#define mqtt_server "broker-internet-facing-f1429d8cb54ca4a7.elb.us-east-1.amazonaws.com"  // MQTT Cloud address
#define humidity_topic "humidity"
#define temperature_topic "temperature"
​
#define DHTTYPE DHT11   // DHT 11
​
WiFiClient espClient;
PubSubClient client(espClient);
DHT dht(DHTPIN, DHTTYPE);
​
void setup() {
    Serial.begin(115200);
    setup_wifi();
    client.setServer(mqtt_server, 1883);
    dht.begin();
}
​
void setup_wifi() {
    delay(10);
    WiFi.begin(wifi_ssid, wifi_password);
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }
}
​
void reconnect() {
    // Loop until we're reconnected
    while (!client.connected()) {
        Serial.print("Attempting MQTT connection...");
        if (client.connect("nodeMcuDHT11")) {
            Serial.println("connected");
        } else {
            Serial.print("failed, rc=");
            Serial.print(client.state());
            Serial.println(" try again in 5 seconds");
            delay(5000);
        }
    }
}
​
bool checkBound(float newValue, float prevValue, float maxDiff) {
    return newValue < prevValue - maxDiff || newValue > prevValue + maxDiff;
}
​
long lastMsg = 0;
float temp = 0.0;
float hum = 0.0;
float diff = 1.0;
​
void loop() {
    if (!client.connected()) {
        reconnect();
    }
    client.loop();
​
    long now = millis();
    if (now - lastMsg > 30000) {
        // Wait a few seconds between measurements
        lastMsg = now;
​
        float newTemp = dht.readTemperature();
        float newHum = dht.readHumidity();
        if (checkBound(newTemp, temp, diff)) {
            temp = newTemp;
            Serial.print("New temperature:");
            Serial.println(String(temp).c_str());
            client.publish(temperature_topic, String(temp).c_str(), true);
        }
​
        if (checkBound(newHum, hum, diff)) {
            hum = newHum;
            Serial.print("New humidity:");
            Serial.println(String(hum).c_str());
            client.publish(humidity_topic, String(hum).c_str(), true);
        }
    }
}

(Code tags added by Moderator, please use the </> button on the menu next time.)

Use the Copy button now, and see if the extraneous characters are gone.

1 Like

you mean to write "</> "at the beginning of the copied code and the problem will be solve

Here is the code with the stray Unicode characters removed

#include <ESP8266WiFi.h>
 
#include <PubSubClient.h>
 
#include "DHT.h"
 
#define DHTPIN D4     // what pin we're connected to
#define wifi_ssid "xxxxx"
#define wifi_password "xxxxx"
 
#define mqtt_server "broker-internet-facing-f1429d8cb54ca4a7.elb.us-east-1.amazonaws.com"  // MQTT Cloud address
#define humidity_topic "humidity"
#define temperature_topic "temperature"
 
#define DHTTYPE DHT11   // DHT 11
 
WiFiClient espClient;
PubSubClient client(espClient);
DHT dht(DHTPIN, DHTTYPE);
 
void setup() {
    Serial.begin(115200);
    setup_wifi();
    client.setServer(mqtt_server, 1883);
    dht.begin();
}
 
void setup_wifi() {
    delay(10);
    WiFi.begin(wifi_ssid, wifi_password);
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }
}
 
void reconnect() {
    // Loop until we're reconnected
    while (!client.connected()) {
        Serial.print("Attempting MQTT connection...");
        if (client.connect("nodeMcuDHT11")) {
            Serial.println("connected");
        } else {
            Serial.print("failed, rc=");
            Serial.print(client.state());
            Serial.println(" try again in 5 seconds");
            delay(5000);
        }
    }
}
 
bool checkBound(float newValue, float prevValue, float maxDiff) {
    return newValue < prevValue - maxDiff || newValue > prevValue + maxDiff;
}
 
long lastMsg = 0;
float temp = 0.0;
float hum = 0.0;
float diff = 1.0;
 
void loop() {
    if (!client.connected()) {
        reconnect();
    }
    client.loop();
 
    long now = millis();
    if (now - lastMsg > 30000) {
        // Wait a few seconds between measurements
        lastMsg = now;
 
        float newTemp = dht.readTemperature();
        float newHum = dht.readHumidity();
        if (checkBound(newTemp, temp, diff)) {
            temp = newTemp;
            Serial.print("New temperature:");
            Serial.println(String(temp).c_str());
            client.publish(temperature_topic, String(temp).c_str(), true);
        }
 
        if (checkBound(newHum, hum, diff)) {
            hum = newHum;
            Serial.print("New humidity:");
            Serial.println(String(hum).c_str());
            client.publish(humidity_topic, String(hum).c_str(), true);
        }
    }
}

thanks a lot it worked now .