This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

WebCGI Trigger
i am a new user of LM & Lua.

Question: How can i trigger a Web CGI by a switch?

Example: If the input state of a the switch "XY" from  0 to 1 trigger : world!!

If possible step by step for beginners...

Many Thanks!
Try the code below and see what you get in the log. That's the response from your system. Please change the url to the correct url to make it work.

local http = require "socket.http"

local data = ""

local function collect(chunk)
if chunk ~= nil then
data = data .. chunk
return true

local ok, statusCode, headers, statusText = http.request {
method = "GET",
url = "",
sink = collect

log("ok\t", ok);
log("statusCode", statusCode)
log("statusText", statusText)
for i,v in pairs(headers) do
log("\t",i, v)

log("data", data)
Many Thanks for your message.
I will test it.

(12.01.2020, 20:50)JXA Wrote: Many Thanks for your message.
I will test it.


i have tested the code.
But is still not working.

# This is a  trigger Message to a SMS Gateway, you can send SMS by WebCGI only with a simple SIM Card!

"Event for Fensterkontakt  - Button A (1/1/20) 14.01.2020 14:29:08
* arg: 1
  * string: data
* arg: 2
  * string: <HTML><HEAD><TITLE>400 Bad Request</TITLE></HEAD>
<BODY><H1>400 Bad Request</H1>
Your client has issued a malformed or illegal request.

If you trigger by a Browser all is fine!

Any Idea what's wrong? "Bad Request"


Attached Files Image(s)
Your end device might expect some headers or some headers are not handled properly by it. You can try sending raw request without any headers like this:
ip = ''
qs = '/cgi/WebCGI?1500101=account=apiuser&password=password&port=1&destination=15880270900&content=Hello'

sock = require('socket').tcp()

res, err = sock:connect(ip, 80)
if res then
  sock:send('GET ' .. qs .. ' HTTP/1.1\r\n\r\n')
  res = sock:receive('*a')
  log(res, err)

Open dev tools in browser (F12), go to Network tab, right click the request and select "Copy headers". This data can be used to send exactly the same request from LM.
yes the code is working fine without any changes.

But i still have 2 questions:

About the SMS Message    "...... content=Hello this is a test SMS"
-> if you have Space character in your Message it will not be send. (sending via Browser works fine)
Any Placeholder required in Lua?

How can i send the Input Status (0/1) as "var" in the SMS Content?
--> '...... content=Hello the Input status is "var" '    (var means 0 or 1)

Many Thanks for your support!
If using an event script you can use event.getvalue() to add current value to content variable. Use socket.url.escape to convert spaces and other characters to correct escape sequences.

value = event.getvalue()
content = 'Input status is ' .. tostring(value)
content = socket.url.escape(content)
qs = '/cgi/WebCGI?1500101=account=apiuser&password=password&port=1&destination=15880270900&content=' .. content

Forum Jump: