We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi all,
I'm trying to get this test connection to work: // import UDP library import hypermedia.net.*;
UDP udp; // the UDP object
byte[] command = new byte[3];
void setup(){
command[0] = 69; // turn on zone 1
command[1] = 100; // at hue 100
command[2] = 85; // always end with 85
udp = new UDP( this, 50000, "192.168.1.100");
udp.send( command );
}
But I get the following errors:
opening socket failed!
address:192.168.1.100, port:50000 [group:null] Cannot assign requested address: Cannot bind
Can someone tell me where to look to solve this issue? Thanks very much in advance, best, danielle
Answers
hi danielle, usually for udp you dont need to specify an ip for creating the socket. try
UDP(this, 50000);
for creating the socket, and then send messages withudp.send(command, ip, port);
.Whats the other part of the connection? are you connecting two programms on the same machine? if one is already on port 50000 it might be blocked for the other.
i hope that helps, i've never worked with this library and used java udp directly.
Hi, Thank you very much for your response. I've tried out your suggestion but still no luck. This is the adapted program:
I've also tried with another port for the localhost (new UDP(this, port);). I don't get any errors, the port is opened but I also get no result. The program hangs at println(udp.isBroadcast ()); The program is for connecting to a wifi LED lamp (http://www.applamp.nl/service/applamp-api/). This program runs on a PC and it tries to connect to the wifi box of the lamps which has the port and IP address as stated above.
I must say I don't have so much faith in this library. I've tried working with it before but no luck either. So if you could share a snipet of the UPD Java code you use I'd be very grateful.
Thanks in advance for your help, best, danielle.
Hi danielle, i will write a little code snippet for udp communication tonight, and post it here.
Super! TIA, danielle
Hi danielle, i packaged my helper classes into a library, which you can get here from github. just unzip and put into your library folder. feel free to browse the source here. The interesting parts are in the
startListening()
method, that sets up the socket and channel etc.here a adapted version of the example:
you can check on your local machine or on a remote machine if the sendMessage worked by listening with netcat on the target port. just open a terminal and type
nc -lu 50000
to listen for udp on port 50000. I hope that code works for you. if not just let me know.Thank you so very much! Great stuff. I've tested your code. Everything works except the sending of the code to the lamp. Or maybe it works but the lamp doesn't react :( I've tried different things: - working with the testlocal socket (commented it out) - changing the wireless network (it seemed unstable) - changing the command send (still nothing happens)
I've ran out of idea's for now. Do you have any idea where I can start to solve this mystery? Could it have to do with my localhost? Is it the byte array? Maybe that isn't well formed, although I don't get any errors. Is there a way I can test if the bytes are at least send? The program is just one direction by the way. Just the Processing script sending the bytes to the socket of the lamp.
If I look at the original code (copied below for you convenience it seems pretty straightforward. But maybe you can see what I'm missing. Thanks ever so much for all your trouble. I hope we can work it out. Best, danielle.
Original JS code: Usage in Node JS: //load this wifi box class var WifiBoxModule = require('wifibox.js'); var byteCommand = require('commands.js'); //create instance with wifi box ip and port var box = new WifiBoxModule("192.168.1.100", 50000); //send a command ( see commands.js ) box.command(byteCommand.bulb.color.hue(180)); box.command(byteCommand.bulb.white.allOn()); **/
OK, I see that you already gave instructions on how to monitor the trafic. I'm trying to get it to work, I'm on windows, it isn't installed yet. I'll be back.
I've managed to install and try it out. I've typed: nc -luv 50000 Reply: 50000: inverse host lookup failed: h_errno 11004: NO_DATA
I've tried pressing the t all the time.
Hope this means anything to you? Thanks, d
hm ... it might be that you need the
p
parameter with your version of netcat to specify the 50000 port. i put my machines local network ip in the testlocal address so i could check with netcat on the same machine if the commands are sent, you would have to put your ip address in there.try
nc -luvp 50000
here are some other thoughts that might be the issue. i am guessing here :)
whats the output of the processing sketch in the beginning? your machine and the lamp are in the same network segment, like pc's ip=192.168.1.1 lamp's ip=192.168.1.2 ?
you could try to send the command bytes to the broadcast address (255.255.255.255), every machine in your network listening on your specified port would/should get the message.
can you write a sketch listening on the needed port, run it on another computer, to see if the connection over the network works?
is there a firewall involved? windows built in maybe?
does it work with nodejs?
have you tried different commands?
{0x22, 0x00, 0x55}
looks like the on command for white bulbs?Hi,
I've tried nc -lup 50000 there's no error now but also nothing happens, no output.
I've tried switching of the firewall, still no result.
I already tried different codes. It is the colour RGBW so it is no use trying to use the code for the white bulbs.
When I use 255.etc I do get some output in the netcat terminal: B VAdUB U I'm sending the following command:
I don't know if that makes sense :)
This is the output of your helper:
I don't really know anything about networking but am I right when I say that the lamp wifi box net6 Microsoft Virtual WiFi Miniport Adapter
/fe80:0:0:0:b490:c6dc:90e8:924f%15
(I think that is it.) Doesn't have an ip address at all? I've discovered some more documentation. This is posted under an other name but apparently it is the same hardware: http://www.limitlessled.com/dev/
I wouldn't know. I don't see these numbers appearing in the helper output... Where can I find them?
I haven't tried with nodeJS, I don't have it on my pc and don't know anything about it. But I could try if none of this makes sense to you.
Thanks in advance for your feedback, best, danielle.