• 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

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

the daemon returns a http webpage referring to the builtin webserver:
<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!

Make sure you don't use webserver port but the regular socket port, and don't do HTTP requests on the regular socket port.
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:
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).
You are sending HTTP requests with Curl. You need to send clean socket requests.

What pilight actually receives from you is something like:
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:
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:
[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?
Please follow the debug guide in the manual so we can see where it fails.

Possibly Related Threads...
Thread Author Replies Views Last Post
  [Solved] pilight service crashing on first webserver access after reboot VrahoK 20 648 12-21-2019, 09:46 AM
Last Post: curlymo
  pilight-control modify values coolinx 16 717 11-13-2019, 08:02 PM
Last Post: curlymo
  Bug: double free or corruption in pilight-send blackzombie 12 700 10-07-2019, 08:15 PM
Last Post: blackzombie
  [Fixed] High CPU usage when pilight usb nano disconnects DieterK 1 288 08-13-2019, 05:43 PM
Last Post: curlymo
  pilight Nano USB interface curlymo 228 105,404 07-10-2019, 06:14 PM
Last Post: curlymo
  communication between main daemon and clientized daemon stops tomk 29 2,820 05-06-2019, 08:57 PM
Last Post: curlymo
  problems compiling pilight on Odroid C2 WitchDoctor 101 13,284 03-14-2019, 09:01 PM
Last Post: curlymo
  pilight 8 what chages for custom protocols? polo 11 3,562 02-15-2019, 06:22 PM
Last Post: polo
  pilight-debug shows nothing minhdomanh 3 736 10-18-2018, 07:01 AM
Last Post: felfert
  pilight-send and pilight-daemon DieterK 0 712 06-20-2018, 12:44 AM
Last Post: DieterK

Forum Jump:

Browsing: 1 Guest(s)