Friday, March 24, 2017

Thingspeak - SmartMon Ext Board P4

This is Part 4 of the SmartMon Extension Board series.

SmartMon v2.7ex Board  is a extension board fully compatible with Arduino, ESP8266, ARM, PIC & other available MCu's out there.  As long as your MCU/Dev Board has I2C Bus capabilities you are good to go!
It is probably one of the easiest ways to create your own Voltage/Current and Power consumption monitoring system for your Projects, devices, batteries, power supplies and many more!


UPDATE !! SmartMon v2.7Ex is available also on Tindie Store !





This time we will go thru a full example on how to monitor your power line and load, read Voltage/Current and Power consumtion data and upload them on the Thingspeak related Channel.

Previous Articles:


What we will need:


Software implementation:

Thingspeak channels or standalone Thingspeak Server setup part is not covered in this article.
 If interested to see how can be done a standalone Thingspeak Server, please take a look here:
1. RaspberryPI - Standalone Thingspeak Server install
2. RaspberryPI2 - Thingspeak Server install on Jessie 


To make it running, you need also the function from the previous article:

Part 3: INA219 Driver and a simple data read example 


Send data to Thingspeak function
function sendDataTh()
    print("Sending data to thingspeak.com")
    conn=net.createConnection(net.TCP, 0)
        conn:on("receive", function(conn, payload) print(payload) end)
        -- api.thingspeak.com 184.106.153.149
        conn:connect(80,'184.106.153.149')
        conn:send('GET /update?key=T89U8XLJDPQTW0AR&field1='..volt..'&field2='..current..'&field3='..power..'&field4='..peng..'HTTP/1.1\r\n')
        conn:send('Host: api.thingspeak.com\r\n')
        conn:send('Accept: */*\r\n')
        conn:send('User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n')
        conn:send('\r\n')
        conn:on("sent",function(conn) print("Closing connection")
        conn:close()
    end)
    conn:on("disconnection", function(conn) print("Got disconnection...")
    end)
end 


Main Program
---- INA216 Module TEST
init_i2c()
setCAL_reg()
print_values()
If you want to read and update values every minute add function from below:
tmr.alarm( 1, 60000, 1, function()
     print_values()
     sendDataTh()
end)
You can stop your running timer anytime with:
tmr.stop(1)

No comments:

Post a Comment