Python Plugin : HTTP Listener example question

Python and python framework

Moderator: leecollings

Post Reply
gerardwr
Posts: 32
Joined: Saturday 28 January 2017 11:30
Target OS: -
Domoticz version:
Contact:

Python Plugin : HTTP Listener example question

Post by gerardwr »

I am looking for a way to add a Python Plugin thats acts like a webserver, that can be called by a webclient on antoher computer.

Running Domotizc Version: 3.8755 on RPi-1-Jessie.

I did not find much information on the HTTP Listener Python Plugin example, but I THINK it:
- adds a webserver waiting for connections from webclients
- starts a webclient on every "heartbeat" and connects to the plugin-webserver

Running the plugin the Log shows that the heartbeat-client connects to the server and responds to the client. Works!

BUT if I try to connect a client on an different machine to the plugin-server I get no response from the server, and no info in the Domoticz Log.

My Domoticz is on 192.168.0.28, and is UP:

Code: Select all

pi@raspberrypiZolder:~/domoticz/plugins/HTTPListener $ curl 192.168.0.28:8080/log
<html><head><title>Not Found</title></head><body><h1>404 Not Found</h1></body></html>
The HTTP Listener Plugin listens on the default port 127.0.0.1:8008. When I try to connect, no response:

Code: Select all

pi@raspberrypiZolder:~/domoticz/plugins/HTTPListener $ curl 192.168.0.28:8008
I would expect the client to be connected to the plugin-webserver, but that does not happen.

Stupid mistake on my part, or am I missing something?
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Python Plugin : HTTP Listener example question

Post by Dnpwwo »

@gerardwr,

Your summary of the example's functionality is pretty accurate. I figured there was no point in a sample that just listened without any activity.

I never tested with Curl but would expect it to work. I connected from a web browser which from memory opens a connection then issues an HTTP GET. The example returns a 200 response and

Code: Select all

<!doctype html><html><head></head><body><h1>Successful GET!!!</h1><body></html>
I would suggest:
  • try from a web browser
  • turning debug on and looking at the Domoticz log I would expect to see a connection message at a minimum. I would recommend running Domoticz from the command line to do that because HTML response don't format very well in the Web UI log
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
gerardwr
Posts: 32
Joined: Saturday 28 January 2017 11:30
Target OS: -
Domoticz version:
Contact:

Re: Python Plugin : HTTP Listener example question

Post by gerardwr »

Dnpwwo wrote: Thursday 21 December 2017 6:38 @gerardwr,

Your summary of the example's functionality is pretty accurate. I figured there was no point in a sample that just listened without any activity.
Thanks for the heads up. Took me a while before I got it. Excellent "turn key" example, once you "get it" !
I never tested with Curl but would expect it to work. I connected from a web browser which from memory opens a connection then issues an HTTP GET. The example returns a 200 response and

Code: Select all

<!doctype html><html><head></head><body><h1>Successful GET!!!</h1><body></html>
Tested in a browser ( on Mac with both Safari and Chrome ) but no response, the browser is, just like Curl, "waiting" :(

I would suggest:
  • try from a web browser
  • turning debug on and looking at the Domoticz log I would expect to see a connection message at a minimum. I would recommend running Domoticz from the command line to do that because HTML response don't format very well in the Web UI log
[/quote]

Looked at the log, it is flooded with numerous debugmessages from Heartbeat, but I did not spot a connection message from the brwoser-use yet. Will try later witch Domticz in the command-line, gives me more time to check the messages :)

Thx so far!
gerardwr
Posts: 32
Joined: Saturday 28 January 2017 11:30
Target OS: -
Domoticz version:
Contact:

Re: Python Plugin : HTTP Listener example question

Post by gerardwr »

Dnpwwo wrote: Thursday 21 December 2017 6:38 I would suggest:
  • try from a web browser
  • turning debug on and looking at the Domoticz log I would expect to see a connection message at a minimum. I would recommend running Domoticz from the command line to do that because HTML response don't format very well in the Web UI log
Had a better look. Started domoticz on commandline and browsed from Mac on 192.168.0.81 to the Domoticz URL defined in the plugin (192.168.0.28:8008)

In the Domicz output I see that the GET from the browser is received:
- onConnect handler is called
- onMessage handler is called
=== "succesfull get" page is sent
=== and "succesfull get" page is received again, huh!?

But the "succesfull get" page is not shown in the browser.

Could it be that the page is returned to the IP of the Domticz server instead of the Ip of the requesting browser?

Detailed output is:
Spoiler: show
pi@raspberrypiZolder:~/domoticz $ ./domoticz | grep httplist
2017-12-21 11:29:04.723 (httplistener) Started.
2017-12-21 11:29:11.388 (httplistener) Initialized version 1.0.0, author 'dnpwwo'
2017-12-21 11:29:11.391 (httplistener) Entering work loop.
2017-12-21 11:29:11.921 (httplistener) Debug log level set to: 'true'.
2017-12-21 11:29:11.925 (httplistener) 'Version':'1.0.0'
2017-12-21 11:29:11.928 (httplistener) 'Author':'dnpwwo'
2017-12-21 11:29:11.931 (httplistener) 'Name':'httplistener'
2017-12-21 11:29:11.939 (httplistener) 'Mode6':'Debug'
2017-12-21 11:29:11.942 (httplistener) 'HomeFolder':'/home/pi/domoticz/plugins/HTTPListener/'
2017-12-21 11:29:11.960 (httplistener) 'Key':'HTTPListen'
2017-12-21 11:29:11.963 (httplistener) 'HardwareID':'27'
2017-12-21 11:29:11.966 (httplistener) 'Port':'8008'
2017-12-21 11:29:11.969 (httplistener) Device count: 0
2017-12-21 11:29:11.972 (httplistener) Leaving on start
2017-12-21 11:29:12.002 (httplistener) Protocol set to: 'HTTP'.
2017-12-21 11:29:12.006 (httplistener) Transport set to: 'TCP/IP', :8008.
2017-12-21 11:29:12.010 (httplistener) Listen directive received, action initiated successfully.


===============> browse to url : 192.168.0.28:8008/page.html =================================

2017-12-21 11:29:27.470 (httplistener) Protocol set to: 'HTTP'.
2017-12-21 11:29:27.471 (httplistener) Calling message handler 'onConnect'.
2017-12-21 11:29:27.474 (httplistener) Connected successfully to: 192.168.0.81:49219
2017-12-21 11:29:27.476 (httplistener) Name: '192.168.0.81:49219', Transport: 'TCP/IP', Protocol: 'HTTP', Address: '192.168.0.81', Port: '49219', Baud: 0, Bytes: 366, Connected: True, Last Seen: 2017-12-21 11:29:27
2017-12-21 11:29:27.481 (httplistener) Received 366 bytes of data:
2017-12-21 11:29:27.483 (httplistener) 47 45 54 20 2f 70 61 67 65 2e 68 74 6d 6c 20 48 54 54 50 2f GET./page.html.HTTP/
2017-12-21 11:29:27.485 (httplistener) 31 2e 31 0d 0a 48 6f 73 74 3a 20 31 39 32 2e 31 36 38 2e 30 1.1..Host:.192.168.0
2017-12-21 11:29:27.491 (httplistener) 2e 32 38 3a 38 30 30 38 0d 0a 55 70 67 72 61 64 65 2d 49 6e .28:8008..Upgrade-In
2017-12-21 11:29:27.492 (httplistener) 73 65 63 75 72 65 2d 52 65 71 75 65 73 74 73 3a 20 31 0d 0a secure-Requests:.1..
2017-12-21 11:29:27.495 (httplistener) 41 63 63 65 70 74 3a 20 74 65 78 74 2f 68 74 6d 6c 2c 61 70 Accept:.text/html,ap
2017-12-21 11:29:27.500 (httplistener) 70 6c 69 63 61 74 69 6f 6e 2f 78 68 74 6d 6c 2b 78 6d 6c 2c plication/xhtml+xml,
2017-12-21 11:29:27.501 (httplistener) 61 70 70 6c 69 63 61 74 69 6f 6e 2f 78 6d 6c 3b 71 3d 30 2e application/xml;q=0.
2017-12-21 11:29:27.501 (httplistener) 39 2c 2a 2f 2a 3b 71 3d 30 2e 38 0d 0a 55 73 65 72 2d 41 67 9,*/*;q=0.8..User-Ag
2017-12-21 11:29:27.501 (httplistener) 65 6e 74 3a 20 4d 6f 7a 69 6c 6c 61 2f 35 2e 30 20 28 4d 61 ent:.Mozilla/5.0.(Ma
2017-12-21 11:29:27.501 (httplistener) 63 69 6e 74 6f 73 68 3b 20 49 6e 74 65 6c 20 4d 61 63 20 4f cintosh;.Intel.Mac.O
2017-12-21 11:29:27.502 (httplistener) 53 20 58 20 31 30 5f 31 31 5f 36 29 20 41 70 70 6c 65 57 65 S.X.10_11_6).AppleWe
2017-12-21 11:29:27.502 (httplistener) 62 4b 69 74 2f 36 30 34 2e 34 2e 37 20 28 4b 48 54 4d 4c 2c bKit/604.4.7.(KHTML,
2017-12-21 11:29:27.502 (httplistener) 20 6c 69 6b 65 20 47 65 63 6b 6f 29 20 56 65 72 73 69 6f 6e .like.Gecko).Version
2017-12-21 11:29:27.502 (httplistener) 2f 31 31 2e 30 2e 32 20 53 61 66 61 72 69 2f 36 30 34 2e 34 /11.0.2.Safari/604.4
2017-12-21 11:29:27.503 (httplistener) 2e 37 0d 0a 41 63 63 65 70 74 2d 4c 61 6e 67 75 61 67 65 3a .7..Accept-Language:
2017-12-21 11:29:27.503 (httplistener) 20 6e 6c 2d 6e 6c 0d 0a 41 63 63 65 70 74 2d 45 6e 63 6f 64 .nl-nl..Accept-Encod
2017-12-21 11:29:27.503 (httplistener) 69 6e 67 3a 20 67 7a 69 70 2c 20 64 65 66 6c 61 74 65 0d 0a ing:.gzip,.deflate..
2017-12-21 11:29:27.504 (httplistener) 43 6f 6e 6e 65 63 74 69 6f 6e 3a 20 6b 65 65 70 2d 61 6c 69 Connection:.keep-ali
2017-12-21 11:29:27.504 (httplistener) 76 65 0d 0a 0d 0a .. .. .. .. .. .. .. .. .. .. .. .. .. .. ve....
2017-12-21 11:29:27.505 (httplistener) Calling message handler 'onMessage'.
2017-12-21 11:29:27.505 (httplistener) onMessage called for connection: 192.168.0.81:49219
2017-12-21 11:29:27.505 (httplistener) HTTP Details (3):
2017-12-21 11:29:27.506 (httplistener) --->'URL':'/page.html'
2017-12-21 11:29:27.506 (httplistener) --->'Verb':'GET'
2017-12-21 11:29:27.506 (httplistener) --->'Headers (7):
2017-12-21 11:29:27.507 (httplistener) ------->'Connection':'keep-alive'
2017-12-21 11:29:27.507 (httplistener) ------->'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
2017-12-21 11:29:27.507 (httplistener) ------->'Accept-Language':'nl-nl'
2017-12-21 11:29:27.508 (httplistener) ------->'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/604.4.7 (KHTML, like Gecko) Version/11.0.2 Safari/604.4.7'
2017-12-21 11:29:27.508 (httplistener) ------->'Accept-Encoding':'gzip, deflate'
2017-12-21 11:29:27.508 (httplistener) ------->'Host':'192.168.0.28:8008'
2017-12-21 11:29:27.509 (httplistener) ------->'Upgrade-Insecure-Requests':'1'
2017-12-21 11:29:27.509 (httplistener) GET request received.
2017-12-21 11:29:27.552 (httplistener) Sending 249 bytes of data:
2017-12-21 11:29:27.554 (httplistener) 48 54 54 50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d 0a 44 61 74 HTTP/1.1.200.OK..Dat
2017-12-21 11:29:27.557 (httplistener) 65 3a 20 54 68 75 2c 20 32 31 20 44 65 63 20 32 30 31 37 20 e:.Thu,.21.Dec.2017.
2017-12-21 11:29:27.559 (httplistener) 31 30 3a 32 39 3a 32 37 20 47 4d 54 0d 0a 53 65 72 76 65 72 10:29:27.GMT..Server
2017-12-21 11:29:27.571 (httplistener) 3a 20 44 6f 6d 6f 74 69 63 7a 2f 31 2e 30 0d 0a 41 63 63 65 :.Domoticz/1.0..Acce
2017-12-21 11:29:27.573 (httplistener) 70 74 3a 20 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 74 65 pt:.Content-Type:.te
2017-12-21 11:29:27.575 (httplistener) 78 74 2f 68 74 6d 6c 3b 20 63 68 61 72 73 65 74 3d 55 54 46 xt/html;.charset=UTF
2017-12-21 11:29:27.577 (httplistener) 2d 38 0d 0a 43 6f 6e 6e 65 63 74 69 6f 6e 3a 20 6b 65 65 70 -8..Connection:.keep
2017-12-21 11:29:27.579 (httplistener) 2d 61 6c 69 76 65 0d 0a 43 6f 6e 74 65 6e 74 2d 4c 65 6e 67 -alive..Content-Leng
2017-12-21 11:29:27.582 (httplistener) 74 68 3a 20 37 39 0d 0a 0d 0a 3c 21 64 6f 63 74 79 70 65 20 th:.79....<!doctype.
2017-12-21 11:29:27.584 (httplistener) 68 74 6d 6c 3e 3c 68 74 6d 6c 3e 3c 68 65 61 64 3e 3c 2f 68 html><html><head></h
2017-12-21 11:29:27.586 (httplistener) 65 61 64 3e 3c 62 6f 64 79 3e 3c 68 31 3e 53 75 63 63 65 73 ead><body><h1>Succes
2017-12-21 11:29:27.588 (httplistener) 73 66 75 6c 20 47 45 54 21 21 21 3c 2f 68 31 3e 3c 62 6f 64 sful.GET!!!</h1><bod
2017-12-21 11:29:27.590 (httplistener) 79 3e 3c 2f 68 74 6d 6c 3e .. .. .. .. .. .. .. .. .. .. .. y></html>
2017-12-21 11:29:27.594 (httplistener) Received 249 bytes of data:
2017-12-21 11:29:27.603 (httplistener) 48 54 54 50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d 0a 44 61 74 HTTP/1.1.200.OK..Dat
2017-12-21 11:29:27.605 (httplistener) 65 3a 20 54 68 75 2c 20 32 31 20 44 65 63 20 32 30 31 37 20 e:.Thu,.21.Dec.2017.
2017-12-21 11:29:27.607 (httplistener) 31 30 3a 32 39 3a 32 37 20 47 4d 54 0d 0a 53 65 72 76 65 72 10:29:27.GMT..Server
2017-12-21 11:29:27.609 (httplistener) 3a 20 44 6f 6d 6f 74 69 63 7a 2f 31 2e 30 0d 0a 41 63 63 65 :.Domoticz/1.0..Acce
2017-12-21 11:29:27.611 (httplistener) 70 74 3a 20 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 74 65 pt:.Content-Type:.te
2017-12-21 11:29:27.616 (httplistener) 78 74 2f 68 74 6d 6c 3b 20 63 68 61 72 73 65 74 3d 55 54 46 xt/html;.charset=UTF
2017-12-21 11:29:27.618 (httplistener) 2d 38 0d 0a 43 6f 6e 6e 65 63 74 69 6f 6e 3a 20 6b 65 65 70 -8..Connection:.keep
2017-12-21 11:29:27.620 (httplistener) 2d 61 6c 69 76 65 0d 0a 43 6f 6e 74 65 6e 74 2d 4c 65 6e 67 -alive..Content-Leng
2017-12-21 11:29:27.631 (httplistener) 74 68 3a 20 37 39 0d 0a 0d 0a 3c 21 64 6f 63 74 79 70 65 20 th:.79....<!doctype.
2017-12-21 11:29:27.634 (httplistener) 68 74 6d 6c 3e 3c 68 74 6d 6c 3e 3c 68 65 61 64 3e 3c 2f 68 html><html><head></h
2017-12-21 11:29:27.636 (httplistener) 65 61 64 3e 3c 62 6f 64 79 3e 3c 68 31 3e 53 75 63 63 65 73 ead><body><h1>Succes
2017-12-21 11:29:27.638 (httplistener) 73 66 75 6c 20 47 45 54 21 21 21 3c 2f 68 31 3e 3c 62 6f 64 sful.GET!!!</h1><bod
2017-12-21 11:29:27.641 (httplistener) 79 3e 3c 2f 68 74 6d 6c 3e .. .. .. .. .. .. .. .. .. .. .. y></html>

===============> browse to url : 192.168.0.28:8008/testgwr.html =================================

2017-12-21 11:29:41.476 (httplistener) Calling message handler 'onConnect'.
2017-12-21 11:29:41.477 (httplistener) Connected successfully to: 192.168.0.81:49222
2017-12-21 11:29:41.477 (httplistener) Name: '192.168.0.81:49222', Transport: 'TCP/IP', Protocol: 'HTTP', Address: '192.168.0.81', Port: '49222', Baud: 0, Bytes: 369, Connected: True, Last Seen: 2017-12-21 11:29:41
2017-12-21 11:29:41.477 (httplistener) Received 369 bytes of data:
2017-12-21 11:29:41.478 (httplistener) 47 45 54 20 2f 74 65 73 74 67 77 72 2e 68 74 6d 6c 20 48 54 GET./testgwr.html.HT
2017-12-21 11:29:41.478 (httplistener) 54 50 2f 31 2e 31 0d 0a 48 6f 73 74 3a 20 31 39 32 2e 31 36 TP/1.1..Host:.192.16
2017-12-21 11:29:41.478 (httplistener) 38 2e 30 2e 32 38 3a 38 30 30 38 0d 0a 55 70 67 72 61 64 65 8.0.28:8008..Upgrade
2017-12-21 11:29:41.478 (httplistener) 2d 49 6e 73 65 63 75 72 65 2d 52 65 71 75 65 73 74 73 3a 20 -Insecure-Requests:.
2017-12-21 11:29:41.479 (httplistener) 31 0d 0a 41 63 63 65 70 74 3a 20 74 65 78 74 2f 68 74 6d 6c 1..Accept:.text/html
2017-12-21 11:29:41.479 (httplistener) 2c 61 70 70 6c 69 63 61 74 69 6f 6e 2f 78 68 74 6d 6c 2b 78 ,application/xhtml+x
2017-12-21 11:29:41.479 (httplistener) 6d 6c 2c 61 70 70 6c 69 63 61 74 69 6f 6e 2f 78 6d 6c 3b 71 ml,application/xml;q
2017-12-21 11:29:41.479 (httplistener) 3d 30 2e 39 2c 2a 2f 2a 3b 71 3d 30 2e 38 0d 0a 55 73 65 72 =0.9,*/*;q=0.8..User
2017-12-21 11:29:41.480 (httplistener) 2d 41 67 65 6e 74 3a 20 4d 6f 7a 69 6c 6c 61 2f 35 2e 30 20 -Agent:.Mozilla/5.0.
2017-12-21 11:29:41.494 (httplistener) 28 4d 61 63 69 6e 74 6f 73 68 3b 20 49 6e 74 65 6c 20 4d 61 (Macintosh;.Intel.Ma
2017-12-21 11:29:41.495 (httplistener) 63 20 4f 53 20 58 20 31 30 5f 31 31 5f 36 29 20 41 70 70 6c c.OS.X.10_11_6).Appl
2017-12-21 11:29:41.495 (httplistener) 65 57 65 62 4b 69 74 2f 36 30 34 2e 34 2e 37 20 28 4b 48 54 eWebKit/604.4.7.(KHT
2017-12-21 11:29:41.495 (httplistener) 4d 4c 2c 20 6c 69 6b 65 20 47 65 63 6b 6f 29 20 56 65 72 73 ML,.like.Gecko).Vers
2017-12-21 11:29:41.495 (httplistener) 69 6f 6e 2f 31 31 2e 30 2e 32 20 53 61 66 61 72 69 2f 36 30 ion/11.0.2.Safari/60
2017-12-21 11:29:41.496 (httplistener) 34 2e 34 2e 37 0d 0a 41 63 63 65 70 74 2d 4c 61 6e 67 75 61 4.4.7..Accept-Langua
2017-12-21 11:29:41.496 (httplistener) 67 65 3a 20 6e 6c 2d 6e 6c 0d 0a 41 63 63 65 70 74 2d 45 6e ge:.nl-nl..Accept-En
2017-12-21 11:29:41.496 (httplistener) 63 6f 64 69 6e 67 3a 20 67 7a 69 70 2c 20 64 65 66 6c 61 74 coding:.gzip,.deflat
2017-12-21 11:29:41.497 (httplistener) 65 0d 0a 43 6f 6e 6e 65 63 74 69 6f 6e 3a 20 6b 65 65 70 2d e..Connection:.keep-
2017-12-21 11:29:41.497 (httplistener) 61 6c 69 76 65 0d 0a 0d 0a .. .. .. .. .. .. .. .. .. .. .. alive....

2017-12-21 11:29:41.497 (httplistener) Calling message handler 'onMessage'.
2017-12-21 11:29:41.498 (httplistener) onMessage called for connection: 192.168.0.81:49222
2017-12-21 11:29:41.498 (httplistener) HTTP Details (3):
2017-12-21 11:29:41.499 (httplistener) --->'URL':'/testgwr.html'
2017-12-21 11:29:41.499 (httplistener) --->'Verb':'GET'
2017-12-21 11:29:41.499 (httplistener) --->'Headers (7):
2017-12-21 11:29:41.500 (httplistener) ------->'Connection':'keep-alive'
2017-12-21 11:29:41.500 (httplistener) ------->'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
2017-12-21 11:29:41.518 (httplistener) ------->'Accept-Language':'nl-nl'
2017-12-21 11:29:41.520 (httplistener) ------->'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/604.4.7 (KHTML, like Gecko) Version/11.0.2 Safari/604.4.7'
2017-12-21 11:29:41.523 (httplistener) ------->'Accept-Encoding':'gzip, deflate'
2017-12-21 11:29:41.526 (httplistener) ------->'Host':'192.168.0.28:8008'
2017-12-21 11:29:41.528 (httplistener) ------->'Upgrade-Insecure-Requests':'1'
2017-12-21 11:29:41.530 (httplistener) GET request received.
2017-12-21 11:29:41.532 (httplistener) Sending 249 bytes of data:
2017-12-21 11:29:41.534 (httplistener) 48 54 54 50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d 0a 44 61 74 HTTP/1.1.200.OK..Dat
2017-12-21 11:29:41.536 (httplistener) 65 3a 20 54 68 75 2c 20 32 31 20 44 65 63 20 32 30 31 37 20 e:.Thu,.21.Dec.2017.
2017-12-21 11:29:41.538 (httplistener) 31 30 3a 32 39 3a 34 31 20 47 4d 54 0d 0a 53 65 72 76 65 72 10:29:41.GMT..Server
2017-12-21 11:29:41.540 (httplistener) 3a 20 44 6f 6d 6f 74 69 63 7a 2f 31 2e 30 0d 0a 41 63 63 65 :.Domoticz/1.0..Acce
2017-12-21 11:29:41.542 (httplistener) 70 74 3a 20 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 74 65 pt:.Content-Type:.te
2017-12-21 11:29:41.544 (httplistener) 78 74 2f 68 74 6d 6c 3b 20 63 68 61 72 73 65 74 3d 55 54 46 xt/html;.charset=UTF
2017-12-21 11:29:41.547 (httplistener) 2d 38 0d 0a 43 6f 6e 6e 65 63 74 69 6f 6e 3a 20 6b 65 65 70 -8..Connection:.keep
2017-12-21 11:29:41.549 (httplistener) 2d 61 6c 69 76 65 0d 0a 43 6f 6e 74 65 6e 74 2d 4c 65 6e 67 -alive..Content-Leng
2017-12-21 11:29:41.551 (httplistener) 74 68 3a 20 37 39 0d 0a 0d 0a 3c 21 64 6f 63 74 79 70 65 20 th:.79....<!doctype.
2017-12-21 11:29:41.552 (httplistener) 68 74 6d 6c 3e 3c 68 74 6d 6c 3e 3c 68 65 61 64 3e 3c 2f 68 html><html><head></h
2017-12-21 11:29:41.552 (httplistener) 65 61 64 3e 3c 62 6f 64 79 3e 3c 68 31 3e 53 75 63 63 65 73 ead><body><h1>Succes
2017-12-21 11:29:41.552 (httplistener) 73 66 75 6c 20 47 45 54 21 21 21 3c 2f 68 31 3e 3c 62 6f 64 sful.GET!!!</h1><bod
2017-12-21 11:29:41.553 (httplistener) 79 3e 3c 2f 68 74 6d 6c 3e .. .. .. .. .. .. .. .. .. .. .. y></html>
2017-12-21 11:29:41.561 (httplistener) Received 249 bytes of data:
2017-12-21 11:29:41.561 (httplistener) 48 54 54 50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d 0a 44 61 74 HTTP/1.1.200.OK..Dat
2017-12-21 11:29:41.562 (httplistener) 65 3a 20 54 68 75 2c 20 32 31 20 44 65 63 20 32 30 31 37 20 e:.Thu,.21.Dec.2017.
2017-12-21 11:29:41.562 (httplistener) 31 30 3a 32 39 3a 34 31 20 47 4d 54 0d 0a 53 65 72 76 65 72 10:29:41.GMT..Server
2017-12-21 11:29:41.562 (httplistener) 3a 20 44 6f 6d 6f 74 69 63 7a 2f 31 2e 30 0d 0a 41 63 63 65 :.Domoticz/1.0..Acce
2017-12-21 11:29:41.568 (httplistener) 70 74 3a 20 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 74 65 pt:.Content-Type:.te
2017-12-21 11:29:41.569 (httplistener) 78 74 2f 68 74 6d 6c 3b 20 63 68 61 72 73 65 74 3d 55 54 46 xt/html;.charset=UTF
2017-12-21 11:29:41.569 (httplistener) 2d 38 0d 0a 43 6f 6e 6e 65 63 74 69 6f 6e 3a 20 6b 65 65 70 -8..Connection:.keep
2017-12-21 11:29:41.569 (httplistener) 2d 61 6c 69 76 65 0d 0a 43 6f 6e 74 65 6e 74 2d 4c 65 6e 67 -alive..Content-Leng
2017-12-21 11:29:41.569 (httplistener) 74 68 3a 20 37 39 0d 0a 0d 0a 3c 21 64 6f 63 74 79 70 65 20 th:.79....<!doctype.
2017-12-21 11:29:41.570 (httplistener) 68 74 6d 6c 3e 3c 68 74 6d 6c 3e 3c 68 65 61 64 3e 3c 2f 68 html><html><head></h
2017-12-21 11:29:41.578 (httplistener) 65 61 64 3e 3c 62 6f 64 79 3e 3c 68 31 3e 53 75 63 63 65 73 ead><body><h1>Succes
2017-12-21 11:29:41.578 (httplistener) 73 66 75 6c 20 47 45 54 21 21 21 3c 2f 68 31 3e 3c 62 6f 64 sful.GET!!!</h1><bod
2017-12-21 11:29:41.579 (httplistener) 79 3e 3c 2f 68 74 6d 6c 3e .. .. .. .. .. .. .. .. .. .. .. y></html>
zak45
Posts: 952
Joined: Sunday 22 January 2017 11:37
Target OS: Windows
Domoticz version: V2024.4
Contact:

Re: Python Plugin : HTTP Listener example question

Post by zak45 »

Maybe this could provide some help.
Attached plugin that implement Server/client communication.
plugin.py ==> execute the Server part and wait for client connection
btle.py ==> client connecting to the server and sending information.
if you connect to the Server using browser, you get Successful GET!!! message
BTLeScanr.zip
(22.36 KiB) Downloaded 65 times
gerardwr
Posts: 32
Joined: Saturday 28 January 2017 11:30
Target OS: -
Domoticz version:
Contact:

Re: Python Plugin : HTTP Listener example question

Post by gerardwr »

zak45 wrote: Thursday 21 December 2017 12:58 Maybe this could provide some help.
Thanks @zak45,

Will try that later today.
zak45
Posts: 952
Joined: Sunday 22 January 2017 11:37
Target OS: Windows
Domoticz version: V2024.4
Contact:

Re: Python Plugin : HTTP Listener example question

Post by zak45 »

@gerardwr
take care : there is a problem in Domoticz/Python and the Tcp connection
if you reload the plugin, tcp connection is not closed and reopen.. but remain opened.
you need to change the Port number every time.

Dnpwwo know that and I think he or someonelse work on it...

https://www.domoticz.com/forum/viewtopi ... ed#p155902
gerardwr
Posts: 32
Joined: Saturday 28 January 2017 11:30
Target OS: -
Domoticz version:
Contact:

