I’m trying to use UDP to wirelessly send files from a SD card attached to my photon to a computer running a node.js server, but right now my goal is just to send basically anything from a photon to a computer. I’m trying to use about the simplest code that I can to minimize anywhere there might be an error, and the code for the photon and the server both run fine and appear to be working, except that nothing is actually sent.
Photon code:
UDP Udp;
unsigned char TxMsg[12] = { 1, 254, 1, 254, 1, 254, 43, 212, 71, 184, 3, 252 };
void setup() {
Udp.begin(9000);
}
void loop() {
Udp.beginPacket(IPAddress(0,0,0,0), 9000);
Udp.write(TxMsg, 12);
Udp.endPacket();
delay(500);
}
Nodejs:
var dgram = require('dgram');
var udpServer = dgram.createSocket('udp4');
udpServer.on('listening',function(){
var address = udpServer.address();
var port = address.port;
var family = address.family;
var ipaddr = address.address;
console.log('Server is listening at port: ' + port);
console.log('Server ip: ' + ipaddr);
console.log('Server is IP4/IP6: ' + family);
});
udpServer.on('message', function(message, remote){
console.log('recieved message:');
console.log(message);
console.log('\nremote:');
console.log(remote);
});
udpServer.on('close',function(){
console.log('Socket is closed !');
});
udpServer.on('error',function(error) {
console.log('Error: ' + error);
udpServer.close();
});
udpServer.bind(9000);
I’m a complete beginner at this stuff, so please excuse the dumb question, but what IP should I use? I thought 0.0.0.0 was the ip that every device on the network could communicate with for some reason but all the example code I found online didn’t use it. Running hostname -I
in terminal (my laptop runs Ubuntu) gives me two different IP addresses.
I also think part of the problem might be that i’m using an iPhone hotspot for internet right now, as i’m not at home and there’s no other internet. I saw a post saying if your router doesn’t have UDP enabled your code won’t work, but i’m not sure how to check that on an iPhone. I’ll try tonight at home on an actual wifi network where I can be sure UDP is enabled, but any other ideas for why this isn’t working?
Thanks in advance
Ben