HTTP request to get the current LCDdisplay

Hi all,

Is there a HTTP request to get the current values as displayed in the LCD section in JSON format? (I presume that’s how the web client gets is anyway).

Also, sorry if it’s in a really obvious location, but is there anywhere that describes the available API calls to the BrewPi backend?

I’m putting together a basic home automation system (with Domoticz) and it’d be nice to display my fermenter status in there too.

Cheers,
Karl.

To answer my own question, you need to make a POST request like this:

http://server:port/socketmessage.php
And parameter:
messageType=lcd

E.g. you can use curl from the command line (OS X and linux):

curl --data “messageType=lcd” http://server:port/socketmessage.php

1 Like

:+1: Thanks for following up with the answer - doing that will contribute to the sum of knowledge available here!

I am also using domoticz which rises my curiosity. Is there an easy way to get the data into domoticz using the URL posted above. Is it through a LUA script then? Do you have an example?

I’m only getting started with Domoticz myself, but from what I understand you’re correct - it would be necessary to write a script to poll the BrewPi server and update a Domoticz dummy device.

I haven’t had a chance to work on it yet, but I’ll update here when I do.

1 Like

Any progress regarding this? I tried a bit myself but ran into a brick wall.

Looks like the response I am getting from “curl --data “messageType=lcd” http://10.0.0.70:80/socketmessage.php” is simply 0.

Edit, I ws wrong, I am getting the right data with curl:

["Mode   Beer Const.  ", "Beer    1.0   1.0 &degC", "Fridge  0.3  -0.5 &degC", "Idling for     10m58"]

If I just type “http://10.0.0.70:80/socketmessage.php” in a browser I get “messageType not set” Shouldn’t something like “http://10.0.0.70:80/socketmessage.php?messageType=lcd” work?

There seems to be more info here: Brewpi Spark Wishlist

Anyone worked this out?

Edit:
I am working with a zwave based home automation system, the main part of this is the micasaverde vera. I am trying to come up with a luup script which collects these infos and writtes them to a dummy device. This would allow be to remotly check if everything is ok and even get messages of an independat system if something goes down.

Also got the “MessageType not set” when i tried.

I am really wondering why “http://10.0.0.70:80/socketmessage.php?messageType=lcd” is not working, it just returns “messageType not set”. What am I missing?

It is pretty easy to realize a lua script with luup.inet.wget() on the micasaverde vera, and then parse the data into a dummy device. But for some reason it does not seem to be possible to get data from curl, at least I am not able to figure this out.

Edit:
With the following lua script I am now able to read the date. The parsing and sending to the dummy device is not solved yet, but it’s a step forward:

    --VARIABLES
local ipAddress = "10.0.0.70"
local port = 80
local DEBUG_MODE = true


--FUNCTIONS
local function log(stuff, level)
  luup.log("BrewPi: " .. stuff, (level or 50))
end
  
local function debug(stuff)
  if (DEBUG_MODE) then
    log("debug " .. stuff, 1)
  end
end


--READING FROM BREWPI
json = require('json-dm')
curlcommand = "curl --data \"messageType=lcd\" http://" .. ipAddress .. ":" .. port .. "/socketmessage.php"
debug("CURLCALL COMMAND: " .. curlcommand)
local handle = io.popen(curlcommand)
local result = handle:read("*a")
handle:close()
debug("Reading from BrewPi SECOND: " .. result)

Voila, here is my finished lua script, I am no real developer, I am sure ther would be nicer solutions but it works. As said this is used on a micasaverde vera, the dummy device is a so called VariableContainer. Basically the script gets the data from the raspberry through the curl command. The data is then seperated an written into a table, from the table the data is written to the dummy device.

--VARIABLES
local ipAddress = "10.0.0.70"
local port = 80

--FUNCTIONS
function totable(inputstr, sep)
   local t={} ; i=1
   for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
           t[i] = str
           i = i + 1
   end
   return t
end

--READING DATA FROM BREWPI
json = require('json-dm')
curlcommand = "curl --data \"messageType=lcd\" http://" .. ipAddress .. ":" .. port .. "/socketmessage.php"
local handle = io.popen(curlcommand)
local result = handle:read("*a")
handle:close()

--PARSING / WRITING DATA TO TABLE
parsed = totable(result, "%s")

--WRITTING TO DUMMY DEVICE
setVCvar(104,1,"" .. parsed[13] .. " " .. parsed[14] .. " " ..parsed[15])
setVCvar(104,2,parsed[7])
setVCvar(104,3,parsed[6])
setVCvar(104,4,parsed[11])
setVCvar(104,5,parsed[10])

