belsamber has asked for the wisdom of the Perl Monks concerning the following question:
For example, you can turn the bulbs on by sending a UDP packet with a payload of 0x22 0x00 0x55. You can adjust hue of the bulbs with a payload of 0x21 0x00 0x55 where the middle hex chunk varies from 0x00 to 0xFF. Example code:
The first "send" works correctly and sends raw hex digits. A packet decode looks like this (note the 210255 at the end of the packet):#!/usr/bin/perl use strict; use warnings; use IO::Socket; my $bulb_sock = IO::Socket::INET->new( Proto => 'udp', PeerPort => 50000, PeerAddr => '192.168.1.8', ) or die "Could not create socket: $!\n"; $bulb_sock->send("\x22\x02\x55") or die "Send Error: $!\n"; my $variable; for (my $i=1 ; $i<3 ; $i++) { $variable = "\x21"."$i"."\x55"; $bulb_sock->send("$variable") or die "Send Error: $!\n"; }
but any time I try to manipulate the values as in the loop, it ends up sending the ASCII value of the data instead of treating it as hex. the other packets are as follows:15:51:05.035323 IP localhost.53816 > 192.168.1.8.50000: UDP, length 3 0x0000: 0200 0000 4500 001f 3e3e 0000 4011 bd5c ....E...>>..@..\ 0x0010: ac1b 1168 c0a8 0108 d238 c350 000b 7518 ...h.....8.P..u. 0x0020: 2102 55 !.U
Note that the 21 works, and the 55 works, but I can't cast the middle number into hex no matter what I try. Any thoughts?15:51:05.035358 IP localhost.53816 > 192.168.1.8.50000: UDP, length 3 0x0000: 0200 0000 4500 001f f877 0000 4011 0323 ....E....w..@..# 0x0010: ac1b 1168 c0a8 0108 d238 c350 000b 74e9 ...h.....8.P..t. 0x0020: 2131 55 !1U 15:51:05.035369 IP localhost.53816 > 192.168.1.8.50000: UDP, length 3 0x0000: 0200 0000 4500 001f 3f34 0000 4011 bc66 ....E...?4..@..f 0x0010: ac1b 1168 c0a8 0108 d238 c350 000b 74e8 ...h.....8.P..t. 0x0020: 2132 55
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sending raw hex in UDP packets
by BrowserUk (Patriarch) on May 07, 2013 at 06:51 UTC | |
by belsamber (Initiate) on May 07, 2013 at 08:14 UTC | |
by BrowserUk (Patriarch) on May 07, 2013 at 08:33 UTC | |
by belsamber (Initiate) on May 07, 2013 at 11:36 UTC | |
|
Re: Sending raw hex in UDP packets
by graff (Chancellor) on May 08, 2013 at 00:01 UTC | |
|
Re: Sending raw hex in UDP packets
by Browne (Initiate) on Jan 08, 2014 at 22:56 UTC |