Hy guys im having a little trouble posting my temperature and humidity readings on weathercloud. In the serial monitor everithing is reading fine but when i go to weathercloud account it shows that the card connected but the temperature and humidity stay on zero. Here is the code. thanks
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino/archive/master.zip
#include <WiFiUdp.h>
#include <ESP8266WiFiMulti.h>
#include <ArduinoOTA.h>
#include <SPI.h>
#include <ESP8266mDNS.h>
#include <Wire.h>
ESP8266WiFiMulti wifiMulti;
//--------------------------------Setup Wifi----------------------------------------------
const char* ssid1 = “HUAWEI P30 lite”; //I use multiple SSID In my home, but you can only define one.
const char* password1 = “12345678”;
//----------------------------Weathercloud.net ID Key ----------------------------------
char server = “http://api.weathercloud.net”;;
char ID = “72389dd447e00ec0”;
char Key = “693ac7924969c7e86304f63973d23c15”;
unsigned int counter = 19;
float t;
float h;
float hic;
float dewpt_c;
#include “DHT.h”
#define DHTPIN 5 // Digital pin connected to the DHT sensor
// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 –
// Pin 15 can work but DHT must be disconnected during program upload.
// Uncomment whatever type you’re using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT11 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors. This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println(F(“DHTxx test!”));
dht.begin();
startwifi();
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
float dewpt_c = (dewPoint(t, h)); //dew point
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F(“Failed to read from DHT sensor!”));
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F(“°F”));
delay(30000);
weathercloud();
Counter();
}
//------------------------------------------------------------------------------------------------------------
///////////////////////////////// SEND DATA TO Weathercloud.net ////////////////////////////////////////////
//------------------------------------------------------------------------------------------------------------
void weathercloud(void)
{
if (counter == 20){
{
Serial.print("connecting to ");
Serial.print(server);
Serial.println("…");
WiFiClient client;
if (client.connect(server, 80)) {
Serial.print("connected to ");
Serial.println(client.remoteIP());
} else {
Serial.println(“connection failed”);
}
client.print(“GET /set/wid/”);
client.print(ID);
client.print("/key/");
client.print(Key);
client.print("/temp/");
client.print(t*10);
client.print("/dew/");
client.print(dewpt_c*10);
client.print("/heat/");
client.print(hic*10);
client.print("/hum/");
client.print(h);
client.print("/wspd/");
client.println("/ HTTP/1.1");
client.println(“Host: api.weathercloud.net”);
client.println();
delay(1000);
if (!client.connected()) {
Serial.println(“client disconected.”);
if (client.connect(server, 80)) {
delay(100);
Serial.print("connected to ");
Serial.println(client.remoteIP());
} else {
Serial.println(“connection failed”);
}
}
}
}
delay(100);
}
void startwifi()
{
Serial.print("Connecting to Wifi ");
delay(1000);
wifiMulti.addAP(ssid1, password1); //if you have less SSID, delete the others
while (wifiMulti.run() != WL_CONNECTED) { delay(1000);
Serial.print(".");
}
Serial.println("");
Serial.println(“WiFi connected”);
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
delay(500);
}
//------------------------------------------------------------------------------------------------------------
/////////////////////////////////////////////// Calculate dew Point C ////////////////////////////////////////
//------------------------------------------------------------------------------------------------------------
double dewPoint(double t, double h)
{
double RATIO = 373.15 / (273.15 + t); // RATIO was originally named A0, possibly confusing in Arduino context
double SUM = -7.90298 * (RATIO - 1);
SUM += 5.02808 * log10(RATIO);
SUM += -1.3816e-7 * (pow(10, (11.344 * (1 - 1/RATIO ))) - 1) ;
SUM += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO - 1))) - 1) ;
SUM += log10(1013.246);
double VP = pow(10, SUM - 3) * h;
double T = log(VP/0.61078); // temp var
return (241.88 * T) / (17.558 - T);
}
//------------------------------------------------------------------------------------------------------------
/////////////////////////////////////////////// Counter /////////////////////////////////////////////////////
//------------------------------------------------------------------------------------------------------------
void Counter()
{
if (counter == 20)
{
counter = 0; //10 minutes loop 30*20=600s = 10min
}
counter++;
}