0 votes
in WeatherStationClassic by (160 points)
edited by
In the code for the project there are more projects to expand the basic code to enable indoor or outdoor sensors using the lines associated with Thing speak, I understand this.

I understand also that my local temp readings are being read from my sensor DHT11 in my case and somehow ported to thing speak from where it can be read back to my device with a "READ" function.

How can this be when there is no "WRITE" function in the code?

Looking now at my thingspeak chanel, there are no readings and no lookup attempts..

The readings from my sensor are displayed at the default 10 minutes.

Looking at the serial output after a reboot shows all the usual stuff until it gets the URL request thingspeak and then stops. After 10 minutes the process starts again with the same outcome.

The readings on the OLED for temp and humidity are marginal at best, for example, i am freezing my Squixes off yet its showing 30 deg C. It does change from time to time so i know its not static. I also swapped the DHT for another.

When i tried to add a write command just above the read command for thingspeak my temp reading shows on the oled as null.

//Thingspeak Settings
const String THINGSPEAK_CHANNEL_ID = "306xxx";
//const String ThingSpeak.writeField(3063xx, 1, Temperature, RYIFJRWHxxxxx); NOT TRIED THIS, LOOKS WRONG, NOT CALLING API
// Initialize the oled display for address 0x3c

I need to understand this a little better so I can do an outside temperature reading as well as a new page on the screen.

Am I going Squix or what?

Nigel :)

1 Answer

0 votes
by (550 points)
Hi Nigel, this mostly depends on how you've coded your app.

If you're following the excellent ESP8266 weather station kit book, the book has you code the following:

Weather station with screen

   -> gets local temp from weatherunderground.com
   -> Pulls in one additional sensor from thingspeak. *NOTE Default pulls Daniel's weather, not yours!

Then just after that the book shows how to make a 'climate node' which records data to thingspeak.com


I found a blog post on squix that showed some code for reading a local sensor (on the weather station with screen) in this code, the local temp was read into a variable and *not* sent to thingspeak.com, so that's what I've done so far.

If you want to share your code on gist.github.com, and past a link, we can have a look -
Be sure to erase the following before posting your gist online:
- Replace your wifi network name and password with *****
- Replace any thingspeak API keys/ID's with *****
Thanks for that, I was wondering how to share some code.
I haven't got any issues with displaying the local temp on the screen, I was just messing with a nodemcu and some of Squixs code trying to use out how the temp was getting to and from thingspeak.
I've used thingspeak before for my solar sensors I just couldn't fathom how we can fetch the temp without sending it first.
I will find the code and post although what is above is pretty much it.
I got it of Squixs somewhere.
Thanks BasementJack
by (550 points)
Nigel, just checking to see if you sorted this issue out?
by (160 points)
Not yet.
Decided  to go back to basics and just try and send a write to Thing speak with "esp9266-dht-thingspeak-logger.ino also by squix from a link in his instruction pdf.

In this example the requests are totally different to squixs other code, he must have been experimenting to see what works. This example returns a bad URL request as below.

WiFi connected
IP address:
connecting to api.thingspeak.com
Requesting URL: /update?api_key=def4daadxxxxxx&field1=nan&field2=nan
HTTP/1.1 400 Bad Request
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: close
Status: 400 Bad Request
X-Frame-Options: ALLOWALL
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS, DELETE, PATCH
Access-Control-Allow-Headers: origin, content-type, X-Requested-With
Access-Control-Max-Age: 1800
Cache-Control: no-cache
X-Request-Id: 7979595a-fcfb-4fc9-96ab-2a6b486c81e3
X-Runtime: 0.004253
X-Powered-By: Phusion Passenger 4.0.57
Date: Tue, 25 Jul 2017 12:18:40 GMT
Server: nginx/1.9.3 + Phusion Passenger 4.0.57


closing connection

Again, i dont see anywhere that we have rights to submit a "write", or to which channel, although the bad URL is another issue. Maybe something has changed since it was written.
I have used thingspeak for a couple of years with domoticz but in that format requests are made with PHP at least in my case.
Also interesting in this case is that we are not calling another library i.e thingspeak.h where we can define the requests.
No panic, we will get there LOL, got food in our bellies it can wait.
Understand i am not trying to get a squix kit working here, just playing around trying to learn a little, at my age stuff goes in and out with little to no retention. AKA NULL VOID
by (550 points)
if you're using this code: https://github.com/squix78/esp8266-dht-thingspeak-logger
I can confirm it still works.

when troubleshooting an API call, it can be helpful to just do the call in your computer's web browser.

from your output above, you'd grab the host and URL and just manually paste those into your browser (for example chrome) and then see what chrome returns.

For example
In my browser this returns 0 which is to be expected since that's not an actual API key.

See if you can get it to accept the values - it could be that your 'nan' s are the problem, and you may want to, in your browser, replace those with actual numbers to see if it changes the way it works, once you get it working in your browser, it will be easier to then go back to the source code and know what needs to be updated.
by (160 points)
Thanks BasementJack,

I will have a go later on, that is the same source code im running unchanged apart from keys so i can see if i can get a "write" to my thingspeak fields.

Just trying to understand it. there seems to be so many ways to do this and it gets kinda confusing.

My old brain tells me that  
A i need an address to post the letter
B i need a key to open the box to post the letter
C i need a key to open the box to get a reply from the letter box
D i need and address to deliver the letter to.

It seems from what your saying that i have not got a letter to post yet.
I will go find my letter :P
by (550 points)
That sounds right - you can log into thingspeak and look at your counter - there are nice line charts that will show values if any are there.

Welcome to ThingPulse Q&A, where you can ask questions and receive answers from other members of the community.