The dummy device on the Micasaverde Vera:

Nice work!

Btw, I believe the error message about “messageType not set” is because you were adding it to the URL - it needs to be part of the POST payload, hence the --data “messageType=lcd”

This is my contribution. A Script to get all data to Domoticz. Feel free to use it as you like.
I am no programmer so things might be done in a smarter way but it works. It even takes care of the different work modes on the BrewPi. Tried to comment most of it for easy reading. It also prints alot to Domoticz log for debugging.
My Domoticz is run on a Raspberry Pi.

Save the script in “/scripts/lua/” folder as “script_device_brewpi.lua” and do not forget to change the idx numbers to match your dummy devices.

------------------------------------------------------------------------
--BrewPi reader by Mikael Blom
--2015-09-14
--Version 1.0 RC1
------------------------------------------------------------------------

commandArray = {}

------------------------------------------------------------------------
--All Variables for easy config
------------------------------------------------------------------------
-- BrewPi2IP="192.168.1.103"
-- BrewPi2Port="80"
tempfile = '/var/tmp/tempfile.tmp'

-- idx of dummy devices in Domoticz
local idxBrewPiRoomTemp = 79
local idxBrewPiBeerTemp = 80
local idxBrewPiBeerSetTemp = 81
local idxBrewPiFridgeTemp = 82
local idxBrewPiFridgeSetTemp = 83
local idxBrewPiMode = 84
local idxBrewPiStatus = 85

------------------------------------------------------------------------
--Printing for LOG debug
-----------------------------------------------------------------------
print("-------------------------------------------");
print("------ Brewpi Status Script started -------");
print("-------------------------------------------");

------------------------------------------------------------------------
-- Check if brewpi is online and execute
------------------------------------------------------------------------

 ping_success=os.execute("ping -c1 " .. BrewPi2IP .. "")
 if ping_success then
   print ("BrewPi Ping: BrewPi is ONLINE")
   --Read data from BrewPi to tempfile
	file = io.open(tempfile, "w+") -- Clearing file
	--curlcommand = os.execute('curl --data messageType=lcd http://192.168.1.103:80/socketmessage.php >' ..tempfile)
	curlcommand = os.execute('curl --data messageType=lcd http://192.168.1.103:80/socketmessage.php >' ..tempfile)
	response = file:read("*a")
	file:close()

		--print ("Debug: " .. response .. " ") -- Print complete string for debug
	
		-- Format same as BrewPi LCD
		sRow1 = string.match(response, '%"(.-)%"')
		sRow2 = string.match(response, '%".-%",.-%"(.-)%"')
		sRow3 = string.match(response, '%".-%",.-%".-%",.-%"(.-)%"')
		sRow4 = string.match(response, '%".-%",.-%".-%",.-%".-%",.-%"(.-)%"')
	
		--Print complete formatted LCD info for debug
		--print("-------------------------------------------");	
		--print("BrewPi Status: " .. sRow1 .. "")
		--print("BrewPi Status: " .. sRow2 .. "")
		--print("BrewPi Status: " .. sRow3 .. "")
		--print("BrewPi Status: " .. sRow4 .. "")
		--print("-------------------------------------------");	
		
		-- Print status
		sBrewPiMode = sRow1 -- BrewPi Mode
		print("BrewPi Mode: " .. sBrewPiMode .. ""); -- Print BrewPi Mode
		commandArray[1] = {['UpdateDevice'] = idxBrewPiMode .. "|0|" .. sRow1}
		sRow1InfoType = string.match(sBrewPiMode, '%a+%s*(%a+)') --Get BrewPi Mode without extra text (Beer or Fridge)
		
		
		
		sBrewpiStatus = sRow4 --BrewPi Status
		print("BrewPi Status: " .. sRow4 .. ""); -- Print BrewPi Status
		commandArray[2] = {['UpdateDevice'] = idxBrewPiStatus .. "|0|" .. sRow4}
				
		-- Match Beer Temp
		sBrewPiBeerTemp = string.match(sRow2, '(-?%d+.%d+)') -- Get Beer temp
		print("BrewPi Beer Temp: " .. sBrewPiBeerTemp .. " °C");
		commandArray[3] = {['UpdateDevice'] = idxBrewPiBeerTemp .. "|0|" .. sBrewPiBeerTemp}
				
		-- Match Beer Set Temp
		
		if sRow1InfoType == "Beer" then
			sBrewPiBeerSetTemp = string.match(sRow2, '%d+.%d+%s*(-?%d+.%d+)') -- Get Beer Set temp
			print("BrewPi Beer Set Temp: " .. sBrewPiBeerSetTemp .. " °C");
			commandArray[4] = {['UpdateDevice'] = idxBrewPiBeerSetTemp .. "|0|" .. sBrewPiBeerSetTemp}
		end
		
		 --Get which type of temp it is on Row3 (Room or Fridge)				
		sRow3InfoType = string.match(sRow3, '(%a+)')
			
		--Get Room temp if sRow3InfoType = Room
		if sRow3InfoType == "Room" then 
			sBrewPiRoomTemp = string.match(sRow3, '(-?%d+.%d+)') -- Get Room temp
			print("BrewPi Room Temp: " .. sBrewPiRoomTemp .. " °C") -- Print BrewPi Room temp
			commandArray[5] = {['UpdateDevice'] = idxBrewPiRoomTemp .. "|0|" .. sBrewPiRoomTemp}
		end
	
		--Get Fridge temp if sRow3InfoType = Fridge
		if sRow3InfoType == "Fridge" then 
			
			sBrewPiFridgeTemp = string.match(sRow3, '(-?%d+.%d+)') -- Get Fridge temp
			print("BrewPi Fridge Temp: " .. sBrewPiFridgeTemp .. " °C") -- Print BrewPi Fridge Temp
			commandArray[6] = {['UpdateDevice'] = idxBrewPiFridgeTemp .. "|0|" .. sBrewPiFridgeTemp}
			
			sBrewPiFridgeSetTemp = string.match(sRow3, '%d+.%d+%s*(-?%d+.%d+)') -- Get Fridge Set temp
			print("BrewPi Fridge Set Temp: " .. sBrewPiFridgeSetTemp .. " °C") -- Print BrewPi Fridge Set Temp
			commandArray[7] = {['UpdateDevice'] = idxBrewPiFridgeSetTemp .. "|0|" .. sBrewPiFridgeSetTemp}
		end	
