Page 3 of 9

Re: Network Broadcast Sender / Listener

Posted: Wed Oct 14, 2009 7:58 pm
by Pako
I also tried your plugin. Worked well, but I encountered two problems:
1) If I disable Broadcaster plugin and then enable again, I get an error message and the plugin stops working
(not to say always, but it is very often).
2) I have a Czech Windows, and if there Broadcaster plugin has perform the line number 117,
this results in UnicodeDecodeError (and the original error message is not printed).

I found the solution to both problems:
1) Instead of

Code: Select all

    def handle_write(self):
        pass
Is to be written

Code: Select all

    def writable(self):
        return False  # we don't have anything to send !
2) This problem can be solved as follows: It should be added:

Code: Select all

from locale import getdefaultlocale as localeEncoding
and line 117 should be corrected as follows:

Code: Select all

self.Exception(exc[1].decode(localeEncoding()[1]))
I have but one more comment. In your plugin is used to indentation sometime space character and sometime Tab character.
It is very unpleasant. I was forced to do first unification (I use the Space), and then I could use my editor.
Pako

Re: Network Broadcast Sender / Listener

Posted: Wed Oct 14, 2009 9:02 pm
by kingtd
Thanks Pako! I had been chasing that "not a socket" error for a while. I'm going to test this out on my setup for a little bit, then I'll post an updated version if it all checks out (which I expect it to, of course).

In terms of the spaces vs tab - I agree it's a little annoying, but I code in notepad so I don't notice too much. If there was an automated way of fixing it, I probably would.

-T

Re: Network Broadcast Sender / Listener

Posted: Thu Oct 15, 2009 1:52 pm
by jitterjames
So, no word on multiple payloads? If the broadcaster doesn't support them I'd be happy to contribute some code, but I'd like some feedback first on how we should best encode the string to maintain functionality for other users doing rebroadcasts etc.

If you are not interested I can just go back to having my own version that supports multiple payloads for my needs.

In the world of bugs, I have an issue with my windows 7 machine, where having the broadcaster plugin active puts my cpu % through the roof. If you get a chance to post the lastest version with Pako's changes I'll test that and then let you know if it is still happening. This is on a pretty old single core dell that I got before vista even came out so it may be specific to that machine, or it may be a windows 7 issue. My htpc doesn't have this problem but is running vista.

Re: Network Broadcast Sender / Listener

