diff --git a/examples/W5500/client-with-W5500-ESP8266/client-with-W5500-ESP8266.ino b/examples/W5500/client-with-W5500-ESP8266/client-with-W5500-ESP8266.ino new file mode 100644 index 0000000..29db13e --- /dev/null +++ b/examples/W5500/client-with-W5500-ESP8266/client-with-W5500-ESP8266.ino @@ -0,0 +1,111 @@ +#include +#include + +#include "TinyMqtt.h" // https://github.com/hsaturn/TinyMqtt + +#define WIZRST D3 //Specify pin to use for reseting W5500 +#define WIZCS D1 //Specify the pin for SPI CS + +#define PORT 1883 +MqttBroker broker(PORT); +unsigned long Time; +unsigned long freeRam; + +/** Basic Mqtt Broker + * + * +-----------------------------+ + * | ESP | + * | +--------+ | + * | | broker | | 1883 <--- External client/s + * | +--------+ | + * | | + * +-----------------------------+ + * + * Your ESP will become a MqttBroker. + * You can test it with any client such as mqtt-spy for example + * + */ + +#if defined(USE_ETHERNET) + +byte mac[] = { 0x00, 0xAA, 0xBB, 0xE0, 0x01, 0x25 }; //MAC Address +//IPAddress ip = (192,168,0,88); //Fixed IP Address + +#else + +const char* ssid = "xxxxxxx"; +const char* password = "xxxxxxxx"; + +#endif + + +void WizReset() { + Serial.print("Resetting Wiz W5500 Ethernet Board... "); + pinMode(WIZRST, OUTPUT); + digitalWrite(WIZRST, HIGH); + delay(250); + digitalWrite(WIZRST, LOW); + delay(50); + digitalWrite(WIZRST, HIGH); + delay(350); + Serial.println("Done."); +} + +void setup() +{ + Serial.begin(115200); + +#if defined(USE_ETHERNET) + + Ethernet.init(WIZCS); // SPI CS Pin + SPI.begin(); + WizReset(); + Console << TinyConsole::green << "Starting Ethernet...." << endl; + Ethernet.begin(mac); //Connect using DHCP + //Ethernet.begin(mac,ip); //Connect using Fixed IP + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Console << TinyConsole::red << "Ethernet shield was not found. Sorry, can't run without hardware. :(" << endl; + } else + if (Ethernet.linkStatus() == LinkOFF) { + Console << TinyConsole::red << "Ethernet cable is not connected." << endl; + } + Console << TinyConsole::green << "Local Ethernet IP address: " << Ethernet.localIP() << endl; + broker.begin(); + Console << "Broker ready (eth) : " << Ethernet.localIP() << " on port " << PORT << endl; + +#else + + if (strlen(ssid)==0) + Console << TinyConsole::red << "****** PLEASE MODIFY ssid/password *************" << endl; + WiFi.disconnect(); //Remove previous SSID & Password + WiFi.begin(ssid, password); // Connect to the network + Console << TinyConsole::white << "WiFi Connecting to " << ssid << " ..."; + int i = 0; + while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect + delay(1000); + Console << TinyConsole::white << "."; + i++; + if (i > 20) break; + } + Console << endl << endl; + Console << TinyConsole::green << "Connected to " << ssid << " IP address: " << WiFi.localIP() << endl; + broker.begin(); + Console << "Broker ready (wifi) : " << WiFi.localIP() << " on port " << PORT << endl; + +#endif +} + +void loop() +{ + broker.loop(); + if(millis()-Time>10000) { + Time=millis(); + if(ESP.getFreeHeap()!=freeRam) + { + freeRam=ESP.getFreeHeap(); + Serial.print("RAM:"); + Serial.println(freeRam); + } + } + +} diff --git a/examples/W5500/client-with-W5500-RP2040/RP2040W5500SimpleBroker.binary.zip b/examples/W5500/client-with-W5500-RP2040/RP2040W5500SimpleBroker.binary.zip new file mode 100644 index 0000000..f6fd547 Binary files /dev/null and b/examples/W5500/client-with-W5500-RP2040/RP2040W5500SimpleBroker.binary.zip differ diff --git a/examples/W5500/client-with-W5500-RP2040/client-with-W5500-RP2040.ino b/examples/W5500/client-with-W5500-RP2040/client-with-W5500-RP2040.ino new file mode 100644 index 0000000..234d2e5 --- /dev/null +++ b/examples/W5500/client-with-W5500-RP2040/client-with-W5500-RP2040.ino @@ -0,0 +1,117 @@ +#include +#include + +#include "TinyMqtt.h" // https://github.com/hsaturn/TinyMqtt + +#define WIZRST 20 //Specify pin to use for reseting W5500 = GPIO20 +#define WIZCS 17 //Specify the pin for SPI CS = GPIO17 = D5 + +#define PORT 1883 +MqttBroker broker(PORT); +unsigned long Time; +unsigned long freeRam; + +/** Basic Mqtt Broker + * + * +-----------------------------+ + * | ESP | + * | +--------+ | + * | | broker | | 1883 <--- External client/s + * | +--------+ | + * | | + * +-----------------------------+ + * + * Your ESP will become a MqttBroker. + * You can test it with any client such as mqtt-spy for example + * + */ + +#if defined(USE_ETHERNET) + +byte mac[] = { 0x00, 0xAA, 0xBB, 0xE0, 0x01, 0x25 }; //MAC Address +//IPAddress ip = (192,168,0,88); //Fixed IP Address + +#else + +const char* ssid = "xxxxxxx"; +const char* password = "xxxxxxxx"; + +#endif + + +void WizReset() { + Serial.print("Resetting Wiz W5500 Ethernet Board... "); + pinMode(WIZRST, OUTPUT); + digitalWrite(WIZRST, HIGH); + delay(250); + digitalWrite(WIZRST, LOW); + delay(50); + digitalWrite(WIZRST, HIGH); + delay(350); + Serial.println("Done."); +} + +void setup() +{ + Serial.begin(115200); + +#if defined(USE_ETHERNET) + + Ethernet.init(WIZCS); + SPI.begin(); + WizReset(); + Console << TinyConsole::green << "Starting Ethernet...." << endl; + Ethernet.begin(mac); //Connect using DHCP + //Ethernet.begin(mac,ip); //Connect using Fixed IP + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Console << TinyConsole::red << "Ethernet shield was not found. Sorry, can't run without hardware. :(" << endl; + } else + if (Ethernet.linkStatus() == LinkOFF) { + Console << TinyConsole::red << "Ethernet cable is not connected." << endl; + } + Console << TinyConsole::green << "Local Ethernet IP address: " << Ethernet.localIP() << endl; + broker.begin(); + Console << "Broker ready (eth) : " << Ethernet.localIP() << " on port " << PORT << endl; + +#else + + if (strlen(ssid)==0) + Console << TinyConsole::red << "****** PLEASE MODIFY ssid/password *************" << endl; + WiFi.disconnect(); //Remove previous SSID & Password + WiFi.begin(ssid, password); // Connect to the network + Console << TinyConsole::white << "WiFi Connecting to " << ssid << " ..."; + int i = 0; + while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect + delay(1000); + Console << TinyConsole::white << "."; + i++; + if (i > 20) break; + } + Console << endl << endl; + Console << TinyConsole::green << "Connected to " << ssid << " IP address: " << WiFi.localIP() << endl; + broker.begin(); + Console << "Broker ready (wifi) : " << WiFi.localIP() << " on port " << PORT << endl; + +#endif +} + +void loop() +{ + broker.loop(); + if(millis()-Time>10000) { + Time=millis(); + #ifdef ARDUINO_ARCH_RP2040 + if(rp2040.getFreeHeap()!=freeRam) { + freeRam=rp2040.getFreeHeap(); + #else + if(ESP.getFreeHeap()!=freeRam) { + freeRam=ESP.getFreeHeap(); + #endif + + + Serial.print("RAM:"); + Serial.println(freeRam); + } + } + +} diff --git a/examples/W5500/client-with-W5500-RP2040/readme b/examples/W5500/client-with-W5500-RP2040/readme new file mode 100644 index 0000000..c351fbc --- /dev/null +++ b/examples/W5500/client-with-W5500-RP2040/readme @@ -0,0 +1,5 @@ +In TinyString.h the operator + + TinyString& operator +=(int); + +may need to be added.