64 lines
1.9 KiB
C++
64 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#include <ESP8266WiFi.h>
|
|
#include <WiFiUdp.h>
|
|
|
|
/// <summary>
|
|
/// Connects to a PixelHub server, receives commands, and acts upon them.
|
|
/// </summmary>
|
|
class PixelBot
|
|
{
|
|
public:
|
|
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();
|
|
|
|
/// <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:
|
|
// ~~~ 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];
|
|
// The port number that the PixelHub server is running on. Autofilled by the FindServer() method.
|
|
int serverPort = -1;
|
|
|
|
// ~~~ Auto Discovery System ~~~ //
|
|
|
|
// The multicast address that the PixelHub beacon is broadcasting on.
|
|
IPAddress beaconAddress = IPAddress(239, 62, 148, 30);
|
|
// The multicast port number that the PixelHub beacon is broadcasting on.
|
|
unsigned int beaconPort = 5050;
|
|
|
|
// The size of the datagram buffer that is used to buffer incoming messages.
|
|
int datagramBufferSize = 256;
|
|
|
|
// ~~~ PixelHub Server Client ~~~ //
|
|
|
|
// The TCP client to use as the PixelHub server transport connection.
|
|
WiFiClient tcpClient = WiFiClient();
|
|
|
|
bool processCommand(String command);
|
|
};
|
|
|