HOME - - - - - - - - Table of contents, my Arduino "How To" articles
Other material for programmers     

Environmental Monitoring Webserver

With Inexpensive Si7021 sensor

filename: aht5env-mon-si7021.htm

This PAGE is poor.... not well edited, bits undeveloped.

Also, it is a very close cousin to my page about a $16+sensor environmental monitor server based on the SHT_15 humidity and temperature sensor.

And the software is only "fair". It WORKS, though, and it is free. And it runs in a Sparkfun ESP8266 (about $16), and if you don't like the sensor I've used, you can replace that element of the package.

What I was trying to do: I wanted a SIMPLE (reliable!), INEXPENSIVE (well, relatively) device which could sit on a WiFi, be accessible across the internet, and report a few environmental sensor readings. The device I envisioned (and present here) doesn't do "clever things", like draw graphs, or tell you the hottest or coldest readings in the past 24 hours, etc.

It doesn't do those things because I envision a separate computer automatically, periodically, "harvesting" readings from one or more of the simple devices described here. That computer can log and present and analyze the data. (I have in fact written programs for this... usually in Lazarus... but they are still more fit for my eyes than public scrutiny. My tutorial on fetching a page of html is all you need to get started with your own version of what I envision, if you are in a hurry.)

A Mash Up

Usually in my tutorials, I look at one process per tutorial. And I usually do a more thorough job of "explaining".

In this tutorial I have mashed together, rather crudely, two demo programs from Sparkfun, for the ESP8266 and a sensor, the Si7021. (You can replace the sensor bits with whatever you need for YOUR sensor quite easily.)

You can download the sourcecode for my ESP8266 Environmental Monitor Webserver with Si7021. Be advised: It WILL NOT RUN exactly as downloaded. You need to tweak the code AT LEAST to tell it your WiFi's SSID and key ("password"). And you may well want to change the IP address the server comes up on. (It is configured to use a static IP address, because it must have one (one way or another) if you want to access the device from outside your LAN. If you get it working from INSIDE your LAN, the rest is "easy", and won't depend on anything about the ESP8266 webserver that the supplied code, with the little tweaks mentioned, creates.)

Blow by blow...

I should split bits of this out. It tells two stories, side by side...

a) Getting started with ESP8266. I will give the details for a specific one, the Sparkfun Thing Dev Board (WRL-13711.. a product distinct from their very similarly named "Sparkfun Thing"). I have other pages, much tidier, more complete, about this. But THIS page, at 8/18, is my latest "run through" the steps for a beginner, and may have peculiar charms.

b) Using the SparkFun Humidity and Temperature Sensor Breakout based on the Si7021 (SEN-13683)... don't worry... if you don't want to use this sensor, there is still LOTS that will be useful to you, as you adapt what is here to manage a different sensor.

Among other things, I hope you will notice how a lot of "stuff" was "wrapped up" in the "ReadSensor" procedure. (Good). Even if the code uses some global variable badly. (Bad... but we all do it, and this is one of those circumstances where the practice can be tolerated, I feel.)

Things to note....

The 8266 is not "an Arduino", strictly speaking... but it is very like one... with bonus features! And only about $16! If you want to ignore the 8266 parts of this you can. Virtually everything relating specifically to the Si7021 should work just fine with a more basic Arduino.

