Skip to content

Commit

Permalink
Particle - added basic discovery support
Browse files Browse the repository at this point in the history
  • Loading branch information
Rick authored and Rick committed Sep 26, 2015
1 parent d714d7c commit 68bf49e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
20 changes: 16 additions & 4 deletions Particle/Core/AtmoOrb_UDP.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

// UDP SETTINGS
#define SERVER_PORT 49692
#define DISCOVERY_PORT 49692
UDP client;
IPAddress multicastIP(239, 15, 18, 2);

Expand All @@ -17,8 +18,10 @@ Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

// UDP buffers
#define BUFFER_SIZE 5 + 3 * PIXEL_COUNT
#define BUFFER_SIZE_DISCOVERY 5
#define TIMEOUT_MS 500
uint8_t buffer[BUFFER_SIZE];
uint8_t bufferDiscovery[BUFFER_SIZE_DISCOVERY];

// SMOOTHING SETTINGS
#define SMOOTH_STEPS 50 // Steps to take for smoothing colors
Expand Down Expand Up @@ -58,12 +61,12 @@ void loop(){
unsigned int i = 0;

// Look for 0xC0FFEE
if(buffer[i++] == 0xC0 && buffer[i++] == 0xFF && buffer[i++] == 0xEE){
if(buffer[i++] == 0xC0 && buffer[i++] == 0xFF && buffer[i++] == 0xEE)
{
byte commandOptions = buffer[i++];
byte rcvOrbID = buffer[i++];

// Command option: 1 = force off | 2 = validate command by Orb ID
// Command option: 1 = force off | 2 = validate command by Orb ID | 8 = discovery
if(commandOptions == 1)
{
// Orb ID 0 = turn off all lights
Expand All @@ -85,7 +88,16 @@ void loop(){
return;
}
}

else if(commandOptions == 8)
{
// Respond to remote IP address with Orb ID
IPAddress remoteIP = client.remoteIP();
bufferDiscovery[0] = orbID;

client.sendPacket(bufferDiscovery, BUFFER_SIZE_DISCOVERY, remoteIP, DISCOVERY_PORT);
return;
}

byte red = buffer[i++];
byte green = buffer[i++];
byte blue = buffer[i++];
Expand Down
20 changes: 16 additions & 4 deletions Particle/Photon/AtmoOrb_UDP.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

// UDP SETTINGS
#define SERVER_PORT 49692
#define DISCOVERY_PORT 49692
UDP client;
IPAddress multicastIP(239, 15, 18, 2);

Expand All @@ -17,8 +18,10 @@ Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

// UDP buffers
#define BUFFER_SIZE 5 + 3 * PIXEL_COUNT
#define BUFFER_SIZE_DISCOVERY 5
#define TIMEOUT_MS 500
uint8_t buffer[BUFFER_SIZE];
uint8_t bufferDiscovery[BUFFER_SIZE_DISCOVERY];

// SMOOTHING SETTINGS
#define SMOOTH_STEPS 50 // Steps to take for smoothing colors
Expand Down Expand Up @@ -58,12 +61,12 @@ void loop(){
unsigned int i = 0;

// Look for 0xC0FFEE
if(buffer[i++] == 0xC0 && buffer[i++] == 0xFF && buffer[i++] == 0xEE){
if(buffer[i++] == 0xC0 && buffer[i++] == 0xFF && buffer[i++] == 0xEE)
{
byte commandOptions = buffer[i++];
byte rcvOrbID = buffer[i++];

// Command option: 1 = force off | 2 = validate command by Orb ID
// Command option: 1 = force off | 2 = validate command by Orb ID | 8 = discovery
if(commandOptions == 1)
{
// Orb ID 0 = turn off all lights
Expand All @@ -85,7 +88,16 @@ void loop(){
return;
}
}

else if(commandOptions == 8)
{
// Respond to remote IP address with Orb ID
IPAddress remoteIP = client.remoteIP();
bufferDiscovery[0] = orbID;

client.sendPacket(bufferDiscovery, BUFFER_SIZE_DISCOVERY, remoteIP, DISCOVERY_PORT);
return;
}

byte red = buffer[i++];
byte green = buffer[i++];
byte blue = buffer[i++];
Expand Down

0 comments on commit 68bf49e

Please sign in to comment.