0

I have been trying to create a temperature/humidity logger using one of these ESP8266-based dev-kits. I wrote a simple sketch that sends a request to a (working) web server, using GET for simplicity.

Below is the sketch:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <DHTesp.h>

#define ssid "ssid"
#define password "password"


  #define DEVICE_ID 1

DHTesp dht;

void setup() {
  Serial.begin(115200);
  Serial.println("Debug");
  dht.setup(4);
}

void loop() {

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  HTTPClient http;

  float temperature = dht.getTemperature();
  float humidity = dht.getHumidity();

  Serial.println("Measured");

  while (WiFi.status() != WL_CONNECTED) {delay(10);}

  Serial.println("Connected");

  char str_temp[10] = {'-'};
  char str_temp2[10] = {'-'};
  Serial.println(humidity);

  dtostrf(temperature, 2, 2, str_temp);
  dtostrf(humidity, 2, 0, str_temp2);

  char query[400];
  Serial.println(str_temp);

  sprintf(query, "http://192.168.1.198/temp.php?device=%d&temperature=%s&humidity=%s", DEVICE_ID, str_temp, str_temp2);
  Serial.println(query);
  http.begin(query);

  int httpCode = http.GET();

  if (httpCode > 0) {
    Serial.printf("[HTTP] GET... code: %d\n", httpCode);

    if (httpCode == HTTP_CODE_OK) {
      String payload = http.getString();
      Serial.println(payload);
    }
  } else {
    Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
  }

  http.end();
  ESP.deepSleep(60e6);
}

Here is a brief explanation:

When the module powers up, it gets the data from a DHT22 sensor, and sends it to the server. It then goes to sleep for 10 minutes and resets. (D0 and RST are connected)

For some reason, nothing seems to work correctly, I don't even get the first Debug print. BAUD rate is 115200, and this is the Serial output:

1384, room 16
tail 8
chksum sd$⸮⸮|⸮l⸮| ⸮ $⸮c<ǃ⸮⸮{⸮c⸮ #⸮⸮no⸮$g'⸮⸮⸮cp⸮⸮dsd;lx⸮o⸮ ⸮ d ⸮⸮ co⸮|l⸮ ⸮c⸮⸮gn⸮dćd⸮ogl n{⸮⸮⸮g ⸮⸮ s⸮⸮' ⸮⸮sۓnl⸮|⸮⸮ ⸮{⸮o⸮#⸮o#x⸮sd$⸮⸮|⸮l⸮| ⸮$⸮c|ǃ⸮⸮{⸮c⸮ b⸮⸮ng⸮$gn⸮⸮⸮cp⸮⸮dsdrd8⸮o⸮ ⸮ $ ⸮⸮ #g⸮|l⸮ ⸮c⸮⸮'o⸮d⸮⸮d⸮g'lo;⸮⸮⸮g ⸮⸮s⸮⸮' ⸮⸮{ۓol⸮|⸮⸮⸮{⸮⸮o⸮#⸮g#x⸮sdlܟ<⸮l⸮< ⸮l⸮c|⸮⸮⸮⸮{⸮c⸮ b⸮⸮og⸮lgn⸮⸮⸮cp⸮⸮dsdsd8⸮g⸮ ⸮$ ⸮⸮ #g⸮|d⸮ ⸮c⸮⸮'o⸮d⸮⸮$⸮g' lo;Ǜ⸮' ⸮⸮s⸮⸮n ⸮⸮{⸮⸮ol⸮|⸮⸮⸮;⸮⸮g⸮b⸮gbx⸮{ll⸮⸮|⸮d⸮| ⸮l⸮ c|⸮⸮⸮⸮r⸮c⸮c⸮⸮g'⸮lno⸮⸮⸮ b8x⸮⸮l{l{${ll⸮⸮|⸮d⸮| ⸮ l⸮ #|⸮⸮⸮⸮r⸮#⸮c⸮⸮gn⸮log⸮⸮⸮ bx⸮⸮l;l{$p⸮'⸮ ⸮l⸮⸮ c n⸮|$⸮ ⸮b⸮⸮og⸮l⸮⸮l ⸮no $gs⸮ۓo ⸮⸮;⸮⸮o⸮⸮⸮r⸮⸮gd⸮|⸮⸮⸮s⸮⸮'⸮c⸮ncp⸮

Where the random code inserts are just characters and nothing special.

9
  • 1
    I have a Wemos D1 mini, which uses the ESP8266. I ran your code and it works fine. The ESP outputs some debug information (that is, the 1384, room 16, tail 8, etc.) before it starts executing the user code. For my hardware, the ESP's native debug output is at 74880 baud, and looks like gibberish at 115200, but the user code (printing of Debug is fine.) What devkit are you using? – jose can u c Apr 12 '18 at 19:49
  • 1
    For troubleshooting, I would a) set baud in the sketch to 74880, so you can see both the native boot info and your debug, and b) try a simple sketch first ... i.e. blink, and then try your code without WiFi requirement, i.e. print results to serial – Jaromanda X Apr 12 '18 at 23:20
  • 1
    Here's the output now: ` 1384, room 16 tail 8 chksum ets Jan 8 2013,rst cause:2, boot mode:(3,6) load 0x4010f000, len 1384, room 16 tail 8 chksum 0xef csum 0xef csum err ets_main.c ` – DaniFoldi Apr 14 '18 at 17:38
  • 1
    @josecanuc what upload settings did you use? – DaniFoldi Apr 14 '18 at 17:42
  • 1
    Arduino says that it's done uploading. – DaniFoldi Apr 15 '18 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.