PLEASE HELP. Thing Speak not updating on DHT 11 | ThingSpeak API | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
PLEASE HELP. Thing Speak not updating on DHT 11
No permission to create posts
December 28, 2017
1:10 am
Avatar
ashebray

Silver
Members
Forum Posts: 8
Member Since:
December 28, 2017
sp_UserOfflineSmall Offline

I have no idea why, but my sensor isn't reading anymore despite just setting it up. My numbers for humidity and temps are off and I don't know how to fix that (it shows 255 as the reading for both). I am new at this, but I will post my coding below for the DHT and the Personal Weather Station. Any help will be so appreciated! 

 

DHT CODING

#include <DHT.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ThingSpeak.h>
#define DHTPIN D5
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
const char* ssid = "WuTangLAN";
const char* password = "spranktank7664A";
WiFiClient client;
unsigned long myChannelNumber = 386894;
const char * myWriteAPIKey = "9DAGDL2109WC8DIJ";
uint8_t temperature, humidity;
void setup()
{
Serial.begin(115200);
dht.begin();
delay(10);
// Connect to WiFi network
Serial.println();
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");
// Print the IP address
Serial.println(WiFi.localIP());
ThingSpeak.begin(client);
}
void loop()
{
static boolean data_state = false;
temperature = dht.readTemperature();
humidity = dht.readHumidity();
Serial.print("Temperature Value is :");
Serial.print(temperature);
Serial.println("C");
Serial.print("Humidity Value is :");
Serial.print(humidity);
Serial.println("%");
// Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different
// pieces of information in a channel. Here, we write to field 1.
if( data_state )
{
ThingSpeak.writeField(myChannelNumber, 1, temperature, myWriteAPIKey);
data_state = false;
}
else
{
ThingSpeak.writeField(myChannelNumber, 2, humidity, myWriteAPIKey);
data_state = true;
}
delay(30000); // ThingSpeak will only accept updates every 15 seconds.
}

PWS

/**The MIT License (MIT)

Copyright (c) 2016 by Daniel Eichhorn

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

See more at http://blog.squix.ch
*/

#include <ESP8266WiFi.h>
#include <Ticker.h>
#include <JsonListener.h>
#include "SSD1306Wire.h"
#include "OLEDDisplayUi.h"
#include "Wire.h"
#include "WundergroundClient.h"
#include "WeatherStationFonts.h"
#include "WeatherStationImages.h"
#include "TimeClient.h"
#include "ThingspeakClient.h"

/***************************
* Begin Settings
**************************/
// Please read http://blog.squix.org/weatherstation-getting-code-adapting-it
// for setup instructions

// WIFI
const char* WIFI_SSID = "WuTangLAN";
const char* WIFI_PWD = "spranktank7664A";

 

// Setup
const int UPDATE_INTERVAL_SECS = 10 * 60; // Update every 10 minutes

// Display Settings
const int I2C_DISPLAY_ADDRESS = 0x3c;
const int SDA_PIN = D3;
const int SDC_PIN = D4;

// TimeClient settings
const float UTC_OFFSET = -5;

// Wunderground Settings
const boolean IS_METRIC = true;
const String WUNDERGRROUND_API_KEY = "c7fdd773c27f8a63";
const String WUNDERGRROUND_LANGUAGE = "EN";
const String WUNDERGROUND_COUNTRY = "WV";
const String WUNDERGROUND_CITY = "Morgantown";

//Thingspeak Settings
const String THINGSPEAK_CHANNEL_ID = " 386894";
const String THINGSPEAK_API_READ_KEY = "BZF0D1CS8DBQC6AQ";

// Initialize the oled display for address 0x3c
// sda-pin=14 and sdc-pin=12
SSD1306Wire display(I2C_DISPLAY_ADDRESS, SDA_PIN, SDC_PIN);
OLEDDisplayUi ui( &display );

/***************************
* End Settings
**************************/

TimeClient timeClient(UTC_OFFSET);

// Set to false, if you prefere imperial/inches, Fahrenheit
WundergroundClient wunderground(IS_METRIC);

