diff --git a/ArduinoProps.vcxitems b/ArduinoProps.vcxitems index a4a6dcd..1a7f882 100644 --- a/ArduinoProps.vcxitems +++ b/ArduinoProps.vcxitems @@ -15,7 +15,6 @@ - @@ -26,13 +25,14 @@ + + + + + + - - - - - @@ -53,7 +53,14 @@ - - + + + + + + + + + \ No newline at end of file diff --git a/ArduinoProps.vcxitems.filters b/ArduinoProps.vcxitems.filters index 036b8bd..54a39b3 100644 --- a/ArduinoProps.vcxitems.filters +++ b/ArduinoProps.vcxitems.filters @@ -12,18 +12,17 @@ {a17437ae-fae9-404e-b013-d8b8094f7732} + + {5f7b209e-a331-4095-bf45-013b0c4639aa} + - - - - Examples @@ -39,8 +38,22 @@ - - + + Help + + + Help + + + Help + + + Help + + + Help + + @@ -89,7 +102,32 @@ - - + + Help + + + Help + + + Help + + + Help + + + Help + + + Help + + + Help + + + Help + + + Help + \ No newline at end of file diff --git a/ArduinoProps.zip b/ArduinoProps.zip index f14e4ca..77a15be 100644 Binary files a/ArduinoProps.zip and b/ArduinoProps.zip differ diff --git a/EXAMPLES.md b/EXAMPLES.md index 8dac8b0..6e46b90 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -6,16 +6,20 @@ An adaptation of the internal led Blink example (https://www.arduino.cc/en/tutor 3. **BlinkOnWifiProps**: the Blink example on a Wifi props with *ArduinoProps library* 4. **BlinkOnBridgePubSub**: the Blink example on props using *PubSubClient* directly -MQTT messages are received asynchronously therefore to keep the sketch responsive to MQTT commands, calls to delay() should be avoided (except short ones, say < 100milliseconds). +MQTT messages are received asynchronously therefore to keep the sketch responsive to MQTT commands, calls to delay() should be avoided (except short ones, say < 100 milliseconds). + +With *Props* class, the props code is more readable because all MQTT *PubSubClient* stuff are hidden in *Props* calls, therefore the props code is easier to write and maintain. Asynchronous-like behavior is obtained using *PropsAction*, *TimedAction* or *VariableTimedAction*. -*Copy and change any of these sketches to build your own Arduino connected props, you will only be limited by your imagination.* +***Copy and change any of these sketches to build your own Arduino connected props, you will only be limited by your imagination.*** ## 1. *BlinkOnBridgeProps*: the Blink example on a Yun props with *ArduinoProps library* -With *Props* class, the code is the most readable. All MQTT stuff are hidden in *Props* calls, your processing code is easier to write and maintain. +The library comes with a number of example sketches. See **File > Examples > ArduinoProps** within the Arduino IDE application after installing the *ArduinoProps* library from the `.zip` file. + +![](help/examples-shot.png) ```csharp /* BlinkOnBridgeProps.ino @@ -25,7 +29,7 @@ With *Props* class, the code is the most readable. All MQTT stuff are hidden in simple MQTT props. Avoid delay() calls (except short ones) in loop() to ensure CPU for MQTT protocol. Use PropsAction checks instead. - Copy and change it to build your fist Arduino connected props, you will + Copy and change it to build your first Arduino connected props, you will only be limited by your imagination. Requirements: install ArduinoProps.zip library. @@ -132,15 +136,15 @@ void updateBrokerAdressFromFile(const char* broker_file, BridgeProps* props) ### Memory imprint on Arduino Yun: ```bash -The sketch uses 16720 bytes (58%) of the program storage space. The maximum is 28672 bytes. -Global variables use 1122 bytes (43%) of dynamic memory, which leaves 1438 bytes for local variables. The maximum is 2560 bytes. +The sketch uses 16752 bytes (58%) of the program storage space. The maximum is 28672 bytes. +Global variables use 1120 bytes (43%) of dynamic memory, which leaves 1438 bytes for local variables. The maximum is 2560 bytes. ``` -### Memory imprint on *Dragino Yun + Arduino Mega 2560: +### Memory imprint on Dragino Yun + Arduino Mega 2560: ```bash -The sketch uses 14030 bytes (5%) of the program storage space. The maximum is 258048 bytes. -Global variables use 982 bytes (11%) of dynamic memory, which leaves 7210 bytes for local variables. The maximum is 8192 bytes. +The sketch uses 14060 bytes (5%) of the program storage space. The maximum is 258048 bytes. +Global variables use 980 bytes (11%) of dynamic memory, which leaves 7210 bytes for local variables. The maximum is 8192 bytes. ``` @@ -149,15 +153,23 @@ Global variables use 982 bytes (11%) of dynamic memory, which leaves 7210 bytes Sketch with *EthernetProps* differs slightly from code with *BridgeProps*. -The library comes with a number of example sketches. See **File > Examples > ArduinoProps** within the Arduino IDE application after installing the *ArduinoProps* library from the `.zip` file. +#### Pay atention to the board MAC address: +MAC adresses are hardware identifiers on the network so they must be unique. + +A good practice is to increment only the byte at the very right (`0x03`) when adding a new Arduino Ethernet on your network. + +```csharp +byte mac[] = { 0x46, 0x4F, 0xEA, 0x10, 0x20, 0x03 }; //<<< MAKE SURE IT'S UNIQUE IN YOUR NETWORK!!! and not a reserved MAC + +``` -![](examples-shot.png) ## 3. *BlinkOnWifiProps*: the Blink example on a Wifi props with *ArduinoProps library* Sketch with *WifiProps* differs slightly from code with *BridgeProps*. -Please update the WiFiNINA firmware: [WiFiNINA firmware update](WifiNinaFirmware.md). +#### The board WiFiNINA firmware must be recent (> 1.0): +Uupdating WiFiNINA firmware is easy: [WiFiNINA firmware update](help/WifiNinaFirmware.md). ## 4. *BlinkOnBridgePubSub*: the Blink example on props using *PubSubClient* directly @@ -401,6 +413,7 @@ Global variables use 1013 bytes (39%) of dynamic memory, which leaves 1547 bytes ``` +Only 1 KBytes less than BlinkOnBridgeProps on Arduino Yun, and the sketch is much less readable. ## Author diff --git a/LICENSE.txt b/LICENSE.txt deleted file mode 100644 index 3d905b9..0000000 --- a/LICENSE.txt +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2019 Marie Faure - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/PrésentationEditor.snag b/PrésentationEditor.snag deleted file mode 100644 index d212d92..0000000 Binary files a/PrésentationEditor.snag and /dev/null differ diff --git a/README.md b/README.md index 2affe6d..8bc34b4 100644 --- a/README.md +++ b/README.md @@ -11,35 +11,45 @@ ## 1. Installation and usage + +### Prepare Arduino IDE Download [ArduinoProps.zip](https://github.com/fauresystems/ArduinoProps/raw/master/ArduinoProps.zip) from GitHub and use **Sketch > Include Library > Add .ZIP Library...** -![](install-shot.png) +![](help/install-shot.png) Download library dependencies for Library Manager: * ***PubSubClient*** * ***ListLib*** -![](dependencies-shot.png) +![](help/dependencies-shot.png) +### Start coding your own props +Add `#include "ArduinoProps.h"` on top of your sketch and start coding. -Add `#include "ArduinoProps.h"` on top of your sketch and start coding. Reading [EXAMPLES.md](EXAMPLES.md) will be helpful. +A fork of one the examples is the fastest way to create your own props. -|ArduinoProps library documentation | -|--------------------------------------------------------| -| [This README file](README.md) | -| [Props class reference](Props.md) | -| [PropsData class reference](PropsData.md) | -| [PropsAction class reference](PropsAction.md) | -| [ArduinoProps library examples](EXAMPLES.md) | -| [Arduino Props for Escape Room 2.0](Arduino_Props.md) | -| [WiFiNINA firmware update](WifiNinaFirmware.md) | +### Find help in the documentation + +Reading [EXAMPLES.md](EXAMPLES.md) will be helpful. + +|ArduinoProps library documentation | +|-------------------------------------------------------------| +| [This README file](README.md) | +| [Props class reference](help/Props.md) | +| [PropsData class reference](help/PropsData.md) | +| [PropsAction class reference](help/PropsAction.md) | +| [ArduinoProps library examples](EXAMPLES.md) | +| [Arduino Props for Escape Room 2.0](help/Arduino_Props.md) | +| [WiFiNINA firmware update](help/WifiNinaFirmware.md) | ## 2. Escape room 2.0 props with Arduino The *ArduinoProps library* allows to build *escape room 2.0 props* easily with Arduino and particularly with Arduino Yun or Arduino Mega 2560 + Dragino Yun shield however it works with Ethernet and Wifi shields too. -The *ArduinoProps library* relies on *Nick O'Leary PubSubClient***** library for MQTT. MQTT is a lightweight publish/subscribe messaging protocol designed for M2M (machine to machine) telemetry in low bandwidth environments. +The *ArduinoProps library* relies on *Nick O'Leary PubSubClient***** library for MQTT. MQTT is a lightweight +![](help/install-shot.png) + publish/subscribe messaging protocol designed for M2M (machine to machine) telemetry in low bandwidth environments. ### Props with *Raspberry* Escape room 2.0 props can be powered with Raspberry Pi or any Pythonic nanocomputer using *MqttApp*, our pure Python 3 class based on Eclipse Paho™ MQTT Python Client. @@ -61,7 +71,7 @@ Props receives commands in its inbox MQTT topic. Props can subscribe to any other MQTT topic to receive othe information, for example the escape game scenario (English/French/Kids) or the game clock countdown. -### Escape room structured MQTT topics +#### Escape room structured MQTT topics If you're running our Escape Room control software *Room 2.0* to supervise the escape room in real-time you have to respect its syntax for inbox/outbnox MQTT topics: ```csharp Room/[escape room name]/Props/[propsname]/inbox|outbox @@ -175,7 +185,7 @@ More MQTT topics can be use for anything (room scenario, etc.). - Arduino Ethernet - Arduino Ethernet Shield -For WiFi props, please update the WiFiNINA firmware: [WiFiNINA firmware update](WifiNinaFirmware.md). +For WiFi props, please update the WiFiNINA firmware: [WiFiNINA firmware update](help/WifiNinaFirmware.md). To use other WiFi hardware compatible with any *Nick O'Leary PubSubClient* library you have to fork `WifiProps.h` and `WifiProps.cpp` and to replace `WiFiNINA.h` whih appropriate WiFi library (`ESP8266WiFi.h` for example): diff --git a/examples-shot.png b/examples-shot.png deleted file mode 100644 index 32b48b3..0000000 Binary files a/examples-shot.png and /dev/null differ diff --git a/examples/BlinkOnBridgeProps/BlinkOnBridgeProps.ino b/examples/BlinkOnBridgeProps/BlinkOnBridgeProps.ino index d9fe63b..e11a8fb 100644 --- a/examples/BlinkOnBridgeProps/BlinkOnBridgeProps.ino +++ b/examples/BlinkOnBridgeProps/BlinkOnBridgeProps.ino @@ -5,7 +5,7 @@ simple MQTT props. Avoid delay() calls (except short ones) in loop() to ensure CPU for MQTT protocol. Use PropsAction checks instead. - Copy and change it to build your fist Arduino connected props, you will + Copy and change it to build your first Arduino connected props, you will only be limited by your imagination. Requirements: install ArduinoProps.zip library. diff --git a/examples/BlinkOnEthernetProps/BlinkOnEthernetProps.ino b/examples/BlinkOnEthernetProps/BlinkOnEthernetProps.ino index a1f6fde..f58dff6 100644 --- a/examples/BlinkOnEthernetProps/BlinkOnEthernetProps.ino +++ b/examples/BlinkOnEthernetProps/BlinkOnEthernetProps.ino @@ -5,7 +5,7 @@ simple MQTT props. Avoid delay() calls (except short ones) in loop() to ensure CPU for MQTT protocol. Use PropsAction checks instead. - Copy and change it to build your fist Arduino connected props, you will + Copy and change it to build your first Arduino connected props, you will only be limited by your imagination. Requirements: install ArduinoProps.zip library. @@ -52,7 +52,7 @@ void setup() } delay(1500); // time for shield stuff - + // can do more static IP configuration, must be called after Ethernet.begin() //Ethernet.setSubnetMask(IPAddress(255, 255, 255, 0)); //Ethernet.setGatewayIP(IPAddress(192, 168, 1, 1)); diff --git a/examples/BlinkOnWifiProps/BlinkOnWifiProps.ino b/examples/BlinkOnWifiProps/BlinkOnWifiProps.ino index b60838a..e6179ab 100644 --- a/examples/BlinkOnWifiProps/BlinkOnWifiProps.ino +++ b/examples/BlinkOnWifiProps/BlinkOnWifiProps.ino @@ -5,7 +5,7 @@ simple MQTT props. Avoid delay() calls (except short ones) in loop() to ensure CPU for MQTT protocol. Use PropsAction checks instead. - Copy and change it to build your fist Arduino connected props, you will + Copy and change it to build your first Arduino connected props, you will only be limited by your imagination. Requirements: install ArduinoProps.zip library. @@ -60,20 +60,19 @@ void loop() delay(250); // acceptable freeze for this props (otherwise use PropsAction for async-like behavior) // do static IP configuration disabling the dhcp client, must be called after every WiFi.begin() String fv = WiFi.firmwareVersion(); - if (fv.startsWith("1.0")) { - Serial.println("Please upgrade the firmware for static IP"); - // see https://github.com/fauresystems/ArduinoProps/blob/master/WifiNinaFirmware.md - } - else { - //WiFi.config(IPAddress(192, 168, 1, 21), // local_ip - // IPAddress(192, 168, 1, 1), // dns_server - // IPAddress(192, 168, 1, 1), // gateway - // IPAddress(255, 255, 255, 0)); // subnet - //WiFi.setHostname("wifiprops"); - } + if (fv.startsWith("1.0")) { + Serial.println("Please upgrade the firmware for static IP"); + // see https://github.com/fauresystems/ArduinoProps/blob/master/WifiNinaFirmware.md + } + else { + //WiFi.config(IPAddress(192, 168, 1, 21), // local_ip + // IPAddress(192, 168, 1, 1), // dns_server + // IPAddress(192, 168, 1, 1), // gateway + // IPAddress(255, 255, 255, 0)); // subnet + } if (WiFi.status() == WL_CONNECTED) { - wifiBegun = true; - Serial.println(WiFi.localIP()); + wifiBegun = true; + Serial.println(WiFi.localIP()); Serial.println(WiFi.subnetMask()); Serial.println(WiFi.gatewayIP()); } else { diff --git a/Arduino_Props.md b/help/Arduino_Props.md similarity index 100% rename from Arduino_Props.md rename to help/Arduino_Props.md diff --git a/Props.md b/help/Props.md similarity index 97% rename from Props.md rename to help/Props.md index 77f7cbc..b0c20f6 100644 --- a/Props.md +++ b/help/Props.md @@ -3,7 +3,7 @@ *Props* is a base class for 3 connected props, depending on their network interface: * ***BridgeProps*** for Yun board and Yun shield * ***EthernetProps*** for Ethernet shield -* ***WifiProps*** for Wifi shield +* ***WifiProps*** for WiFiNINA boards *Props* class reference: 1. Define the *Props* @@ -131,7 +131,7 @@ Room 2.0 *outbox* topic: format: Room/[escape room name]/Props/[props name]/outbox example: u8"Room/Demoniak/Props/Arduino Contrôleur/outbox" ``` -See [README.md](README.md): **4. Application protocol for escape room 2.0 props**. +See [README.md](../README.md): **4. Application protocol for escape room 2.0 props**. #### *PropsData* instances *PropsData* provides a facility to monitor data sent into MQTT outbox. @@ -312,7 +312,7 @@ void updateBrokerAdressFromFile(const char* broker_file, BridgeProps* props) ## 6. Examples The library comes with a number of example sketches. See **File > Examples > ArduinoProps** within the Arduino IDE application. -See [EXAMPLES.md](EXAMPLES.md) for an adaptation of the Blink example (https://www.arduino.cc/en/tutorial/blink) as a simple MQTT props: +See [EXAMPLES.md](../EXAMPLES.md) for an adaptation of the Blink example (https://www.arduino.cc/en/tutorial/blink) as a simple MQTT props: 1. **BlinkOnBridgeProps**: the Blink example on a Yun props with *ArduinoProps library* 2. **BlinkOnEthernetProps**: the Blink example on an Ethernet props with *ArduinoProps library* diff --git a/PropsAction.md b/help/PropsAction.md similarity index 100% rename from PropsAction.md rename to help/PropsAction.md diff --git a/PropsData.md b/help/PropsData.md similarity index 99% rename from PropsData.md rename to help/PropsData.md index 0eef3cd..e3e8309 100644 --- a/PropsData.md +++ b/help/PropsData.md @@ -2,7 +2,7 @@ *PropsData* tracks data changes and provides escape room 2.0 propocol `DATA` ready string format. -See **4. Application protocol for escape room 2.0 props** in [README.md](README.md). +See **4. Application protocol for escape room 2.0 props** in [README.md](../README.md). *PropsData* is an interface (base class) implemented by 4 classes: * ***PropsDataDecimal*** diff --git a/WifiNinaFirmware.md b/help/WifiNinaFirmware.md similarity index 100% rename from WifiNinaFirmware.md rename to help/WifiNinaFirmware.md diff --git a/dependencies-shot.png b/help/dependencies-shot.png similarity index 100% rename from dependencies-shot.png rename to help/dependencies-shot.png diff --git a/help/examples-shot.png b/help/examples-shot.png new file mode 100644 index 0000000..0dce180 Binary files /dev/null and b/help/examples-shot.png differ diff --git a/install-shot.png b/help/install-shot.png similarity index 100% rename from install-shot.png rename to help/install-shot.png diff --git a/wifinina-firmware-1.png b/help/wifinina-firmware-1.png similarity index 100% rename from wifinina-firmware-1.png rename to help/wifinina-firmware-1.png diff --git a/wifinina-firmware-2.png b/help/wifinina-firmware-2.png similarity index 100% rename from wifinina-firmware-2.png rename to help/wifinina-firmware-2.png diff --git a/wifinina-firmware-3.png b/help/wifinina-firmware-3.png similarity index 100% rename from wifinina-firmware-3.png rename to help/wifinina-firmware-3.png diff --git a/wifinina-firmware-4.png b/help/wifinina-firmware-4.png similarity index 100% rename from wifinina-firmware-4.png rename to help/wifinina-firmware-4.png diff --git a/wifinina-firmware-5.png b/help/wifinina-firmware-5.png similarity index 100% rename from wifinina-firmware-5.png rename to help/wifinina-firmware-5.png diff --git a/wifinina-firmware-6.png b/help/wifinina-firmware-6.png similarity index 100% rename from wifinina-firmware-6.png rename to help/wifinina-firmware-6.png diff --git a/src/Props.cpp b/src/Props.cpp index 748669b..5b96a10 100644 --- a/src/Props.cpp +++ b/src/Props.cpp @@ -10,6 +10,9 @@ #include "Props.h" #include +#if defined(__AVR__) +#include +#endif void PropsCallback::run(char* topic, byte* payload, unsigned int len) { @@ -57,7 +60,7 @@ Props::Props(const char* client_id, const char* in_box, const char* out_box, con void Props::addData(PropsData* d) { - _dataTable.push_back(d); + _dataTable.Add(d); } void Props::loop() @@ -95,12 +98,22 @@ void Props::checkDataChanges() if (_dataSentCount > (_maximumSilentPeriod * 1000 / _sendDataAction.getInterval())) _dataSentCount = 0; } +void Props::resetMcu() +{ +#if defined(ARDUINO_ARCH_SAMD) + NVIC_SystemReset(); +#elif defined(__AVR__) + wdt_enable(WDTO_15MS); + while (true); +#endif +} + void Props::sendAllData() { String data("DATA "), str; - for (SimpleList::iterator itr = _dataTable.begin(); itr != _dataTable.end(); ++itr) { - str = (*itr)->fetch(); - send(&data, &str); + for (int i = 0; i < _dataTable.Count(); i++) { + str = _dataTable[i]->fetch(); + send(&data, &str); } if (data.length() > 5) { @@ -111,9 +124,9 @@ void Props::sendAllData() void Props::sendDataChanges() { String data("DATA "), str; - for (SimpleList::iterator itr = _dataTable.begin(); itr != _dataTable.end(); ++itr) { - str = (*itr)->fetchChange(); - send(&data, &str); + for (int i = 0; i < _dataTable.Count(); i++) { + str = _dataTable[i]->fetchChange(); + send(&data, &str); } if (data.length() > 5) { diff --git a/src/Props.h b/src/Props.h index 97a4c05..991af08 100644 --- a/src/Props.h +++ b/src/Props.h @@ -18,7 +18,7 @@ #include #include -#include +#include #include "PropsAction.h" #include "PropsData.h" @@ -54,8 +54,9 @@ class Props Props(const char*, const char*, const char*, const char*, const int=1883); virtual void begin(void(*)(String) = NULL) = 0; void addData(PropsData*); - void loop(); + void loop(); void resetIntervals(const int changes, const int silent); + void resetMcu(); void sendAllData(); void sendDataChanges(); void sendData(String); // only in outbox @@ -86,7 +87,7 @@ class Props unsigned long _nextReconAttempt; uint8_t _payloadMax; PropsAction _sendDataAction; - SimpleList _dataTable; + List _dataTable; }; #endif diff --git a/src/WifiProps.cpp b/src/WifiProps.cpp index 6d98452..e37013f 100644 --- a/src/WifiProps.cpp +++ b/src/WifiProps.cpp @@ -5,7 +5,7 @@ Editor: https://github.com/fauresystems License: MIT License (c) Marie Faure - Class Props for Arduino with Wifi shield. + Class Props for Arduino with WiFiNINA. */ #include "WifiProps.h" diff --git a/src/WifiProps.h b/src/WifiProps.h index b0ccb4a..04e5f37 100644 --- a/src/WifiProps.h +++ b/src/WifiProps.h @@ -5,7 +5,7 @@ Editor: https://github.com/fauresystems License: MIT License (c) Marie Faure - Class Props for Arduino with Wifi shield. + Class Props for Arduino with WiFiNINA. */ #ifndef WIFIPROPS_H #define WIFIPROPS_H