end
print("-------------------------------------------");
return commandArray
1 Like

Is this still working for you @Blom1974? Seems like I don’t get any response since updating to release 0.4.0. But I have not analysed anything so far since I am not at home. Looks like there is no repsonse from the BrewPi.

Yes. It works ok on 0.4.0. I see no changes in the output.

1 Like

Thank you for the fast feedback! Seems like the output has changed a little.

With my “not so proffesional” parsing I had to adjust what was beeing parsed into the virtual variables:

--VARIABLES local ipAddress = "10.0.0.70" local port = 80 local DEBUG_MODE = false

–FUNCTIONS
function totable(inputstr, sep)
local t={} ; i=1
for str in string.gmatch(inputstr, “([^”…sep…"]+)") do
t[i] = str
i = i + 1
end
return t
end

local function log(stuff, level)
luup.log("BrewPi: " … stuff, (level or 50))
end

local function debug(stuff)
if (DEBUG_MODE) then
log("debug " … stuff, 1)
end
end

–READING DATA FROM BREWPI
json = require(‘json-dm’)
curlcommand = “curl --data “messageType=lcd” http://” … ipAddress … “:” … port … “/socketmessage.php"
local handle = io.popen(curlcommand)
local result = handle:read(”*a")
handle:close()
debug("Reading from BrewPi SECOND: " … result)

–PARSING / WRITING DATA TO TABLE
parsed = totable(result, “%s”)

–WRITTING TO DUMMY DEVICE
setVCvar(104,1,"" … parsed[11] … " " … parsed[12] … " " …parsed[13])
setVCvar(104,2,parsed[7])
setVCvar(104,3,parsed[6])
setVCvar(104,4,parsed[10])
setVCvar(104,5,parsed[9])

Hi @Blom1974 ! I’m actually using your code and everything is still working with latest brewpi version.
I’ve got only one problem: in my logs I get these error

2016-08-27 09:56:00.358 Error: EventSystem: in brewpi: [string "---------------------------------------------..."]:105: attempt to concatenate global 'sBrewPiFridgeSetTemp' (a nil value)

I guess this is because brewpi mode is OFF, so set temp is not present.

Any idea how could I clean the code to avoid it?

And also, I’ve created a dummy hardware with dummy devices for temps. Any change to get text strings also? I’d love to see all temperatures and brewpi status too.

Sorry but I’m very new to this and while I understand the code, it’s beyond my possibility to try to correct it :frowning:

Thanks so much for your work!

I have not done any further work on the code so far. Can you maybe specify how far your code is working, have you done any changes? I don’t think it will work for anybody like I have posted it. I am using a “variable container”, a plugin I had published on apps.mios.com, but I pulled it since I was not able to agree with micasaverde (replacement is http://apps.mios.com/plugin.php?id=8231).

Where do you get that log, on vera or brewpi?

Forgot that I did change the code a while ago. The main reason was to get the temperatures in real or rather floating numbers. I am comparing the beer target and is temperatures with PLEG, then I use VeraAlerts to send me notifications to my cell phone in case anything is not OK. Here is my current code (I am no programmer!!):

--SETUP
local ipAddress = "10.0.0.71"
local port = 80

--READING DATA FROM BREWPI
json = require('json-dm')
curlcommand = "curl --data \"messageType=lcd\" http://" .. ipAddress .. ":" .. port .. "/socketmessage.php"
local handle = io.popen(curlcommand)
local result = handle:read("*a")
handle:close()

--EXTRACTING TEMPERATURES / WRITING DATA TO TABLE
temperatures = {}
for temperature in string.gmatch(result, "[%d+]+[%.]+[%d+]") do table.insert(temperatures, temperature) end
words = {}
for word in string.gmatch(result, "%w+") do table.insert(words, word) end

--WRITTING TO DUMMY DEVICE
setVCvar(104,1,"" .. words[14] .. " " .. words[15] .. " " ..words[16])
setVCvar(104,2,temperatures[1])
setVCvar(104,3,temperatures[2])
setVCvar(104,4,temperatures[3])
setVCvar(104,5,"" .. words[1] .. " " .. words[2] .. " " ..words[3])

So if I read your log correctly this happens on the vera itself, propably since PLEG tries to compare a string to a number. But I have to check this at home, I can not put my BrewPi in Off-Mode from work. An since the vera itself is programed so bad, it blocks everything once it has an error like this.

The version above also writes the mode and the current state of the BrewPi into a variable. Basically I parse all the information into tables, but then I only send the information I care about to the dummy device. If you need further information you can use the following debug version, this will show you all the information of what I get from vera:

--SETUP
local ipAddress = "10.0.0.71"
local port = 80
local DEBUG_MODE = true

--BASIC FUNCTIONS
local function log(stuff, level)
  luup.log("BrewPi: " .. stuff, (level or 50))
end
  
local function debug(stuff)
  if (DEBUG_MODE) then
    log("debug " .. stuff, 1)
  end
end

--READING DATA FROM BREWPI
json = require('json-dm')
curlcommand = "curl --data \"messageType=lcd\" http://" .. ipAddress .. ":" .. port .. "/socketmessage.php"
local handle = io.popen(curlcommand)
local result = handle:read("*a")
handle:close()
debug("Reading from BrewPi SECOND: " .. result)

--EXTRACTING TEMPERATURES / WRITING DATA TO TABLE
temperatures = {}
for temperature in string.gmatch(result, "[%d+]+[%.]+[%d+]") do table.insert(temperatures, temperature) end
words = {}
for word in string.gmatch(result, "%w+") do table.insert(words, word) end

--WRITTING TO DUMMY DEVICE
setVCvar(104,1,"" .. words[14] .. " " .. words[15] .. " " ..words[16])
setVCvar(104,2,temperatures[1])
setVCvar(104,3,temperatures[2])
setVCvar(104,4,temperatures[3])
setVCvar(104,5,"" .. words[1] .. " " .. words[2] .. " " ..words[3])

debug("Tabelle 1: " .. temperatures[1])
debug("Tabelle 2: " .. temperatures[2])
debug("Tabelle 3: " .. temperatures[3])
debug("Tabelle 3: " .. words[1])
debug("Tabelle 3: " .. words[2])
debug("Tabelle 3: " .. words[3])
debug("Tabelle 3: " .. words[4])
debug("Tabelle 3: " .. words[5])
debug("Tabelle 3: " .. words[6])
debug("Tabelle 3: " .. words[7])
debug("Tabelle 3: " .. words[8])
debug("Tabelle 3: " .. words[9])
debug("Tabelle 3: " .. words[10])
debug("Tabelle 3: " .. words[11])
debug("Tabelle 3: " .. words[12])
debug("Tabelle 3: " .. words[13])
debug("Tabelle 3: " .. words[14])
debug("Tabelle 3: " .. words[15])
debug("Tabelle 3: " .. words[16])

But there are diffculties. The first one is that BrewPi alters the room-temperature and the fridge temperature on one variable, so you will never reall know what you get since it depends on the moment you ask for it. Another one is that it is difficult to seperate that string into different parts (at least for me…).