Posted: Fri Oct 16, 2009 5:05 pm
by kingtd
Can you post your code or detail the changes you made to support multiple payloads? My biggest concern (or issue that I've encountered) is determining how many payloads are actually present, and making sure that when there's only a single payload that it doesn't get broken up as an array of characters instead of a string.

Re: Network Broadcast Sender / Listener

Posted: Fri Oct 16, 2009 6:29 pm
by jitterjames
sure. I'm not a master programmer or anything but
given a string in one of the following forms, this works for me.

command
or
command?payload1string
or
command?payload1?payload2...

Code: Select all

	# Receive messages
	while True:
	    data, addr = UDPSock.recvfrom(1024)
	    bits = data.split("?")
	    commandSize=len(bits)
	    if commandSize==1:
	       self.TriggerEvent(bits[0])
	    if commandSize==2:
	       self.TriggerEvent(bits[0],bits[1])
	    if commandSize>2:
	       self.TriggerEvent(bits[0],bits[1:])	
of course I can't use '?' in any of my payloads, but we could just as easily delimit the string using:
,payload=
and I think it would work pretty safely.
I'm not sure if you can do a split in python using a string rather than a character but there must be a way.

Re: Network Broadcast Sender / Listener

Posted: Mon Oct 19, 2009 5:50 pm
by jitterjames
Broadcaster seems to have a serious windows 7 bug :(

I have tried this latest version of the plugin on 2 different Windows 7 computers, and in both cases enabling the broadcast plugin causes 1 cpu core to go to 100%. I'm guessing it must have something to do with the listener thread.

Let me know if there is anything I can do to help you trouble-shoot this problem.

The plugin still seems to be working normally but this bug essentially makes the plugin unusable on window 7 machines. (IMO)

Re: Network Broadcast Sender / Listener

Posted: Sun Oct 25, 2009 10:24 pm
by jitterjames
This thread seems to have stalled abit so I've taken the liberty of updating this plugin. I hope no one minds.

I implemented pako's suggestion to change this code

Code: Select all

    def writable(self):
        return False  # we don't have anything to send !    def writable(self):
        return False  # we don't have anything to send !
and I'm not sure if it was this change but my problems with windows 7 are now gone.

I've added support for multiple payloads, and the delimiter is configurable as well (the same is used for send and receive and is set in the general plugin settings along with the port). The default delimiter is '&&' but you can change it to 'payload=' for compatibility with the older version.

It's working well for me, let me know if there are any problems.

I was thinking of adding an automatic re-broadcasting option, but I'm not really sure how people are doing that so I'd need some feedback there. Maybe it's not necessary.

jitter

Re: Network Broadcast Sender / Listener

Posted: Sat Nov 21, 2009 11:09 pm
by magao
I have multiple IPv4 interfaces on my machines, which mean that I might receive each broadcast multiple times to the same machine (e.g. if listening to self broadcasts).

I've added a drop-down choice of the available IPv4 addresses on the machine. This means each configured broadcaster will only listen on one address. If you want to listen on multiple addresses on the one machine, you can use multiple instances of the plugin.

For machines with only a single address, this version will "just work" without reconfiguring - if the listening address is not configured (or isn't currently active - good for laptops that are sometimes wired in and sometimes wireless) it will default to the first address in the list (sorted by address).

Bugfix: when self-broadcasting, the address sent from may be different to the address we're listening on - need to check if the sending address is any of our addresses.

Re: Network Broadcast Sender / Listener

Posted: Wed Dec 16, 2009 3:39 am
by Fiasco
Kingtd,

Is it possible to pick up these udp broadcasts from outside my network (I'm thinking over 3G) or can I only listen to them inside my network IP

Re: Network Broadcast Sender / Listener

Posted: Wed Dec 16, 2009 12:41 pm
by jitterjames
as it is currently set up it I think it must be used only for the local lan. perhaps it could be modified, but I think something like tcp would make more sense when targeting outside the network. Targeting being the key word there since udp is just a dumb broadcast, and you wouldn't want to broadcast to the entire internet...

I am no expert though! I have only a muddy understanding of how most of this stuff actually works.

If you are more specific about what you want to do (i.e. over 3G) maybe someone will have a suggestion.

Re: Network Broadcast Sender / Listener

Posted: Sat Dec 19, 2009 11:40 pm
by Fiasco
I was using the CommandFusion plugin to send feedback to my iphone interface. However, the commandfusion plugin randomly looses the ability to send data back (remote to command fusion plugin still works fine).

I was using my DynDNS.org address for my house to send and receive info on my phone from this plugin so I could manipulate my stuff over 3g. Since it was unreliable I switched to using broadcaster to broadcast the feedback which works great on my local network but obviously not over the innerwebs.

Re: Network Broadcast Sender / Listener

Posted: Mon Dec 21, 2009 8:43 pm
by kingtd
Sorry I haven't been around to look at these posts lately. I think all the new changes and fixes to the plugin are great, and address some of the wider use cases.

@Fiasco: It's going to be pretty difficult to get it working outside your local network. UDP broadcasting isn't really built to traverse wider networks and target a specific device. Your best bet would probably be to use the built-in Network Sender and simply relay commands from the Broadcaster to that plugin.

For my own purposes, I have a VPN connection from my iPhone to my router. I connect it to my local network when I need to, and then it can receive the UDP broadcasts (although I'm not currently using that feature). It also allows me access to my web-based interfaces without publishing them outward facing to the internet.

~K

Re: Network Broadcast Sender / Listener

Posted: Tue Dec 29, 2009 4:21 pm
by wayner
A question on the functionality of Network Sender. I have a Control4 home automation system for stuff like lighting. The controller for this system is running a stripped down version of Linux. You can communicate with it by sending XML-type commands to port 5020 of your controller. There is absolutely no security around this - you can telnet to port 5020 of the IP address of your controller and start sending commands without having to authenticate. This is obviously bad from a security perspective but this makes it easy to send commands to this system.

For example this command:

Code: Select all

<c4soap name=\"SendToDeviceAsync\" async=\"True\"><param name=\"iddevice\" type=\"number\">41</param><param name=\"data\" type=\"string\"><devicecommand owneridtype=\"\" owneriditem=\"-1\"><command>PUSH_TOGGLE_BUTTON</command><params></params></devicecommand></param></c4soap>\0
Will toggle light # 41. (Note there are some extra \s in the code above as this is taken from a Java program)

Could I use Network Sender in EventGhost to send this type of command?

Thanks for your help.

Re: Network Broadcast Sender / Listener

Posted: Wed Dec 30, 2009 8:33 pm
by kingtd
You'd have to go in and make changes to the Network Sender to get it to do this. It's looking to do some handshaking first (checking a codeword) before it starts to send messages. It may be easier to just use the eventghost "Python Script" command and use some simple code:

Code: Select all

import socket 
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("Control4-hostname-or-IP", 5020)) # Specify the target device and port number
print s.recv(1024)  # Writes anything it tells you when it first connects to the log for troubleshooting.  If there's no initial connect string, you can probably remove this line
s.send("Your XML stuff here\n")  # You could also do eg.event.payload[0] and pass commands to this script from other events.
print s.recv(1024)  # Writes anything it tells you after your command is sent to the log for troubleshooting
s.close()
Hope this helps
~K

Re: Network Broadcast Sender / Listener

Posted: Wed Dec 30, 2009 11:44 pm
by wayner
Thanks - does it make more sense to do this or to just run a java program each time I want to control a light. For example from the command line I can type "java toggleLight" and it toggles a light. I imagine it is trivial to turn this into an eventghost macro triggered by a remote control or whatever, is it not?