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 that you accept these cookies being set.

Control Camera Notification Status
#1
Hi to all.




I am looking for some help on how to create a library in order to call some functions provided by the Synology Surveillance Station API found here.

[url=http://global.download.synology.com/download/Document/DeveloperGuide/Surveillance_Station_Web_API_v2.0.pdf][/url]

The idea is to be able to turn on/off the notification setting of this recorder, so for example, if I arm my alarm system, the KNX bus knows, so through a relative LM script I can then enable the camera recorder to start sending me notification emails (i.e if movement detection), and if I disarm the alarm, the script will disable the notifications.

In the recorder API documentation I understand that it support control through JSON commands and more specifically, I need to modify each time the boolean parameter "mailEnable" of the "SetSetting" Method (page 243) like this:



GET /webapi/entry.cgi?

mailEnable=1 (or 0 accordingly)



Also as I understand from the NetATMO scripting presented at another thread, this must be similar with what I am looking for, but since I am a very new at programming (and LUA and LM in general) can somebody help me with some basic guidelines to start a little faster?



Thank you all in advance.
Reply
#2
You can use LuaSocket to do HTTP requests:
http://w3.impa.br/~diego/software/luasoc...ml#request

Your code should look like this (replace 1.2.3.4 with your Synology device IP):
Code:
require('socket.http')
socket.http.TIMEOUT = 5
data = socket.http.request('http://1.2.3.4/webapi/entry.cgi?mailEnable=1')
Reply
#3
Thank you for your reply.
I tried this but it didn't work because as I saw in the API documentation, you have first to login to the synology like this:

GET /webapi/auth.cgi?

api=SYNO.API.Auth&method=Login&version=2&account=USERNAME&passwd=PASSWORD&session=SurveillanceStation&format=sid

or in LUA according to your example, it will be something like this:


Code:
data = socket.http.request('http://1.2.3.4/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=2&
account=USERNAME&passwd=PASSWORD&session=SurveillanceStation&format=sid')

Then you have to get the sid that will be returned as a response to the above request (GET) command and use it to all other calls you made like this:
Code:
data = socket.http.request('http://1.2.3.4/webapi/entry.cgi?mailEnable=1_sid=Jn5dZ9aS95wh2')

Now in order to insert in the string above the sid response that I would have previously get as data, should I try something like this?:

local request_body = "http://1.2.3.4/webapi/entry.cgi?mailEnable=1_sid=".. data
and then send this?:

data = socket.http.request(request_body)

??
Reply
#4
The easiest way is to do auth request in your browser and check response format. If you get just raw sid value then next request is simple:
Code:
url = "http://1.2.3.4/webapi/entry.cgi?mailEnable=1&_sid=".. data
data = socket.http.request(request_body)

Otherwise, post response here and we will help you with parsing it Wink
Reply
#5
I just tried in the browser and I got this:
{"data":{"sid":"IuGC4XNPXTzfkB3J4N01003"},"success":true}
Smile
So how can i get only the sid part out of the response??
Reply
#6
It looks like JSON type string, so the easiest way is to use already existed library, so:


Code:
local json = require "json"



stringfromsynology = [[{"data":{"sid":"IuGC4XNPXTzfkB3J4N01003"},"success":true}]]
local t = json.decode( stringfromsynology)

log(t) -- here you can see what json library done
if t.success == true then
 sid_number = t.data.sid
end
log (sid_number)
Reply
#7
(31.08.2015, 19:04)Pawel Wrote: It looks like JSON type string, so the easiest way is to use already existed library, so:


Code:
local json = require "json"



stringfromsynology = [[{"data":{"sid":"IuGC4XNPXTzfkB3J4N01003"},"success":true}]]
local t = json.decode( stringfromsynology)

log(t) -- here you can see what json library done
if t.success == true then
 sid_number = t.data.sid
end
log (sid_number)

Thanks a ton Pawel. I will give it a try this weekend and report back results!
Reply


Forum Jump: