Bind
C++ UI framework for Arduino
 
Loading...
Searching...
No Matches
BindOverWifi.h
1#ifndef BINDOVERUDP_H
2#define BINDOVERUDP_H
3#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO_2W) || defined(ARDUINO_ARCH_ESP8266)
4#if __has_include("BindUserConfig.h")
5#include "BindUserConfig.h"
6#endif
7#ifndef BIND_DISABLE_WIFI
8#include "Bind.h"
9#include <Arduino.h>
10#include <Stream.h>
11#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO_2W)
12// This takes too much memory on boards with limited memory, so we let the user include it if needed
13//#include <WiFi.h> // For ESP32 and RP2040 with WiFi support
14#include <AsyncUDP.h> // Both ESP32 and RP2040 support AsyncUDP
15#elif defined(ARDUINO_ARCH_ESP8266)
16// This takes too much memory on boards with limited memory, so we let the user include it if needed
17//#include <ESP8266WiFi.h>
18#include <BindUtil/BindAsyncUDP.h> // ESP8266 uses ESPAsyncUDP
19#endif
20
21#define UDP_DEBUG_MSG 0 // Set to 1 to enable debug messages
22
23/*
24 * This class is used to send and receive data over UDP to be used
25 * with the Bind class.
26*/
27class UDPStream : public Stream
28{
29private:
30 bool sendPackets = false;
31 static uint8_t discoveryMsg[];
32 static uint8_t connectMsg[];
33 static uint8_t stopMsg[];
34 static uint8_t bindHeartbeat[];
35 static uint16_t bindPort;
36 IPAddress canvasIP = IPAddress(0, 0, 0, 0);
37 void handleUDP(UDPStream& udpStream, AsyncUDPPacket& packet);
38 Bind *_bind;
39 AsyncUDP udp;
40 uint32_t lastHeartbeat = 0;
41 const char* bindname;
42public:
43 UDPStream() : canvasIP(IPAddress(0, 0, 0, 0)), sendPackets(false), _bind(nullptr) {}
44 bool begin(const char* bindname, Bind &bind);
45 bool begin(Bind &bind, const char* bindname);
46 size_t write(const uint8_t *buffer, size_t size) override;
47 int available() override { return 0; }
48 int read() override { return 0; }
49 int peek() override { return 0; }
50 void flush() override {}
51 size_t write(uint8_t) override { return 0; }
52};
53#endif // BIND_DISABLE_WIFI
54#endif // defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_RP2040)
55#endif // BINDOVERUDP_H
The Bind class provides a framework for creating interactive applications with BindCanvas.
Definition Bind.h:62