Compare commits
2 commits
09e57a6ec1
...
48d61d74c7
Author | SHA1 | Date | |
---|---|---|---|
48d61d74c7 | |||
f6946ddb27 |
4 changed files with 53 additions and 3 deletions
|
@ -8,8 +8,10 @@
|
|||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiUdp.h>
|
||||
|
||||
#include "Utilities.h"
|
||||
|
||||
char ssid[] = "ssid";
|
||||
char password[] = "password";
|
||||
char password[] = "pass";
|
||||
|
||||
// The address that the PixelHub beacon is broadcasting on.
|
||||
IPAddress beaconAddress(239, 62, 148, 30);
|
||||
|
@ -46,6 +48,7 @@ void setup()
|
|||
Serial.println("success!");
|
||||
|
||||
printWiFiInfoLocal();
|
||||
findServer();
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
@ -94,6 +97,34 @@ void findServer()
|
|||
Serial.print("Raw content: ");
|
||||
Serial.write(datagramBuffer, datagramSize);
|
||||
Serial.println();
|
||||
|
||||
Serial.print("Parsing datagram - ");
|
||||
|
||||
// Parse the recieved message
|
||||
char* datagramStr = (char*)datagramBuffer;
|
||||
|
||||
// Find the positions of the key characters
|
||||
int atPos = findChar(datagramStr, '@');
|
||||
int colonPos = findChar(datagramStr, ':');
|
||||
|
||||
char* role;
|
||||
char* serverIp;
|
||||
char* portNumberText;
|
||||
|
||||
strncpy(role, datagramStr, atPos);
|
||||
strncpy(serverIp, datagramStr + atPos + 1, colonPos);
|
||||
strncpy(portNumberText, datagramStr + colonPos + 1, datagramSize - 1);
|
||||
|
||||
Serial.println("complete.");
|
||||
|
||||
Serial.print("Role: "); Serial.print(role); Serial.print(" ");
|
||||
Serial.print("Remote IP: "); Serial.print(serverIp); Serial.print(" ");
|
||||
Serial.print("Port number: "); Serial.print(portNumberText);
|
||||
Serial.println();
|
||||
|
||||
// If the advertiser isn't playing the role of a server, then we're not interested
|
||||
if(role != "server") continue;
|
||||
|
||||
int portNumber = atoi(portNumberText);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
9
PixelHub-Client/Utilities.cpp
Normal file
9
PixelHub-Client/Utilities.cpp
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include <string.h>
|
||||
|
||||
int findChar(char* str, char targetChar)
|
||||
{
|
||||
for(int i = 0; strcmp(&str[i], "\0") == 0; i++) {
|
||||
if(str[i] == targetChar) return i;
|
||||
}
|
||||
}
|
||||
|
10
PixelHub-Client/Utilities.h
Normal file
10
PixelHub-Client/Utilities.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
/**
|
||||
* Various useful utility functions for the Arduino
|
||||
*********************************************************
|
||||
* By Starbeamrainbowlabs <bugs@starbeamrainbowlabs.com> - https://starbeamrainbowlabs.com)
|
||||
* Originally written for PixelHub - http://git.starbeamrainbowlabs.com/sbrl/PixelHub
|
||||
*
|
||||
* Thanks to Rob Miles for getting me into this :-)
|
||||
*/
|
||||
|
||||
int findChar(char* str, char targetChar);
|
|
@ -153,7 +153,7 @@ namespace PixelHub.Net
|
|||
/// </summary>
|
||||
private async Task emitOnce()
|
||||
{
|
||||
await Send($"{Role}@{LocalIP}:{Port}\n");
|
||||
await Send($"{Role}@{LocalIP}:{Port}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Reference in a new issue