[code]local http = require(“socket.http”)
http.TIMEOUT = 5
local status, userCode = luup.inet.wget(“http://192.168.1.153/arduino/analog/3”,5)
–userCode=‘Pin A2 reads analog 400’
local i = userCode:match('Pin (.-) ')
local nString = userCode:match(‘analog (.-)’)
local n = tonumber(nString)
if n > 500
then
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”,“Variable1”,“” … n … “”,312)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },161)
end
[/code]
With this code I can extract A2 but not the number 400 in the end.
I assume it’s because there is no stop character available:
userCode:match(‘analog (.-)[glow=red,2,300]_[/glow]’)
But how can I do it?
Btw. Will this work with a variable?
local n = tonumber(nString)