Jump to content
C4 Forums | Control4

iOS Push Notification - Lua programming HTTP POST request


HNA

Recommended Posts

Hello everybody,

 

I'm just trying to program a C4 driver which can send push notifications to your/my iphone or ipad on certain events. That would be way better than an email as you see the messages instantaneous! For example: "Your rack room is overheating".

The push service  "http://pnotify.com" offers is pretty nice service.

 

Right now, I'm trying to program an independent Lua script for the HTTP POST request to the pnotify server. But even this first"part" of the C4 driver doesn't behave like I want it to.

 

The only way to do this - I think - is, to use the LuaSocket module by starting the script: 

require "socket.http"

 

My first question is: Are there any Lua modules installed on my HomeController like "socket"? Is there another way to send HTTP POST requests? Normal HTTP GET requests also work, i.e. for IP cameras.

 

I don't get the script to run and send the request.

 

For more information about the module visit: http://w3.impa.br/~diego/software/luasocket/http.html#request

 

There are two possibilities to use the module: a simple and a generic interface. Both don't work for me.

 

Simple interface:

 

local http require'socket.http'
http.request("http://pnotify.com/submit/CODE","title=test&detail=helllloooo")
 
Generic interface:
 
require 'socket.http'
 
local request_body = [[title=test&detail=hello]]
 
local response_body = { }
 
local res, code, response_headers = socket.http.request
{
  method = "POST";
  headers = 
  {
    ["Content-Type"] = "application/x-www-form-urlencoded";
    ["Content-Length"] = #request_body;
  };
  source = ltn12.source.string(request_body);
  sink = ltn12.sink.table(response_body);
}
 
My second question is: Where do I put the parameters "title" and "detail"? I've also tried: http://pnotify.com/submit/CODE?title=test&detail=helllloooo
 
 
 
My programming skills aren't the best and I don't know much about Lua or HTTP POST requests. I just hope that someone out there is able to help me. In my opinion this would be helpful for lots of people.
 
Thanks in advance and a happy new year to all of you!!
 
FS
Link to comment
Share on other sites


Um... There are already several drivers that do exactly that. One of them even uses Push Notify! Unless you want to reinvent it, try one of those. They work great and the work has already been done.

Sent from my Droid MAXX via Tapatalk.

Link to comment
Share on other sites

Push Notify is Seth's which uses prowl and Notify My Android.

 

Phone Notify is mine which uses phone notify (http://pnotify.com)

 

Both pretty much do the same thing so use whatever one you want.  Making it was pretty simple as well so if you want to redevelop then it makes a good first driver to sink your teeth into.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.