Fiddling with ESP8266 (type Wemos D1) with OLED-shield (SS1306, showing 6 lines of 8 characters).
Earlier in this thread some discussion, but trying the examples was not successful.
Looking at the examples mentioned above and at my own 'inventory' of lua-scripts, I compiled the following script for experimentation with upload of info from Domoticz to the OLED of the ESP8266 running ESPEasy R146M.
This 'test-script' has 3 comparable sections, dealing with Temp, Humidity, PV-Production and Consumption, each with related UploadURL(s).
After test you
might split this 'test-script' into 4 small, separate, dedicated scripts (for each of the lines 3, 4, 5 and 6 on the OLED), or you must do something clever with the commandArray to run more than 1 UploadURL from this script:
hint appreciated.
Probably the script could be considerably shrinked, but
during experimentation some 'simple, stepwise setup with abundant comment&check lines' aids in debugging.
Code: Select all
-- Lua-script for info-upload to ESP8266 with OLED SS1306
-- (c)2017 Toulon7559 rev. 01 [but you are free to adapt the script for personal use]
-- Line 04 = Definition of function(s) and Setting of references
function round(num, dec)
if num == 0 then
return 0
else
local mult = 10^(dec or 0)
return math.floor(num * mult + 0.5) / mult
end
end
baseurl = "http://192.168.0.131/control?cmd=oled"
-- Line 16 = Call Meteo-info from Domoticz-database
Binnen_Temp_RV_Baro = 'WS7000_Temp_RV_Baro'
sTemp, sRV, sComfort, sBaro = otherdevices_svalues[Binnen_Temp_RV_Baro]:match("([^;]+);([^;]+);([^;]+);([^;]+)")
sTemp = round(tonumber(sTemp),1);
print ('Temp = '.. sTemp)
sRV = round(tonumber(sRV),1);
print ('RV = '.. sRV)
sComfort = tonumber(sComfort);
print ('Comfort = '.. sComfort)
sBaro = tonumber(sBaro);
print ('Baro = '.. sBaro)
UploadURL0A = baseurl .. ",3,1,T=".. sTemp .."C"
UploadURL0B = baseurl .. ",4,1,V=".. sRV .."%"
print (UploadURL0A)
print (UploadURL0B)
-- Line 33 = Call Production-info from Domoticz-database
Production = 'PVO_Generation_A7'
sPwr1, sEnergy1 = otherdevices_svalues[Production]:match("([^;]+);([^;]+)")
sPwr1 = round(tonumber(sPwr1),0);
print ('Pwr1 = '.. sPwr1)
sEnergy1 = round(tonumber(sEnergy1),0);
print ('Energy1 = '.. sEnergy1)
UploadURL1 = baseurl .. ",5,1,PV=".. sPwr1 .."W"
print (UploadURL1)
-- Line 44 = Call Consumption-info from Domoticz-database
Consumption = 'PVO_Consumption_A7'
sPwr2, sEnergy2 = otherdevices_svalues[Consumption]:match("([^;]+);([^;]+)")
sPwr2 = round(tonumber(sPwr2),0);
print ('Pwr2 = '.. sPwr2)
sEnergy2 = round(tonumber(sEnergy2),0);
print ('Energy2 = '.. sEnergy2)
UploadURL2 = baseurl .. ",6,1,In=".. sPwr2 .."W"
print (UploadURL2)
-- Line 55 = Perform upload
commandArray = {}
commandArray['OpenURL']= UploadURL0A
-- commandArray['OpenURL']= UploadURL0B
-- commandArray['OpenURL']= UploadURL1
-- commandArray['OpenURL']= UploadURL2
return commandArray
This script fills the lines of the OLED at choice for lines 3, 4, 5 and 6, but further improvement is certainly possible, as described below.
Note1:
Experience with this script is that no spaces are allowed in the UploadURLs in the segments between ""
If you insert a space in such segment, then (starting with the space) no further info is displayed.
This in contrary to running such a line from the inputline of a browser: then a space is accepted.
Adding leading zeroes is a solution also providing a fixed length filling of the OLED-line.
Could be realised (e.g. for PV-production) by addition of following simple "if-then"-code-lines.
Code: Select all
if sPwr1 > 999 then
UploadURL1 = baseurl .. ",5,1,PV=".. sPwr1 .."W"
else UploadURL1 = baseurl .. ",5,1,PV=0".. sPwr1 .."W"
end
if sPwr1 <100 then
UploadURL1 = baseurl .. ",5,1,PV=00".. sPwr1 .."W"
end
if sPwr1 <10 then
UploadURL1 = baseurl .. ",5,1,PV=000".. sPwr1 .."W"
end
Also slight problem for
nil-value-input for PV (as happening at night): with this script you get an error-report related to 'empty' variable num.
Subtle difference with a
0-value-input, which is happily accepted.
Note2:
According to the printoutputs the script is OK, see below a log-extract from Domoticz
Code: Select all
2017-02-22 19:55:00.438 LUA: Temp = 20.8
2017-02-22 19:55:00.438 LUA: RV = 48
2017-02-22 19:55:00.438 LUA: Comfort = 1
2017-02-22 19:55:00.438 LUA: Baro = 1000
2017-02-22 19:55:00.438 LUA: http://192.168.0.131/control?cmd=oled,3,1,T=20.8C
2017-02-22 19:55:00.438 LUA: http://192.168.0.131/control?cmd=oled,4,1,V=48%
2017-02-22 19:55:00.438 LUA: Pwr1 = 0
2017-02-22 19:55:00.438 LUA: Energy1 = 14812156
2017-02-22 19:55:00.438 LUA: http://192.168.0.131/control?cmd=oled,5,1,PV=0W
2017-02-22 19:55:00.438 LUA: Pwr2 = 432
2017-02-22 19:55:00.439 LUA: Energy2 = 37099768
2017-02-22 19:55:00.439 LUA: http://192.168.0.131/control?cmd=oled,6,1,In=432W
2017-02-22 19:55:00.439 EventSystem: Fetching url...
2017-02-22 19:55:00.439 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_time_ESP8266F_upload01.lua
The info from the UploadURL appears at the OLED,
but nevertheless you get an error report in the log
Code: Select all
2017-02-22 19:55:00.751 Error: Error opening url: http://192.168.0.131/control?cmd=oled,3,1,T=20.8C
Puzzles remain ............