Re: Python Plugin : HTTP Listener example question

Post by gerardwr »

@zak54

Just tested yor BTLEscan plugin, and I can connect to the server part:

Schermafbeelding 2017-12-21 om 13.27.41.png
Schermafbeelding 2017-12-21 om 13.27.41.png (35.47 KiB) Viewed 1581 times
At least I know now that the problem is not in my setup, but in the HTTP Listener example.
@Dnpwwo can probably help there.

For the time being I will have a more detailed look at the server part of your plugin and use this as a foundation for my own server plugin.

Thanks, you saved me many hours!
gerardwr
Posts: 32
Joined: Saturday 28 January 2017 11:30
Target OS: -
Domoticz version:
Contact:

Re: Python Plugin : HTTP Listener example question

Post by gerardwr »

I compared the code from "HTTP Listener" and "BTLE Scanner" for a clue why a client did not get a response from the HTTP Listener, while it does get a response from BTLE Scanner.

The onConnect code from HTT Listener is:

Code: Select all

    def onConnect(self, Connection, Status, Description):
        if (Status == 0):
            Domoticz.Log("Connected successfully to: "+Connection.Address+":"+Connection.Port)
        else:
            Domoticz.Log("Failed to connect ("+str(Status)+") to: "+Connection.Address+":"+Connection.Port+" with error: "+Description)
        Domoticz.Log(str(Connection))
        if (Connection != self.httpClientConn):
            self.httpServerConns[Connection.Name] = Connection
The onConnectcode from BTLE Scanner is:

Code: Select all

def onConnect(Connection, Status, Description):
    global httpServerConn , httpServerConns , httpClientConn

    if (Status == 0):
        Domoticz.Log("Connected successfully to: "+Connection.Address+":"+Connection.Port)
    else:
        Domoticz.Log("Failed to connect ("+str(Status)+") to: "+Connection.Address+":"+Connection.Port+" with error: "+Description)
        Domoticz.Log(str(Connection))
    if (Connection != httpClientConn):
            httpServerConns[Connection.Name] = Connection
            httpClientConn = Connection
    return
The only difference is the line:

Code: Select all

            httpClientConn = Connection
After adding this line to the HTPP Listener example now the clients get a response! Buy I guess the onHeartbeat will now not get a response anymore.

I think it's best that @Dnwppo evaluates what changes would be required to the HTTListener example.

Thanks to @Dnwppo and @zak54 for their assistence :D
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest