Reef Discussion

Rob

Member
Apr 26, 2012
743
424
Iot Tank Sensor Project
Caution... Very geeky intensive thread......

The Internet of Things (IoT) is a concept designed to publish geographically distributed sensor/data online. Thus the technology is generally small low powered and obviously wifi enabled. The raspberrypi is overkill for such a requirement, too big and power hungry, arduino is small enough however Ethernet/wifi shields are expensive. Over the last 12 months a Chinese manufacturer released a wifi enabled device ESP8622 that has a small amount of IO and can serve this data out via html pages. More recently there is now applications that allow you to program the device similar to the arduino. So for $15.00 you now have available a wifi device that has quite a competent microprocessor onboard that we can easily program.

ESP8266. 16 GPIO pins
image.jpg





Application.....
I currently use a raspberrypi to provide trending for tank sensors which is very reliable. The RPi provides a full web server and does the data collection and trending / display of tank parameters. However what if the sensors are not close to the raspberrypi and too far or impractice to wire up or you have lots of tanks. We can use a esp8266 to gather data, do a little scaling and provide this data to whoever wants it. The RPi can easily log into the esp8266 and retrieve the data and then trend this locally. I have been using this philosophy for the past 18 months, I have no sensors connected to my RPi anymore however log into my profilux web page and retrieve the sensor data from it so I can store this within my RPi. Same principal applies to a esp8266 as it too is a micro web server.

Capability......
The esp8266 has 16 IO which can control outputs and connect various sensors. The simpler sensors are temperature sensors ds18b20 or the dht22 humidity/temp. Digital switch (float), digital outputs or what I am initially interested in pulse input. An LCD screen can also be attached to display data locally...

My 1st Device to test....
I already have a couple of small flow meters (futurlec web site 8l/hr. <$10.00) which I have always wanted to put on my ATO and AWC lines. The flow meters are simple devices and provide a number of pulses per litre. So the only thing you have to do is count the pulses, multiply by a factor to get litres then publish the data. I will probably also add humidity and temp as I have a spare dht22 sensor. The flow meters and esp8266 will be located outside and hopefully in range of my home wifi.

Possibilities ......
Endless :)
 

MagicJ

Moderator
Jul 11, 2011
9,650
3,761
Hobart, Tasmania
Nice timing @Rob - I purchased two of the ESP-01 modules ($3.60 each) a couple of weeks ago which should arrive next week :)

I was planning to hook them up to an Arduino Nano for some testing.
 

Rob

Member
Apr 26, 2012
743
424
@newbiereef
Caution... Very geeky intensive thread......
Maybe wait a few pages (i.e. a couple of weeks) and see the results... a picture is worth a thousand words.

@Sam Parker There was a time before reef and I was 100% committed to discus tank. On there I had auto water changes and produced a report every day/week on the amount changed and any errors that occurred.

I believe the smaller flowmeters from futurlec are used in coffee machines they have a 304 SS shaft. $9.00 1 pulse = 4ml

Now I use kalk in my ATO I am concerned on coating the optics however time will tell
FS-3000AH.jpg
 

MagicJ

Moderator
Jul 11, 2011
9,650
3,761
Hobart, Tasmania
once again English please !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
These little devices (they are actually termed a System on Chip, or SoC) contain a WiFi module that is able to connect directly to your home WiFi internet connection and, for example, upload data to a monitoring website. They can also be used to change variables via a web page. Again, for example, you could adjust your LED outputs using a phone via a web page.
 

Rob

Member
Apr 26, 2012
743
424
Received my ESP8266 in the mail today.... and have connected a humidity/temp sensor as a demo and used a sample program. This sensor a DHT22 is like ~$5.00 + the ESP8266 15.00. so for $20.00 I have a wifi enabled humidity and temp reading. Could of also used a DS18B20 submersible probe for the same price and get tank temps. I will connect my flow meter over the next few days

This is the web site (below) it is serving out, just a couple of values and links to some bitmap files. In the end I will not use it to display values (pages) like this, It will just be text values that my raspberrypi will gather for logging.

I think you can log in via my web address which I'll leave running for a little while.... www.rjconway.homeip.net:85

Web page from the ESP8266 device
8266demopage.jpg

This is the entire setup....you can see the tiny wifi antenna on the circuit board
esp.JPG



here is the sample code I used
Code:
-- Demo http server for sensor DHT22 - tested with NodeMCU 0.9.5 build 20150107
-- 1. Flash NodeMCU 0.9.5 build 20150107 or later to ESP module.
-- 2. Load program monDHT22.lua and dht22.lua to ESP8266 with LuaLoader
-- 3. You can rename the program monDHT22.lua to init.lua
-- 3. HW reset module
-- 4. Login module to your AP - wifi.setmode(wifi.STATION),wifi.sta.config("yourSSID","yourPASSWORD")
-- 5. Run program monDHT22.lua - dofile(monDHT22.lua)
-- 6. Test IP address - wifi.sta.getip()
-- 7. Test it with your browser and true IP address of module.
-- 8. The sensor is repeatedly read every minute.
-- 9. The pictures on page are external.
--10. The length of html code is limited to 1460 characters.
--11. The author of the program module dht22.lua for reading DHT sensor is Javier Yanez


--wifi.setmode(wifi.STATION)
--wifi.sta.config("replace with SSID", "replace with password")
tmr.delay(1000000)
humi="XX"
temp="XX"
fare="XX"
bimb=1
PIN = 4 --  data pin, GPIO2
--load DHT22 module and read sensor
function ReadDHT22()
   dht22 = require("dht22")
   dht22.read(PIN)
   t = dht22.getTemperature()
   h = dht22.getHumidity()
   humi=(h/10).."."..(h%10)
   temp=(t/10).."."..(t%10)
   fare=(9*t/50+32).."."..(9*t/5%10)
   print("Humidity:    "..humi.."%")
   print("Temperature: "..temp.." deg C")
   print("Temperature: "..fare.." deg F")
   -- release module
   dht22 = nil
   package.loaded["dht22"]=nil
