Compare commits
No commits in common. "98daa35b46d864ba31d7b0df64008502ff2b2690" and "9569e2c59bd34a0266786c38b8621b5739d15ac6" have entirely different histories.
98daa35b46
...
9569e2c59b
6 changed files with 9 additions and 117 deletions
|
@ -1,17 +0,0 @@
|
||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
|
||||||
# Visual Studio 2012
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PixelHub-Client-Test", "PixelHub-Client-Test\PixelHub-Client-Test.csproj", "{1D99DDDB-9457-4B8D-83B8-06663554F4C4}"
|
|
||||||
EndProject
|
|
||||||
Global
|
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
||||||
Debug|x86 = Debug|x86
|
|
||||||
Release|x86 = Release|x86
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
||||||
{1D99DDDB-9457-4B8D-83B8-06663554F4C4}.Debug|x86.ActiveCfg = Debug|x86
|
|
||||||
{1D99DDDB-9457-4B8D-83B8-06663554F4C4}.Debug|x86.Build.0 = Debug|x86
|
|
||||||
{1D99DDDB-9457-4B8D-83B8-06663554F4C4}.Release|x86.ActiveCfg = Release|x86
|
|
||||||
{1D99DDDB-9457-4B8D-83B8-06663554F4C4}.Release|x86.Build.0 = Release|x86
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
|
@ -95,50 +95,11 @@ void PixelBot::FindServer()
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
|
||||||
// If the advertiser isn't playing the role of a server, then we're not interested
|
// If the advertiser isn't playing the role of a server, then we're not interested
|
||||||
if(strcmp(role, desiredRemoteRole) != 0)
|
if(role != "server") continue;
|
||||||
{
|
|
||||||
Serial.print("Incompatible role "); Serial.print(role); Serial.println(".");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Serial.println("Role ok!");
|
|
||||||
serverPort = atoi(serverPortText);
|
serverPort = atoi(serverPortText);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PixelBot::Connect()
|
|
||||||
{
|
|
||||||
Serial.print("Connecting to "); Serial.print(serverIp); Serial.print(":"); Serial.print(serverPort); Serial.print(" - ");
|
|
||||||
if(!tcpClient.connect(serverIp, serverPort)) {
|
|
||||||
Serial.println("failed!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Serial.println("success!");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PixelBot::Listen()
|
|
||||||
{
|
|
||||||
while(true) {
|
|
||||||
if(!Tick()) {
|
|
||||||
Serial.println("[PixelBot/Server] Exiting main loop.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PixelBot::Tick()
|
|
||||||
{
|
|
||||||
// Make sure that there's something to read
|
|
||||||
if(tcpClient.available() == 0) {
|
|
||||||
delay(10);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
String nextLine = tcpClient.readStringUntil('\n');
|
|
||||||
Serial.print(" > "); Serial.println(nextLine);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -3,60 +3,31 @@
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Connects to a PixelHub server, receives commands, and acts upon them.
|
|
||||||
/// </summmary>
|
|
||||||
class PixelBot
|
class PixelBot
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PixelBot();
|
PixelBot();
|
||||||
~PixelBot();
|
~PixelBot();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Listens for beacon pings that reveal the location of the PixelHub server.
|
|
||||||
/// </summary>
|
|
||||||
/// <description>
|
|
||||||
/// Upon receiving a ping it parses the message to figure out the location of the PixelHub server.
|
|
||||||
/// Once done it fills out a few private variables ready for the TCP connection.
|
|
||||||
/// </description>
|
|
||||||
void FindServer();
|
void FindServer();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Connects the TCP transport connection to the PixelHub server.
|
|
||||||
/// </summary>
|
|
||||||
bool Connect();
|
|
||||||
/// <summary>
|
|
||||||
/// Starts the main listening loop that handles commands from the PixelHub server.
|
|
||||||
/// </summary>
|
|
||||||
void Listen();
|
|
||||||
/// <summary>
|
|
||||||
/// Performs a single tick of the listen loop.
|
|
||||||
/// Very useful if you want to do other things at the same time as handling commands from the PixelHub server.
|
|
||||||
/// </summary>
|
|
||||||
bool Tick();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// ~~~ Manual Settings ~~~ //
|
|
||||||
char desiredRemoteRole[7] = { 's', 'e', 'r', 'v', 'e', 'r', '\0' };
|
|
||||||
// ~~~ Automatic Settings ~~~ //
|
|
||||||
// The IP address of the remote PixelHub server. Autofilled by the FindServer() method.
|
|
||||||
char serverIp[16];
|
char serverIp[16];
|
||||||
// The port number that the PixelHub server is running on. Autofilled by the FindServer() method.
|
|
||||||
int serverPort = -1;
|
int serverPort = -1;
|
||||||
|
|
||||||
// ~~~ Auto Discovery System ~~~ //
|
// ~~~ Auto Discovery System ~~~ //
|
||||||
|
|
||||||
// The multicast address that the PixelHub beacon is broadcasting on.
|
// The address that the PixelHub beacon is broadcasting on.
|
||||||
IPAddress beaconAddress = IPAddress(239, 62, 148, 30);
|
IPAddress beaconAddress = IPAddress(239, 62, 148, 30);
|
||||||
// The multicast port number that the PixelHub beacon is broadcasting on.
|
// The port number that the PixelHub beacon is broadcasting on.
|
||||||
unsigned int beaconPort = 5050;
|
unsigned int beaconPort = 5050;
|
||||||
|
|
||||||
// The size of the datagram buffer that is used to buffer incoming messages.
|
// The size of the datagram buffer that is used to buffer incoming messages.
|
||||||
int datagramBufferSize = 256;
|
int datagramBufferSize = 256;
|
||||||
|
|
||||||
// ~~~ PixelHub Server Client ~~~ //
|
// ~~~ ~~~ //
|
||||||
|
|
||||||
// The TCP client to use as the PixelHub server transport connection.
|
// The TCP client
|
||||||
WiFiClient tcpClient = WiFiClient();
|
WiFiClient tcpClient = WiFiClient();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -37,13 +37,12 @@ void setup()
|
||||||
|
|
||||||
printWiFiInfoLocal();
|
printWiFiInfoLocal();
|
||||||
pixelBot.FindServer();
|
pixelBot.FindServer();
|
||||||
pixelBot.Connect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
pixelBot.Tick();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
//#include <string.h>
|
//#include <string.h>
|
||||||
//#include <algorithm>
|
//#include <algorithm>
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "Utilities.h"
|
|
||||||
#include "Arduino.h"
|
|
||||||
|
|
||||||
int findChar(char* str, char targetChar)
|
int findChar(char* str, char targetChar)
|
||||||
{
|
{
|
||||||
|
@ -20,13 +16,3 @@ int getPosition(const char *array, size_t size, char c)
|
||||||
return (end == match)? -1 : (match-array);
|
return (end == match)? -1 : (match-array);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void Utilities::PrintCharsAsHex(char* charArray, size_t length)
|
|
||||||
{
|
|
||||||
for(int i = 0; i < length; i++)
|
|
||||||
{
|
|
||||||
Serial.print((int)(charArray[i]), HEX);
|
|
||||||
Serial.print(" ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -9,15 +9,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
int findChar(char* str, char targetChar);
|
int findChar(char* str, char targetChar);
|
||||||
|
|
||||||
int getPosition(const char *array, int size, char c);
|
int getPosition(const char *array, int size, char c);
|
||||||
|
|
||||||
class Utilities
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static void PrintCharsAsHex(char* charArray, size_t length);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
Reference in a new issue