• 10 dec 2017: forum version update. In case of issues use this topic.
  • 30 nov 2017: pilight moved servers. In case of issues use this topic.
Hello There, Guest! Login Register


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pilight-daemon answers json request with html page
#1
Hello,

I want to query the pilight-daemon via the JSON API described in the manual (https://manual.pilight.org/en/api).
I have set up the daemon to listen on port 5000, which basically works, i.e., the server (url: http://servername:5000) answers on requests.

However, when I send (POST) a JSON message
Code:
{"action":"identify"}

the daemon returns a http webpage referring to the builtin webserver:
Code:
<html><head><title>pilight</title></head><body><center><img src="logo.png"><br /><p style="color: #0099ff; font-weight: 800px;font-family: Verdana; font-size: 20px;">The pilight webgui is located at <a style="text-decoration: none; color: #0099ff;font-weight: 800px; font-family: Verdana; font-size:20px;" href="http://10.0.0.xxx:5001">http://10.0.0.xxx:5001</a></p></center></body></html>

I use the Addon HttpRequester for Firefox to send the JSON code above as content-type "application/json". The same happens when using curl from command line.

What did I wrong? Has the API changed from 6.0 to 7.0?

I use pilight 6.0, the version by wo_rasp with support for OregonScientific sensors (see https://forum.pilight.org/Thread-Oregon-...ght=oregon).

Thanks for your hints!

Cheers
Michib
 
Reply
#2
Make sure you don't use webserver port but the regular socket port, and don't do HTTP requests on the regular socket port.
 
Reply
#3
I have configured the daemon with port 5000 and the webserver with port 5001.

I tried the following request that I found common for JSON request from the local command line:
Code:
curl -H 'Content-Type: application/json' -X PUT -d '{"action":"identify"}' localhost:5000

The answer is the html code listed in my first post.

What is wrong? Is php-cgi needed? Because the log says that it is not found by pilight (although installed).
 
Reply
#4
You are sending HTTP requests with Curl. You need to send clean socket requests.

What pilight actually receives from you is something like:
Code:
PUT {"action":"identify"} HTTP/1.1
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
Content-Type: application/json

What is really wants to see is just this:
Code:
{"action":"identify"}
 
Reply
#5
OK, I got it.

Maybe the documentation should be complemented to explicitly address this issue.

However, I still have problems.

For testing reasons, I use nc or ncat to send the request. With the identify action, I get a success response. If I request values, pilight-daemon crashes with no answer.

The error log says:
Code:
[Apr 22 20:09:01:100146] pilight-daemon: -- STACKTRACE (7 FRAMES) --
[Apr 22 20:09:01:101546] pilight-daemon: __default_sa_restorer_v2       ip = 0x76bbf180, sp = 0x757fe9c8
[Apr 22 20:09:01:119337] pilight-daemon: devices_values                 ip = 0x76ea33d8, sp = 0x757fecb8
[Apr 22 20:09:01:119872] pilight-daemon: socket_parse_data              ip =    0x15d2c, sp = 0x757fecf8
[Apr 22 20:09:01:120632] pilight-daemon: socket_wait                    ip = 0x76e32684, sp = 0x757fed70
[Apr 22 20:09:01:121104] pilight-daemon: start_thread                   ip = 0x76d62e90, sp = 0x757fee60
[Apr 22 20:09:01:121597] pilight-daemon: clone                          ip = 0x76c61698, sp = 0x757fefa0

Some hints? Shouldn't it work with tools like nc or ncat?
 
Reply
#6
Please follow the debug guide in the manual so we can see where it fails.
 
Reply
  


Possibly Related Threads...
Thread Author Replies Views Last Post
  pilight Nano USB interface curlymo 228 94,057 07-10-2019, 06:14 PM
Last Post: curlymo
  communication between main daemon and clientized daemon stops tomk 29 1,525 05-06-2019, 08:57 PM
Last Post: curlymo
  problems compiling pilight on Odroid C2 WitchDoctor 101 8,659 03-14-2019, 09:01 PM
Last Post: curlymo
  pilight 8 what chages for custom protocols? polo 11 2,654 02-15-2019, 06:22 PM
Last Post: polo
  pilight-debug shows nothing minhdomanh 3 470 10-18-2018, 07:01 AM
Last Post: felfert
  pilight-send and pilight-daemon DieterK 0 505 06-20-2018, 12:44 AM
Last Post: DieterK
  Lights not switched on or off by rules in pilight 8.1.0 rorie 22 2,296 06-12-2018, 03:56 PM
Last Post: curlymo
  check API in pilight 8 stratege-0815 4 1,270 02-11-2018, 09:34 AM
Last Post: stratege-0815
  pilight-receive terminates zackdvd 8 1,506 12-30-2017, 09:07 PM
Last Post: curlymo
  pilight 8.0 / wiringx wupperpi 2 1,724 12-18-2017, 03:25 PM
Last Post: wupperpi

Forum Jump:


Browsing: 1 Guest(s)