I’d like to broadcast data from my photon on a closed WiFi network that is not connected to the internet. Is this possible with the Photon? I’ve gotten the broadcasting down fine when it is on the internet. (I’m using the simple-osc library to send broadcast on IP 255.255.255.255) I just can’t figure out how to get my photon to join a wifi network that has no internet, or an ad-hoc network for instance.
This is important because the remote locations / conference venues where the system I’m building will be used are likely to not have usable internet.
Check out the docs about System Modes and WiFi. You can Use SEMI_AUTOMATIC or MANUAL mode, and just connect to the local WiFi without trying to talk to the cloud.
Ah great, this looks helpful. Will test it out shortly. But, second question. If I put my photon in semi-auto or manual mode, how do I ever flash new code to it again / get it back on my internet network? (Since as I understand it, this comes from the cloud.)
Putting it in safe mode should work. You could also create a function which you call from within your network, that connects it to the cloud? Flashing it over USB is also possible.
One thing that used to be required tho’ was to use the subnet broadcast address rather than 255.255.255.255.
I’ve not tested if this has changed with one of the recent FW updates, but if you can use the subnet address, that’ll work definetly (I’ve done it with the Core and the Photon).
Ok, trying things one step at a time here. And thanks for the safe-mode tip! I’ve added the system_mode automatic to the code, but now it does not appear to be broadcasting anymore. I’ve tried the all broadcast (255.255.255.255) and the subnet mask broadcast, and putting the wifi.setCredentials code to no avail. Other thoughts? Here’s the full code I’m testing with:
// This #include statement was automatically added by the Particle IDE.
#include "InternetButton/InternetButton.h"
// This #include statement was automatically added by the Particle IDE.
#include "simple-OSC/simple-OSC.h"
SYSTEM_MODE(SEMI_AUTOMATIC);
InternetButton b = InternetButton();
UDP Udp;
IPAddress broadcast(255,255,0,0);
void setup() {
// WiFi.setCredentials("NeighbsNotCrims", "DarkMaster", WPA2, WLAN_CIPHER_AES);
b.begin();
Serial.begin(9600);
Udp.begin(7401);
}
void loop(){
if (b.buttonOn(3)) {
b.ledOn(6, 0, 0, 255); // Blue
//Udp.beginPacket(broadcast, 7401);
//Udp.write('a');
//Udp.endPacket();
int xval = b.readX();
int yval = b.readY();
int zval = b.readZ();
Serial.print(xval);
Serial.println("button3");
OSCMessage outMessage("/pong");
// outMessage.addString("test");
// outMessage.addFloat(-3.14);
outMessage.addInt(xval);
outMessage.addInt(yval);
outMessage.addInt(zval);
outMessage.send(Udp, broadcast, 7401);
// Publish the event "button3" for other services like IFTTT to use
//Spark.publish("button3",NULL, 60, PRIVATE);
//delay(500);
}
else {
b.ledOn(6, 0, 0, 0);
}
}
I’ll just test this quickly, but I think, when you’re running SEMI_AUTOMATIC you want to WiFi.connect() first and wait for WiFi.ready() before you do your UDP stuff.
I don't think that this is correct. That looks more like a netmask (but not a proper one). If that is supposed to be your netmask, and your IP numbers look like 192.168.x.y, then the broadcast address would be 192.168.255.255. If you aren't sure what the proper broadcast address should be, let us know what network details you have, and we can try to help you with that.
Hey Thanks ScruffR! Adding the wiwfi.connect() parts helped, and it will now connect, and breathe green, and send some UDP messages on my internet network. It is doing a weird thing where it will send a few OSC messages, then pause for several seconds and then send a few more.
Still not working on a closed network without internet, though. I’m getting the flashing green status. The credential setup should happen before the wifi connect, right?
void setup() {
WiFi.setCredentials("NeighbsNotCrims", "DarkMaster", WPA2, WLAN_CIPHER_AES);
WiFi.connect();
while(!WiFi.ready())
{
Particle.process(); //might need to comment this out
delay(100);
}
b.begin();
Serial.begin(9600);
Udp.begin(7401);
}