Send data to Domoticz in JSON format via POST requests method (by HTTP)

Others (MiLight, Hue, Toon etc...)

Moderator: leecollings

Post Reply
Dykus
Posts: 1
Joined: Friday 26 October 2018 21:30
Target OS: Linux
Domoticz version:
Contact:

Send data to Domoticz in JSON format via POST requests method (by HTTP)

Post by Dykus »

Hello all!

I would like to send data to virtual sensors in the Domoticz server directly from GSM modem (via GPRS and internet). I can not do this with AT commands (to GSM modem) now, but I think that I have a problem with HTTP request.

Is it possible to send data to Domoticz in JSON format via POST requests?

I'm trying to use POSTMAN (for Chrome) for this. I tried different entries, eg.
POST http://8x.xx.xx.xx2:8080/json.htm
HEADERS:
Accept: application/json
Content-Type: application/json
Content-Length: 67
BODY
{"type":"command","param":"switchlight","idx":"1","switchcmd":"On"}


I receive status from the server: 200 OK, but the answer is:
{
"status": "ERR"
}


If I open link in my browser:
http://8x.xx.xx.xx2:8080/json.htm?type= ... itchcmd=On
then everything works fine and the virtual sensor's state changes. I receive a response from the server:
{
status: "OK",
title: "SwitchLight"
}


I found info on WIKI about JSON through a browser or programmatically from a scripting language, eg.
http://192.168.1.2:8080/json.htm?type=c ... &svalue=79
but I can not send it from a GSM modem.

Thanks for any tips.

My Domoticz works on the virtual cloud server with public IP. System - Debian 3.16 (x86/64). Domoticz v4.9701.
Domoticz reports a problem with dynamic Python libraries, but I think that's not a problem.
I send the requests from Chrome on Windows 10.

For information - my sets of AT commands sent to GSM modem after establishing a GPRS connection:
Method 1:

Code: Select all

AT+HTTPINIT
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","http://8x.xx.xx.xx2:8080/json.htm"
AT+HTTPPARA=REDIR,1
AT+HTTPPARA="Content","application/json"
AT+HTTPDATA=67,20000
{„type”:”command”,”param”:”switchlight”,”idx”:1,”switchcmd”:”On”}
AT+HTTPACTION=1
>>> response: 200 OK - data received by the server, but no effect
Method 2:

Code: Select all

AT+CIPSHUT
AT+CIPMUX=0 
AT+CSTT="internet"
AT+CIICR
AT+CIPSTART= "TCP","8x.xx.xx.xx2","8080"
AT+CIPSEND
POST /json.htm HTTP/1.1
Host: 8x.xx.xx.xx2
Content-Type: application/json
Content-Length: 67
{„type”:”command”,”param”:”switchlight”,”idx”:1,”switchcmd”:”On”}
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest