Open Pixel Control (OPC) server for Arduino.
Compatible with boards that utilize Arduino style WiFiServer / WiFiClient APIs.
- ESP8266
- NodeMCU
- Adafruit HUZZAH
- ...
- ATSAMD21
- Arduino Zero with WiFi Shield 101 (compiles, not tested)
- Adafruit Feather M0 WiFi - ATSAMD21 + ATWINC1500 (compiles, not tested)
- Particle (Formerly Spark)
If you've run this successfully on other boards let me know!
- In the Arduino IDE, Choose Sketch > Include Library > Manage Libraries
- Search for OpcServer
- Click Install
- platformio lib install 350
- Copy files from src/* into your project
See examples.
#include "OpcServer.h"
Depending on your platform you may need to add other headers. For example ESP8266WiFi.h for ESP8266.
Initialize OpcServer
with WiFiServer
(or TCPServer
for Particle), OpcClient
sized for the number of clients you'd like to support, and a buffer
large enough for the OPC messages you'd like to receive.
WiFiServer server = WiFiServer(OPC_PORT);
OpcClient opcClients[OPC_MAX_CLIENTS];
uint8_t buffer[OPC_BUFFER_SIZE * OPC_MAX_CLIENTS];
OpcServer opcServer = OpcServer(server, OPC_CHANNEL,
opcClients, OPC_MAX_CLIENTS,
buffer, OPC_BUFFER_SIZE);
Optionally add any callback functions you'd like OpcServer
to run when a message is received or a client connects/disconnects.
opcServer.setMsgReceivedCallback(cbOpcMessage);
opcServer.setClientConnectedCallback(cbOpcClientConnected);
opcServer.setClientDisconnectedCallback(cbOpcClientDisconnected);
Then call .begin()
.
opcServer.begin();
Call .process()
in your loop to process any incoming OPC data.
opcServer.process();