end

ReadDHT22()
tmr.alarm(1,60000, 1, function() ReadDHT22() bimb=bimb+1 if bimb==5 then bimb=0 wifi.sta.connect() print("Reconnect")end end)

srv=net.createServer(net.TCP) srv:listen(85,function(conn)
    conn:on("receive",function(conn,payload)
   --print(payload) -- for debugging only
   --generates HTML web site
    conn:send('HTTP/1.1 200 OK\r\nConnection: keep-alive\r\nCache-Control: private, no-store\r\n\r\n\
   <!DOCTYPE HTML>\
    <html><head><meta content="text/html;charset=utf-8"><title>ESP8266</title></head>\
   <body bgcolor="#ffe4c4"><h2>Aquarium Ambient<br>DHT22 sensor</h2>\
   <h3><font color="green">\
   <IMG SRC="http://esp8266.fancon.cz/common/hyg.gif"WIDTH="64"HEIGHT="64"><br>\
   <input style="text-align: center"type="text"size=4 name="j"value="'..humi..'"> % of relative humidity<br><br>\
   <IMG SRC="http://esp8266.fancon.cz/common/tmp.gif"WIDTH="64"HEIGHT="64"><br>\
   <input style="text-align: center"type="text"size=4 name="p"value="'..temp..'"> Temperature grade C<br>\
   </body></html>')
    conn:on("sent",function(conn) conn:close() end)
    end)
end)
Im excited to get my flow meter connected up over the next few days..... What this actually means is anybody with a little tech savy can have remote tank temperature monitor without complicated hardware or programming skills...

the device has inbuilt the tcp/ip stack so two lines of code and its connected to your home wifi
--wifi.setmode(wifi.STATION)
--wifi.sta.config("replace with SSID", "replace with password")


and another line its listening for requests (in my case I set the port No to 85)
srv=net.createServer(net.TCP) srv:listen(85,function(conn)
 
Last edited:

n0rk

Member
Aug 10, 2011
412
250
Brisbane
Just be careful using code with a hardcoded plaintext password for your SSID on a web-enabled device, it's been shown to be exploitable previously for pretty serious code injection hacks on networks.

Cool concept, it's nice to see more and more SoC being used for this kind of application.
 

Buddy

Member
Mar 13, 2012
3,142
1,526
Well looks like I'll be adding this one to the list :)
Is it possible to have a temp reading for both the sump and tank?
 

Rob

Member
Apr 26, 2012
743
424
@Buddy from my reading yesterday looks like it supports multiple temperature probes using a device called a DS18B20. this is a digital addressable device, no calibration required.

this is the best probe -waterproof but its $15.00
http://littlebirdelectronics.com.au/products/temperature-sensor-waterproof-ds18b20

You can see them (search "DS18B20") on ebay for <$5.00 however I am dubious on if they really are water proof.....

I have a couple of these and I'll connect them up to test...
 

MagicJ

Moderator
Jul 11, 2011
9,650
3,761
Hobart, Tasmania
My ESP8266's arrived in the mail last week :) Whilst I have purchased a couple of the modules @Rob has pictured in the first post, I also bought a couple of the ESP-01 versions - these only break out 2 GPIO pins but at less then $4 each they represent good value and they are relatively small - around 25 x 13mm.

aencrypted_tbn1_gstatic_com_images_6fa5f155b6f3f58f4251996b5b085644._.jpg

Like Rob, I have loaded the alternative firmware, NodeMCU and used the Lua programming language.

Whilst it took a few hours to get it working, and then a couple more to work out how to increase the resolution, I now have a DS18B20 temperature sensor working as expected - I am sending the temperature every 15 seconds to Thingspeak.com - this is what the output looks like at the moment

upload_2015-9-16_21-53-42.png


Or, you can see the live output here - https://thingspeak.com/channels/55652

I will post my code (most of which has been taken from other open source projects) once I tidy a few things up.

For the cost these are a pretty impressive product - I just need to have a think about some uses for them :)

@Rob - n0rk's comment "Just be careful using code with a hardcoded plaintext password for your SSID on a web-enabled device, it's been shown to be exploitable previously for pretty serious code injection hacks on networks" - is this a genuine concern?

Is it possible to have a temp reading for both the sump and tank?
Yes, although I haven't yet tried using multiple DS18B20 sensors, the code seems to indicate that it will work. Alternatively, this module breaks out 2 GPIO pins and so you could have a sensor on each pin. Other forms of the module break out more of the pins if required.
 
  • Like
Reactions: Rob

Rob

Member
Apr 26, 2012
743
424
Nice work.. hope this inspires others to at least get their tank temperatures into the cloud and visible on their phones....

Hardcoded SSID is definitely a security risk to business and we should be careful in publicizing code, remembering to change your SSID / passphrase before posting code snippets. I have not heard of any exploits with the ESp whereby someone can hack into it and upload the SSID. Even if they did get your wifi details they obviously still need to be in range. I would suggest hackers have easier mechanism to sniff your live wifi packets and get your SSID / passphrase just by sitting outside your house. Plus in this case in not hosting the web page on the ESp and using a cloud based storage (thingspeak)there is no need to route any incomming traffic to the ESP.

So whats next to connect up ?
 

ReeferRob

Solidarité
Oct 22, 2014
2,661
931
Bel Air
I got nothing, that could have been written in Chinese and I'd have gotten the same thing out of it, lol. Cool idea, but if I were to play with that, there would be MASSIVE amounts of Magic Smoke released.:dead