ESP8266 upload data issue

  • 1
  • Problem
  • Updated 5 months ago
Hi - Building a DIY weather station and trying to upload weather data using an Adafruit ESP8266 Feather Huzzah.  I think I have my code correct but it is not showing up online.  I don't get any connection errors. Where am I going wrong?  
#include <ESP8266WiFi.h>
#include <Arduino.h>
#include <Wire.h>

const char* ssid     = "Robots";
const char* password = "xxxxxxx";
const int sleepTimeS = 180; //18000 for Half hour, 300 for 5 minutes etc.

//char server [] = "weatherstation.wunderground.com";
char server [] = "rtupdate.wunderground.com";
char WEBPAGE [] = "GET /weatherstation/updateweatherstation.php?";
char ID [] = "KNCRALEI304";
char PASSWORD [] = "xxxxxxx";

void setup()
{
  Serial.begin(115200);
  Serial.println("ESP8266 Weather 2");
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  Serial.println("ESP8266 Weather 2 main loop");
  //Get sensor data
  float tempc = 29;
  float tempf =  (tempc * 9.0) / 5.0 + 32.0;
  float humidity = 68;
  //check sensor data
  Serial.println(" ");
  Serial.print("tempF= ");
  Serial.print(tempf);
  Serial.println(" *F");
  Serial.print("tempC= ");
  Serial.print(tempc);
  Serial.println(" *C");
  Serial.print("humidity= ");
  Serial.println(humidity);

  //Send data to Weather Underground
  Serial.print("connecting to ");
  Serial.println(server);
  WiFiClient client;
  if (!client.connect(server, 80)) {
    Serial.println("Conection Fail");
    return;
  }
  client.print(WEBPAGE);
  client.print("ID=");
  client.print(ID);
  client.print("&PASSWORD=");
  client.print(PASSWORD);
  client.print("&dateutc=");
  client.print("now");
  client.print("&tempf=");
  client.print(tempf);
  client.print("&humidity=");
  client.print(humidity);
  client.print("&softwaretype=Arduino%20UNO%20version1&action=updateraw&realtime=1&rtfreq=2.5");
  client.println();
  delay(2500);
  sleepMode();
}

void sleepMode() {
  Serial.print(F("Sleeping..."));
  ESP.deepSleep(sleepTimeS * 1000000);
}
Photo of Todd Miller

Todd Miller

  • 3 Posts
  • 0 Reply Likes

Posted 1 year ago

  • 1
Photo of Todd Miller

Todd Miller

  • 3 Posts
  • 0 Reply Likes
All set, figured it out.

void senddataWU()
{
  Serial.println(F("Send to WU Sensor Values"));
  Serial.print(F("connecting to "));
  Serial.println(host2);
  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host2, httpPort)) {
    Serial.println("connection failed");
  //  startwifi();
    return;
  }  
  // Create a URI for the request
  String url = "/weatherstation/updateweatherstation.php?ID=";
  url += ID;
  url += "&PASSWORD=";
  url += PASSWORD;
  url += "&dateutc=now";
  url += "&tempf=";
  url += tem;
  url += "&humidity=";
  url += hum;
  url += "&softwaretype=Arduino-ESP8266&action=updateraw&realtime=1&rtfreq=2.5";
  Serial.print(F("Requesting URL: "));
  Serial.println(url);
  // This will send the request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" + 
               "Connection: close\r\n\r\n");
  delay(10);  
  // Read all the lines of the reply from server and print them to Serial
  while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
  Serial.println();
  Serial.println(F("closing connection"));
}

Photo of Nancy McBride

Nancy McBride

  • 1 Post
  • 0 Reply Likes
Could you post your entire working ESP8266 sketch? DHT sensor?
Photo of Todd Miller

Todd Miller

  • 3 Posts
  • 0 Reply Likes
See my writeup of what I made with my parts list and code.  http://thesolderingstation.com/esp8266-weather-station/