ThingspeakClient thingspeak;

// flag changed in the ticker function every 10 minutes
bool readyForWeatherUpdate = false;

String lastUpdate = "--";

Ticker ticker;

//declaring prototypes
void drawProgress(OLEDDisplay *display, int percentage, String label);
void updateData(OLEDDisplay *display);
void drawDateTime(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
void drawCurrentWeather(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
void drawForecast(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
void drawThingspeak(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
void drawForecastDetails(OLEDDisplay *display, int x, int y, int dayIndex);
void drawHeaderOverlay(OLEDDisplay *display, OLEDDisplayUiState* state);
void setReadyForWeatherUpdate();

 

// Add frames
// this array keeps function pointers to all frames
// frames are the single views that slide from right to left
FrameCallback frames[] = { drawDateTime, drawCurrentWeather, drawForecast, drawThingspeak };
int numberOfFrames = 4;

OverlayCallback overlays[] = { drawHeaderOverlay };
int numberOfOverlays = 1;

void setup() {
Serial.begin(115200);
Serial.println();
Serial.println();

// initialize dispaly
display.init();
display.clear();
display.display();

//display.flipScreenVertically();
display.setFont(ArialMT_Plain_10);
display.setTextAlignment(TEXT_ALIGN_CENTER);
display.setContrast(255);

WiFi.begin(WIFI_SSID, WIFI_PWD);

int counter = 0;
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
display.clear();
display.drawString(64, 10, "Connecting to WiFi");
display.drawXbm(46, 30, 8, 8, counter % 3 == 0 ? activeSymbole : inactiveSymbole);
display.drawXbm(60, 30, 8, 8, counter % 3 == 1 ? activeSymbole : inactiveSymbole);
display.drawXbm(74, 30, 8, 8, counter % 3 == 2 ? activeSymbole : inactiveSymbole);
display.display();

counter++;
}

ui.setTargetFPS(30);

ui.setActiveSymbol(activeSymbole);
ui.setInactiveSymbol(inactiveSymbole);

// You can change this to
// TOP, LEFT, BOTTOM, RIGHT
ui.setIndicatorPosition(BOTTOM);

// Defines where the first frame is located in the bar.
ui.setIndicatorDirection(LEFT_RIGHT);

// You can change the transition that is used
// SLIDE_LEFT, SLIDE_RIGHT, SLIDE_TOP, SLIDE_DOWN
ui.setFrameAnimation(SLIDE_LEFT);

ui.setFrames(frames, numberOfFrames);

ui.setOverlays(overlays, numberOfOverlays);

// Inital UI takes care of initalising the display too.
ui.init();

Serial.println("");

updateData(&display);

ticker.attach(UPDATE_INTERVAL_SECS, setReadyForWeatherUpdate);

}

void loop() {

if (readyForWeatherUpdate && ui.getUiState()->frameState == FIXED) {
updateData(&display);
}

int remainingTimeBudget = ui.update();

if (remainingTimeBudget > 0) {
// You can do some work here
// Don't do stuff if you are below your
// time budget.
delay(remainingTimeBudget);
}

 

}

void drawProgress(OLEDDisplay *display, int percentage, String label) {
display->clear();
display->setTextAlignment(TEXT_ALIGN_CENTER);
display->setFont(ArialMT_Plain_10);
display->drawString(64, 10, label);
display->drawProgressBar(2, 28, 124, 10, percentage);
display->display();
}

void updateData(OLEDDisplay *display) {
drawProgress(display, 10, "Updating time...");
timeClient.updateTime();
drawProgress(display, 30, "Updating conditions...");
wunderground.updateConditions(WUNDERGRROUND_API_KEY, WUNDERGRROUND_LANGUAGE, WUNDERGROUND_COUNTRY, WUNDERGROUND_CITY);
drawProgress(display, 50, "Updating forecasts...");
wunderground.updateForecast(WUNDERGRROUND_API_KEY, WUNDERGRROUND_LANGUAGE, WUNDERGROUND_COUNTRY, WUNDERGROUND_CITY);
drawProgress(display, 80, "Updating thingspeak...");
thingspeak.getLastChannelItem(THINGSPEAK_CHANNEL_ID, THINGSPEAK_API_READ_KEY);
lastUpdate = timeClient.getFormattedTime();
readyForWeatherUpdate = false;
drawProgress(display, 100, "Done...");
delay(1000);
}

 

void drawDateTime(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
display->setTextAlignment(TEXT_ALIGN_CENTER);
display->setFont(ArialMT_Plain_10);
String date = wunderground.getDate();
int textWidth = display->getStringWidth(date);
display->drawString(64 + x, 5 + y, date);
display->setFont(ArialMT_Plain_24);
String time = timeClient.getFormattedTime();
textWidth = display->getStringWidth(time);
display->drawString(64 + x, 15 + y, time);
display->setTextAlignment(TEXT_ALIGN_LEFT);
}

void drawCurrentWeather(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
display->setFont(ArialMT_Plain_10);
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->drawString(60 + x, 5 + y, wunderground.getWeatherText());

display->setFont(ArialMT_Plain_24);
String temp = wunderground.getCurrentTemp() + "°C";
display->drawString(60 + x, 15 + y, temp);
int tempWidth = display->getStringWidth(temp);

display->setFont(Meteocons_Plain_42);
String weatherIcon = wunderground.getTodayIcon();
int weatherIconWidth = display->getStringWidth(weatherIcon);
display->drawString(32 + x - weatherIconWidth / 2, 05 + y, weatherIcon);
}

 

void drawForecast(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
drawForecastDetails(display, x, y, 0);
drawForecastDetails(display, x + 44, y, 2);
drawForecastDetails(display, x + 88, y, 4);
}

void drawThingspeak(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
display->setTextAlignment(TEXT_ALIGN_CENTER);
display->setFont(ArialMT_Plain_10);
display->drawString(64 + x, 0 + y, "Outdoor");
display->setFont(ArialMT_Plain_16);
display->drawString(64 + x, 10 + y, thingspeak.getFieldValue(0) + "°C");
display->drawString(64 + x, 30 + y, thingspeak.getFieldValue(1) + "%");
}

void drawForecastDetails(OLEDDisplay *display, int x, int y, int dayIndex) {
display->setTextAlignment(TEXT_ALIGN_CENTER);
display->setFont(ArialMT_Plain_10);
String day = wunderground.getForecastTitle(dayIndex).substring(0, 3);
day.toUpperCase();
display->drawString(x + 20, y, day);

display->setFont(Meteocons_Plain_21);
display->drawString(x + 20, y + 12, wunderground.getForecastIcon(dayIndex));

display->setFont(ArialMT_Plain_10);
display->drawString(x + 20, y + 34, wunderground.getForecastLowTemp(dayIndex) + "|" + wunderground.getForecastHighTemp(dayIndex));
display->setTextAlignment(TEXT_ALIGN_LEFT);
}

void drawHeaderOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) {
display->setColor(WHITE);
display->setFont(ArialMT_Plain_10);
String time = timeClient.getFormattedTime().substring(0, 5);
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->drawString(0, 54, time);
display->setTextAlignment(TEXT_ALIGN_RIGHT);
String temp = wunderground.getCurrentTemp() + "°C";
display->drawString(128, 54, temp);
display->drawHorizontalLine(0, 52, 128);
}

void setReadyForWeatherUpdate() {
Serial.println("Setting readyForUpdate to true");
readyForWeatherUpdate = true;
}

December 28, 2017
9:25 pm
Avatar
Vinod

MathWorks
Members
Forum Posts: 201
Member Since:
May 1, 2016
sp_UserOfflineSmall Offline

Perhaps you can start with one of the instructables? See here:

http://www.instructables.com/id/Send-sensor-data-DHT11-BMP180-to-ThingSpeak-with-a/

December 28, 2017
11:22 pm
Avatar
ashebray

Silver
Members
Forum Posts: 8
Member Since:
December 28, 2017
sp_UserOfflineSmall Offline

It is able to read data but it is no longer recording it on to thing speak. I even tried this http://community.thingspeak.com/forum/thingspeak-api/my-channel-stopped-updating-the-data-but-shows-entries/ but still not luck. Do I need to put a JSON streamer on? 

December 29, 2017
1:50 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 222
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

Are you still using the code above?  Can you share what you see on the serial monitor?  You should not need a special JSON library.

The link you shared shows hot to updata a channel with an HTTP GET.  Were you able to update your channel that way?

If the numbers for the sensor  are wrong, I would suspect you have a connection error.  Double check your schematic.

December 29, 2017
2:00 pm
Avatar
SouthPark
New Member
Members
Forum Posts: 4
Member Since:
December 18, 2017
sp_UserOfflineSmall Offline

You're probably better off saving a "copy" of your code, and remove all the unnecessary stuff like Oled, displays......ie. get rid of anything that could possibly cause issues or memory problems or writing errors etc. And then just test basic data upload to thingspeak --- without those extra possible distractions. Eventually you may find the issue --- such as memory over-written due to pointers over-running etc. This is just a maybe. The idea is ....to just start small again - to get data sending working properly again.

December 29, 2017
9:38 pm
Avatar
ashebray

Silver
Members
Forum Posts: 8
Member Since:
December 28, 2017
sp_UserOfflineSmall Offline

cstapels said

Are you still using the code above?  Can you share what you see on the serial monitor?  You should not need a special JSON library.

The link you shared shows hot to updata a channel with an HTTP GET.  Were you able to update your channel that way?

If the numbers for the sensor  are wrong, I would suspect you have a connection error.  Double check your schematic.  

I am using the codes above. I have tried a few DHT codes and still only get 2 or three readings then nothing. I'm new to this so I'm not sure how to fix this.

 

For my serial monitor, nothing loads at all. Just a white screen.

December 29, 2017
9:49 pm
Avatar
ashebray

Silver
Members
Forum Posts: 8
Member Since:
December 28, 2017
sp_UserOfflineSmall Offline

cstapels said

Are you still using the code above?  Can you share what you see on the serial monitor?  You should not need a special JSON library.

The link you shared shows hot to updata a channel with an HTTP GET.  Were you able to update your channel that way?

If the numbers for the sensor  are wrong, I would suspect you have a connection error.  Double check your schematic.  

Never mind, here is my SM

Setting readyForUpdate to true
.
02:42:41
2:42:41
9761
Requesting URL: /api/c7fdd773c27f8a63/conditions/lang:EN/q/WV/Morgantown.json
start document
Requesting URL: /api/c7fdd773c27f8a63/forecast10day/lang:EN/q/WV/Morgantown.json
start document
0: snow:forecastday
0: Friday
1: nt_snow:pop
1: Friday Night
2: snow:pop
2: Saturday
3: nt_partlycloudy:pop
3: Saturday Night
4: cloudy:pop
4: Sunday
5: nt_partlycloudy:pop
5: Sunday Night
6: mostlycloudy:pop
6: Monday
7: nt_partlycloudy:pop
7: Monday Night
8: partlycloudy:pop
8: Tuesday
9: nt_clear:pop
9: Tuesday Night
10: partlycloudy:pop
10: Wednesday
11: nt_cloudy:pop
11: Wednesday Night
12: partlycloudy:pop
12: Thursday
13: nt_partlycloudy:pop
13: Thursday Night
14: cloudy:pop
14: Friday
15: nt_partlycloudy:pop
15: Friday Night
16: clear:pop
16: Saturday
17: nt_partlycloudy:pop
17: Saturday Night
18: cloudy:pop
18: Sunday
19: nt_mostlycloudy:pop
19: Sunday Night
1: -4
2: -4
3: -8
4: -8
5: -8
6: -2
7: -9
8: -7
9: -6
10: 0
Requesting URL: /channels/386894/feeds.json?results=1&api_key=BZF0D1CS8DBQC6AQ
.
field1: 512.00
field2: 460.80

December 29, 2017
11:10 pm
Avatar
ashebray

Silver
Members
Forum Posts: 8
Member Since:
December 28, 2017
sp_UserOfflineSmall Offline

Tried a new code, now I'm getting NaN readings for my humidity 

#include <ESP8266WiFi.h>
#include <Ticker.h>
#include <JsonListener.h>
#include "SSD1306Wire.h"
#include "OLEDDisplayUi.h"
#include "Wire.h"
#include "WundergroundClient.h"
#include "WeatherStationFonts.h"
#include "WeatherStationImages.h"
#include "TimeClient.h"
#include "ThingspeakClient.h"

/***************************
* Begin Settings
**************************/
// Please read http://blog.squix.org/weatherstation-getting-code-adapting-it
// for setup instructions

// WIFI
const char* WIFI_SSID = "WuTangLAN";
const char* WIFI_PWD = "spranktank7664A";

 

// Setup
const int UPDATE_INTERVAL_SECS = 10 * 60; // Update every 10 minutes

// Display Settings
const int I2C_DISPLAY_ADDRESS = 0x3c;
const int SDA_PIN = D3;
const int SDC_PIN = D4;

// TimeClient settings
const float UTC_OFFSET = -5;

// Wunderground Settings
const boolean IS_METRIC = true;
const String WUNDERGRROUND_API_KEY = "c7fdd773c27f8a63";
const String WUNDERGRROUND_LANGUAGE = "EN";
const String WUNDERGROUND_COUNTRY = "WV";
const String WUNDERGROUND_CITY = "Morgantown";

//Thingspeak Settings
const String THINGSPEAK_CHANNEL_ID = "386894";
const String THINGSPEAK_API_READ_KEY = "BZF0D1CS8DBQC6AQ";

// Initialize the oled display for address 0x3c
// sda-pin=14 and sdc-pin=12
SSD1306Wire display(I2C_DISPLAY_ADDRESS, SDA_PIN, SDC_PIN);
OLEDDisplayUi ui( &display );

/***************************
* End Settings
**************************/

TimeClient timeClient(UTC_OFFSET);

// Set to false, if you prefere imperial/inches, Fahrenheit
WundergroundClient wunderground(IS_METRIC);

ThingspeakClient thingspeak;

// flag changed in the ticker function every 10 minutes
bool readyForWeatherUpdate = false;

String lastUpdate = "--";

Ticker ticker;

//declaring prototypes
void drawProgress(OLEDDisplay *display, int percentage, String label);
void updateData(OLEDDisplay *display);
void drawDateTime(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
void drawCurrentWeather(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
void drawForecast(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
void drawThingspeak(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
void drawForecastDetails(OLEDDisplay *display, int x, int y, int dayIndex);
void drawHeaderOverlay(OLEDDisplay *display, OLEDDisplayUiState* state);
void setReadyForWeatherUpdate();

 

// Add frames
// this array keeps function pointers to all frames
// frames are the single views that slide from right to left
FrameCallback frames[] = { drawDateTime, drawCurrentWeather, drawForecast, drawThingspeak };
int numberOfFrames = 4;

OverlayCallback overlays[] = { drawHeaderOverlay };
int numberOfOverlays = 1;

void setup() {
Serial.begin(115200);
Serial.println();
Serial.println();

// initialize dispaly
display.init();
display.clear();
display.display();

//display.flipScreenVertically();
display.setFont(ArialMT_Plain_10);
display.setTextAlignment(TEXT_ALIGN_CENTER);
display.setContrast(255);

WiFi.begin(WIFI_SSID, WIFI_PWD);

int counter = 0;
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
display.clear();
display.drawString(64, 10, "Connecting to WiFi");
display.drawXbm(46, 30, 8, 8, counter % 3 == 0 ? activeSymbole : inactiveSymbole);
display.drawXbm(60, 30, 8, 8, counter % 3 == 1 ? activeSymbole : inactiveSymbole);
display.drawXbm(74, 30, 8, 8, counter % 3 == 2 ? activeSymbole : inactiveSymbole);
display.display();

counter++;
}

ui.setTargetFPS(30);

ui.setActiveSymbol(activeSymbole);
ui.setInactiveSymbol(inactiveSymbole);

// You can change this to
// TOP, LEFT, BOTTOM, RIGHT
ui.setIndicatorPosition(BOTTOM);

// Defines where the first frame is located in the bar.
ui.setIndicatorDirection(LEFT_RIGHT);

// You can change the transition that is used
// SLIDE_LEFT, SLIDE_RIGHT, SLIDE_TOP, SLIDE_DOWN
ui.setFrameAnimation(SLIDE_LEFT);

ui.setFrames(frames, numberOfFrames);

ui.setOverlays(overlays, numberOfOverlays);

// Inital UI takes care of initalising the display too.
ui.init();

Serial.println("");

updateData(&display);

ticker.attach(UPDATE_INTERVAL_SECS, setReadyForWeatherUpdate);

}

void loop() {

if (readyForWeatherUpdate && ui.getUiState()->frameState == FIXED) {
updateData(&display);
}

int remainingTimeBudget = ui.update();

if (remainingTimeBudget > 0) {
// You can do some work here
// Don't do stuff if you are below your
// time budget.
delay(remainingTimeBudget);
}

 

}

void drawProgress(OLEDDisplay *display, int percentage, String label) {
display->clear();
display->setTextAlignment(TEXT_ALIGN_CENTER);
display->setFont(ArialMT_Plain_10);
display->drawString(64, 10, label);
display->drawProgressBar(2, 28, 124, 10, percentage);
display->display();
}

void updateData(OLEDDisplay *display) {
drawProgress(display, 10, "Updating time...");
timeClient.updateTime();
drawProgress(display, 30, "Updating conditions...");
wunderground.updateConditions(WUNDERGRROUND_API_KEY, WUNDERGRROUND_LANGUAGE, WUNDERGROUND_COUNTRY, WUNDERGROUND_CITY);
drawProgress(display, 50, "Updating forecasts...");
wunderground.updateForecast(WUNDERGRROUND_API_KEY, WUNDERGRROUND_LANGUAGE, WUNDERGROUND_COUNTRY, WUNDERGROUND_CITY);
drawProgress(display, 80, "Updating thingspeak...");
thingspeak.getLastChannelItem(THINGSPEAK_CHANNEL_ID, THINGSPEAK_API_READ_KEY);
lastUpdate = timeClient.getFormattedTime();
readyForWeatherUpdate = false;
drawProgress(display, 100, "Done...");
delay(1000);
}

 

void drawDateTime(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
display->setTextAlignment(TEXT_ALIGN_CENTER);
display->setFont(ArialMT_Plain_10);
String date = wunderground.getDate();
int textWidth = display->getStringWidth(date);
display->drawString(64 + x, 5 + y, date);
display->setFont(ArialMT_Plain_24);
String time = timeClient.getFormattedTime();
textWidth = display->getStringWidth(time);
display->drawString(64 + x, 15 + y, time);
display->setTextAlignment(TEXT_ALIGN_LEFT);
}

void drawCurrentWeather(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
display->setFont(ArialMT_Plain_10);
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->drawString(60 + x, 5 + y, wunderground.getWeatherText());

display->setFont(ArialMT_Plain_24);
String temp = wunderground.getCurrentTemp() + "°C";
display->drawString(60 + x, 15 + y, temp);
int tempWidth = display->getStringWidth(temp);

display->setFont(Meteocons_Plain_42);
String weatherIcon = wunderground.getTodayIcon();
int weatherIconWidth = display->getStringWidth(weatherIcon);
display->drawString(32 + x - weatherIconWidth / 2, 05 + y, weatherIcon);
}

 

void drawForecast(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
drawForecastDetails(display, x, y, 0);
drawForecastDetails(display, x + 44, y, 2);
drawForecastDetails(display, x + 88, y, 4);
}

void drawThingspeak(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
display->setTextAlignment(TEXT_ALIGN_CENTER);
display->setFont(ArialMT_Plain_10);
display->drawString(64 + x, 0 + y, "Outdoor");
display->setFont(ArialMT_Plain_16);
display->drawString(64 + x, 10 + y, thingspeak.getFieldValue(0) + "°C");
display->drawString(64 + x, 30 + y, thingspeak.getFieldValue(1) + "%");
}

void drawForecastDetails(OLEDDisplay *display, int x, int y, int dayIndex) {
display->setTextAlignment(TEXT_ALIGN_CENTER);
display->setFont(ArialMT_Plain_10);
String day = wunderground.getForecastTitle(dayIndex).substring(0, 3);
day.toUpperCase();
display->drawString(x + 20, y, day);

display->setFont(Meteocons_Plain_21);
display->drawString(x + 20, y + 12, wunderground.getForecastIcon(dayIndex));

display->setFont(ArialMT_Plain_10);
display->drawString(x + 20, y + 34, wunderground.getForecastLowTemp(dayIndex) + "|" + wunderground.getForecastHighTemp(dayIndex));
display->setTextAlignment(TEXT_ALIGN_LEFT);
}

void drawHeaderOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) {
display->setColor(WHITE);
display->setFont(ArialMT_Plain_10);
String time = timeClient.getFormattedTime().substring(0, 5);
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->drawString(0, 54, time);
display->setTextAlignment(TEXT_ALIGN_RIGHT);
String temp = wunderground.getCurrentTemp() + "°C";
display->drawString(128, 54, temp);
display->drawHorizontalLine(0, 52, 128);
}

void setReadyForWeatherUpdate() {
Serial.println("Setting readyForUpdate to true");
readyForWeatherUpdate = true;
}

 

DHT CODING

#include <DHT.h> // DHT.h library
#include <ESP8266WiFi.h> // ESP8266WiFi.h library

#define DHTPIN 2
#define DHTTYPE DHT11

const char* ssid = "WuTangLAN";
const char* password = "spranktank7664A";
const char* host = "api.thingspeak.com";
const char* writeAPIKey = "9DAGDL2109WC8DIJ";

DHT dht(DHTPIN, DHTTYPE, 15);

void setup() {
// Initialize sensor

Serial.begin(115200);

dht.begin();
delay(1000);

// Connect to WiFi network
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println(".");

}
}

void loop() {
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();

if (isnan(humidity) || isnan(temperature)) {
return;
}

// make TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
return;
}

String url = "/update?key=";
url+=writeAPIKey;
url+="&field1=";
url+=String(temperature);
url+="&field2=";
url+=String(humidity);
url+="
";

December 31, 2017
9:58 pm
Avatar
ashebray

Silver
Members
Forum Posts: 8
Member Since:
December 28, 2017
sp_UserOfflineSmall Offline

I'm desperate at this point. The sensor is now reading properly but it is NOT updating in the time frame it should be at all. Here is the code: 

 

#include <ESP8266WiFi.h>
#include "DHT.h"

 

/***************************
* Begin Settings
**************************/

 

const char* ssid = "WuTangLAN";
const char* password = "spranktank7664A";

const char* host = "api.thingspeak.com";

const char* THINGSPEAK_API_KEY = "9DAGDL2109WC8DIJ";

// DHT Settings
#define DHTPIN D6 // what digital pin we're connected to. If you are not using NodeMCU change D6 to real pin

 

// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

const boolean IS_METRIC = true;

// Update every 600 seconds = 10 minutes. Min with Thingspeak is ~20 seconds
const int UPDATE_INTERVAL_SECONDS = 600;

/***************************
* End Settings
**************************/

// Initialize the temperature/ humidity sensor
DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(115200);
delay(10);

// We start by connecting to a WiFi network

Serial.println();
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.print("connecting to ");
Serial.println(host);

// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}

// read values from the sensor
float humidity = dht.readHumidity();
float temperature = dht.readTemperature(!IS_METRIC);

// We now create a URI for the request
String url = "/update?api_key=";

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online: Hans, agrisensezm
38 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

Archieter, JamesExedo, IrbosHich, brodi, kasko, franklin castro

Administrators: Hans: 387, lee: 457