The Si7021 is strictly a 3v3 device. If you want to use it with a 5v device, you can, I am quite confident (though I haven't tried it) as long as you put a level shifter (Sparkfun BOB-12009 ($3)) between them. Happily, the Thing is a 3v3 device too, so no problems for me.

It uses I2C, but is "locked" to one address... 0x40... so you can only have one Si7021 in a given string of I2C devices. (This was a decision by the chip maker, not Sparkfun.)

I've done brief notes on using the Si7021 with an Arduino (or ESP82666, etc). Below here,there are more extensive notes, after the "get your webserver running" notes.

Here we go...

My testing done on a Win 10 PC which had done Arduino work in the past. It had the vers 1.8.5 Arduino IDE on it. It didn't seem that I'd done any 8266 work on the machine previously... there was no entry for the 8266 in the "Tools/Board" menu.

Always set the "Board" before connecting a device to the IDE..

I went off to the Sparkfun intro to the 8266. Quote: "Installing the Add-on With the Arduino Boards Manager: With the release of Arduino 1.6.4, adding third party boards to the Arduino IDE is easily achieved through the board manager."

This has been my experience.

1 Sep 2018, Sparkfun pointed me to the following, which you use as follows.

http://arduino.esp8266.com/stable/package_esp8266com_index.json

In the Arduino IDE, open up File/ Preferences.

Add the URL ("http://arduino.esp8266...") to the "Additional Board Manager URLs" section. click OK.

Again, shamelessly just copy/pasting from Sparkfun, now you "navigate to the Board Manager by going to Tools > Boards > Boards Manager. Look for esp8266. Click the "more info" under that entry, then select Install."

(If you put "8266" in the filter at the top of the Boards Manager dialog, you'll find the right entry faster! The right thing to install 1 Sep 2018 was "esp8266 by ESP8266 Community"). I was offered vers 2.4.2, clicked Install, and it was DONE almost before I finished this paragraph.

If you went off to top up coffee while the install proceeded, look closely. There's no big "DONE!" banner... but now, up at the top of the material about the package, in a nice color and all caps, you should see "Installed". If you know to look!

Close the Boards Manager dialog. (You'll only have to do this "install package" thing once.

Use "Tools/Board" to configure the IDE for creating code for the ESP8266 you are using. Note that there are separate entries for the Sparkfun ESP8266 Thing and ESP8266 Thing Dev Board.

NOW you can plug in your Thing.

Set the IDE to "talk" to Thing on correct port. (Tools/ Port")

Check to see if there was code already in the Thing that gives info via the serial monitor when Thing boots.

Try a quick instance of "Blink" to see all is well so far. the "ordinary" blink is NEARLY what you want, but toggle the D5 line, instead of the usual D13. ('Cause that's where the Thing's LED is.) If you want to get fancy you can use "ESP8266_LED" for "5"! (A good practice, actually... but a bit "clever" for "Blink@!)

On my Sparkfun ESP8266 Thing Dev Board (WRL-13711) (quite old... from c. 1/17?) There are at least 3 tiny LEDs on the board. A red "power present" LED, a faint yellow LED that flickers during code upload, and a nice bright blue LED, "outside" the power LED, that is the one you can turn on or off with D5.

Progress!

So... including writing this, doing all of the above, it has taken me 35 minutes to get this far.

The humidity/ temperature sensor

Four connections are needed to the Arduino/8266:

The last two are the I2C communication wires. I should mention that I've done very little before now with I2C! The list above is from the point of view of the Sparkfun Si7021 breakout board.

For hookup, go to...

Sparkfun page about hooking up Si7021

The Sparkfun 8266 Thing has two pins dedicated to SDA, SCL. The Sparkfun 8266 Thing Dev Board makes pins 2 and 14 "work overtime... serving the needs of I2C serial data (SDA) and I2C serial clock (SCL) respectively.... in addition to serving other roles, depending on the software running on the device.

Back to work...

In the previously cited hook-up guide from Sparkfun, there was, 9/18, a link to a library you can download and install to make working with the Si7021. (If "libraries" bother you, download it anyway, and look into it, reverse engineer what is in the library... if you are feeling energetic. I share your fear of libraries, but sometimes they are Just The Way To Go... especially if they come from a reputable source.)

It is just an "ordinary" library. Install it in the "ordinary" way. (The Sparkfun and github pages have notes for you.)

Be careful when using libraries... you want to stay on top of what devices use which libraries, and where the libraries came from. And probably keep your own archive copies of the library downloads.

There are probably multiple Si7021 libraries. The one I'm using in this comes up in the IDE as "Saprkfun Si7021 Humidity...", and is by "Joel@Sparkfun.com". I was using vers 1.0.1

Reading the sensor

Notes on just reading the sensor are available at Sparkfun, and at a short page from me about reading the inexpensive Si7021 humidity and temperature sensor.

Onward...

We've got the ESP8266 to read the sensor. Now how about making it a webserver, with data from the sensor in the page served up?

Not a BIG deal, but there are a few tricky aspects... not least getting it to read the sensor often enough, but not too often, or at wrong time.

I'm more than out of time. Sorry I can't give you all the details... there ARE notes in the code... And it is free!....

Most of what I am going to present I learned from Sparkfun's good explanation of setting up an ESP8266 as a webserver.

a) Arduino IDE has to be set up for the 8266... see the...

http://arduino.esp8266.com/stable/package_esp8266com_index.json

... step in previous, if you skipped to here, and haven't done that yet.

The code that follows is a messy "mash-up" of the two Sparkfun examples. (Webserver and sensor reader.) Lots of Bad Stuff... but some good, too. And it does work!

Note the "unnecessary" internal documentation... it reports both to the Serial Monitor and to the served webpage the name of the "Sketch" and a version ID.

To make connecting it to the WAN easier, it has been modified to sit at a static IP address on the LAN. (At one point I was using 218... but I won't promise to keep code and text in step. That could have changed) (This approach assumes you do NOT want your DHCP to "put" it at an IP address based on MAC. Which also implies setting aside some IP addresses outside of the DHCP pool. Stories covered at length elsewhere. Get this working on LAN first. Then "go for" WAN access.

For the environmental monitor, bits of the Sparkfun server demo... the turning on and off of LED, the reading of the two inputs... not necessary. The scraps of that not fully weeded from the code.

Sorry! Not my usual standard of "polish"... but worth what you paid for it? I hope it helps, however messy it may be.

Besides the following, remember that the code can be downloaded.

[code]
//ESP8266WebServerSparkfunWiSi7021
//TKB notes- WORKED.. and played nicely with router at 7NC, Sept 18
//Knobbled Sparkfun webserver demo and moved to a static IP
//Plus reading, reporting Si7021, also derived from Sparkfun sources.
//Sensor breakout: Sparkfun product SEN-13763
//eSet saw as ""
//From Sparkfun, 7 Sep 2018
//https://learn.sparkfun.com/tutorials/esp8266-thing-development-board-hookup-guide/example-sketch-web-server

//*** TAKE OUT SSID/ WiFiPW IF PUBLISHING  ***

#include 





   Search this site or the web        powered by FreeFind
 
  Site search Web search
Site Map    What's New    Search

The search engine is not intelligent. It merely seeks the words you specify. It will not do anything sensible with "What does the 'could not compile' error mean?" It will just return references to pages with "what", "does", "could", "not".... etc.
In addition to the tutorials for which this page serves as Table of Contents, I have other sites with material you might find useful.....

Sequenced set of tutorials on Arduino programming and electronics interfacing.
Tutorials about the free database supplied with Open Office/ Libre Office.

Some pages for programmers.
Using the parallel port of a Windows computer.


If you visit 1&1's site from here, it helps me. They host my website, and I wouldn't put this link up for them if I wasn't happy with their service.




Ad from page's editor: Yes.. I do enjoy compiling these things for you... hope they are helpful. However.. this doesn't pay my bills!!! If you find this stuff useful, (and you run an MS-DOS or Windows PC) please visit my freeware and shareware page, download something, and circulate it for me? Links on your page to this page would also be appreciated!

Click here to visit editor's Sheepdog Software (tm) freeware, shareware pages.. Material on this page © TK Boyd qDATE


And if you liked that, or want different things, here are some more pages from the editor of these tutorials....

Click here to visit the homepage of my biggest site.

Click here to visit the homepage of Sheepdogsoftware.co.uk. Apologies if the "?FrmAht" I added to that link causes your browser problems. Please let me know, if so?

Click here to visit editor's pages about using computers in Sensing and Control, e.g. weather logging.



To email this page's editor, Tom Boyd.... Editor's email address. Suggestions welcomed!


Valid HTML 4.01 Transitional Page tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org


Why does this page cause a script to run? Because of the Google panels, and the code for the search button. Why do I mention the script? Be sure you know all you need to about spyware.

....... P a g e . . . E n d s .....