Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

When receiving UDP with nordic characters?

Questions and comments specific to a particular plugin should go here.
skribb
Experienced User
Posts: 228
Joined: Thu Feb 12, 2015 7:22 pm
Location: Win7 64bit

When receiving UDP with nordic characters?

Post by skribb »

Code: Select all

06:15:05   error: uncaptured python exception, closing channel <eg.CorePluginModule.Broadcaster.Server connected 192.168.0.104:33333 at 0x47d2800> (<type 'exceptions.UnicodeDecodeError'>:'ascii' codec can't decode byte 0xc3 in position 12: ordinal not in range(128) [asyncore.pyc|read|76] [asyncore.pyc|handle_read_event|416] [C:\Program Files (x86)\EventGhost\plugins\Broadcaster\__init__.py|handle_read|95] [C:\Program Files (x86)\EventGhost\eg\Classes\PluginBase.py|TriggerEvent|133] [C:\Program Files (x86)\EventGhost\eg\Classes\EventThread.py|TriggerEvent|78] [C:\Program Files (x86)\EventGhost\eg\Classes\EventGhostEvent.py|__init__|84])
Now, I suppose this error is because of the nordic characters not being part of the Unicode charset or whatever? Or is it something else
Automation is life.

Win7 64bit
EG: v0.5.0-rc4
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: When receiving UDP with nordic characters?

Post by kgschlosser »

well this is a hex of the character you are receiving

0xc3

i do not know if that hex value is a unicode value or not. but i am sure with some google searching we can find out
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: When receiving UDP with nordic characters?

Post by kgschlosser »

ok the 0xc3 is in fact a unicode character. it's a capital A with e Tilda (~) above it. I have done a little bit of reading on this. and i think there is a way to get unicode support into EG for the log. but as to how much work it will be i am unsure due to how EG uses events to trigger actions. it's one thing to simply get it to display properly in the log. it's something completely different as to how to handle having eg search for an event in the tree. it' s beyond my knowledge at present. and it would also be something that would have to be done at the core level. but the broadcaster plugin can be modified to work properly simply by going into the plugin and at line 91-99 this the the current code. now this is a oversimplified way of correcting the socket close problem. and the characters may not appear properly. don't know read below.

THIS HAS NOT BEEN TESTED.

Code: Select all

if (not my_addr) or self.selfBroadcast:
    bits = data.split(str(self.payDelim))
    commandSize=len(bits)
    if commandSize==1:
        self.plugin.TriggerEvent(bits[0])
    if commandSize==2:
        self.plugin.TriggerEvent(bits[0],bits[1])
    if commandSize>2:
        self.plugin.TriggerEvent(bits[0],bits[1:])
and it needs to be changed to this

Code: Select all

# quick and dirty hack to stop the broadcaster plugin from disconnecting sockets
# due to unicode encoded data

if (not my_addr) or self.selfBroadcast:
    bits = data.split(str(self.payDelim))
    commandSize=len(bits)
    if commandSize==1:
        self.plugin.TriggerEvent(str(bits[0]))
    if commandSize==2:
        self.plugin.TriggerEvent(str(bits[0]), bits[1])
    if commandSize>2:
        self.plugin.TriggerEvent(str(bits[0]), bits[1:])
If you like the work I have been doing then feel free to Image
skribb
Experienced User
Posts: 228
Joined: Thu Feb 12, 2015 7:22 pm
Location: Win7 64bit

Re: When receiving UDP with nordic characters?

Post by skribb »

This is so weird because the message that is being received is t1.SUNRISE which is what my tablet sends to EG to start my morning alarm stuff in EG. Which works 99% of the time..... I'm not even sending a à character (Ä is nordic tho, but i'm not using that one either.....)

thanks for your fixing attempt KG, I will switch out the snippet you mentioned and see if my problem is ameliorated by that. :D
Automation is life.

Win7 64bit
EG: v0.5.0-rc4
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: When receiving UDP with nordic characters?

Post by kgschlosser »

let me know if it works or not... i am curious to know
If you like the work I have been doing then feel free to Image
skribb
Experienced User
Posts: 228
Joined: Thu Feb 12, 2015 7:22 pm
Location: Win7 64bit

Re: When receiving UDP with nordic characters?

Post by skribb »

kgschlosser wrote:let me know if it works or not... i am curious to know
Why certainly! that is the least I can do :D

I'm eagerly awating tomorrow's morning alarm. Crossing my thumbs and everything :cry:
Automation is life.

Win7 64bit
EG: v0.5.0-rc4
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: When receiving UDP with nordic characters?

Post by kgschlosser »

it should do the trick. if not i can key something up to do a right proper decode. on it.
If you like the work I have been doing then feel free to Image
skribb
Experienced User
Posts: 228
Joined: Thu Feb 12, 2015 7:22 pm
Location: Win7 64bit

Re: When receiving UDP with nordic characters?

Post by skribb »

Status updatE:
No error so far :D
Automation is life.

Win7 64bit
EG: v0.5.0-rc4
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: When receiving UDP with nordic characters?

Post by kgschlosser »

it's a sloppy hack. and not the proper way. but it should work for ya.

and it's easy
If you like the work I have been doing then feel free to Image
skribb
Experienced User
Posts: 228
Joined: Thu Feb 12, 2015 7:22 pm
Location: Win7 64bit

Re: When receiving UDP with nordic characters?

Post by skribb »

kgschlosser wrote:it's a sloppy hack. and not the proper way. but it should work for ya.

and it's easy

Don't worry about it. That's exactly my style :D
Automation is life.

Win7 64bit
EG: v0.5.0-rc4
skribb
Experienced User
Posts: 228
Joined: Thu Feb 12, 2015 7:22 pm
Location: Win7 64bit

Re: When receiving UDP with nordic characters?

Post by skribb »

I bring grave news, fellow tinkerer....

Code: Select all

2016-11-19 09:04:44  INFO: error: uncaptured python exception, closing channel <eg.CorePluginModule.Broadcaster.Server connected 192.168.0.104:33333 at 0x47d6940> (<type 'exceptions.UnicodeDecodeError'>:'ascii' codec can't decode byte 0xc3 in position 10: ordinal not in range(128) [asyncore.pyc|read|76] [asyncore.pyc|handle_read_event|416] [C:\Program Files (x86)\EventGhost\plugins\Broadcaster\__init__.py|handle_read|95] [C:\Program Files (x86)\EventGhost\eg\Classes\PluginBase.py|TriggerEvent|133] [C:\Program Files (x86)\EventGhost\eg\Classes\EventThread.py|TriggerEvent|78] [C:\Program Files (x86)\EventGhost\eg\Classes\EventGhostEvent.py|__init__|84])

Maybe i should try what you wrote here: viewtopic.php?f=4&t=8116&hilit=asyncore&start=45#p40878

For now I will experiment with automatically restarting broadcaster on Schdedulghost
Automation is life.

Win7 64bit
EG: v0.5.0-rc4
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: When receiving UDP with nordic characters?

Post by kgschlosser »

do this it's the much better way and not a sloppy hack

give it a shot

HAS NOT BEEN TESTED

Code: Select all

    if (not my_addr) or self.selfBroadcast:
        bits = data.split(str(self.payDelim))
        commandSize=len(bits)
        if commandSize:
            suffix = bits[0]
            if commandSize == 2:
                payload = bits[1]
            elif commandSize > 2:
                payload = bits[1:]
            else:
                payload = None
            try:
                self.plugin.TriggerEvent(suffix=str(suffix), payload=payload)
            except UnicodeDecodeError:
                self.plugin.TriggerEvent(suffix=suffix.encode('utf8'), payload=payload)
            
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: When receiving UDP with nordic characters?

Post by kgschlosser »

you may or may not have to change the suffix.decode('utf8') to suffix.decode('latin1')

this unicode stuff i have not really messed with. so this is a learning process for the both of us
If you like the work I have been doing then feel free to Image
davidmark
Experienced User
Posts: 85
Joined: Thu Jan 01, 2015 5:25 pm

Re: When receiving UDP with nordic characters?

Post by davidmark »

kgschlosser wrote:you may or may not have to change the suffix.decode('utf8') to suffix.decode('latin1')

this unicode stuff i have not really messed with. so this is a learning process for the both of us
Depends on what sent the bytes over UDP. UTF-8 makes the most sense here, but the bigger problem is that there is a typo in the suggestion (encode rather than decode). Simply document that anything broadcasting to EG needs to send UTF-8 encoded bytes, which will be decoded on reception. That puts the onus on the sender to comply. Shouldn't need try-except at all, other than to log an error if the sender does not comply.

And need to do the payload as well as the event name. I covered all but when the payload length is more than 2.

http://www.eventghost.org/forum/viewtop ... 459992c984
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: When receiving UDP with nordic characters?

Post by kgschlosser »

thanks David for catching that dumbass messup.. LOL

happens with me all the time tho.


yeah this is for nordic characters. so it could be latin1 that's why i stated that..

but his error is for only one hex so the utf8 should work. it's when ya get 2 hex characters but the error message in the traceback doesn't show the message. and i am not sure if on a unicode error if it shows all characters out of ordinal range or just the first one it comes across.. i am thinking it's probably the first one it comes across


i am running into a similar problem with a plugin i am working on but if i encode the string with utf8 it builds the xml tree but won't convert the xml tree into a string. and if i convert it using str() i get an error elsewhere. so not exactly sure how to handle that kind of issue because i have to iterate through the whole thing..... unless maybe if i use isinstance to check and see if it's not a basestring and if not then convert it and if it's unicode then to encode it. i dunno i will have to mess with it
If you like the work I have been doing then feel free to Image
Post Reply