Props to prop no plural
This commit is contained in:
+16
-15
@@ -21,10 +21,11 @@
|
|||||||
<None Include="$(MSBuildThisFileDirectory)ArduinoProps.zip" />
|
<None Include="$(MSBuildThisFileDirectory)ArduinoProps.zip" />
|
||||||
<None Include="$(MSBuildThisFileDirectory)create-library-zip.bat" />
|
<None Include="$(MSBuildThisFileDirectory)create-library-zip.bat" />
|
||||||
<None Include="$(MSBuildThisFileDirectory)EXAMPLES.md" />
|
<None Include="$(MSBuildThisFileDirectory)EXAMPLES.md" />
|
||||||
<None Include="$(MSBuildThisFileDirectory)examples\BlinkOnBridgeProps\BlinkOnBridgeProps.ino" />
|
<None Include="$(MSBuildThisFileDirectory)examples\BlinkOnBridgePropInFench\BlinkOnBridgePropInFench.ino" />
|
||||||
|
<None Include="$(MSBuildThisFileDirectory)examples\BlinkOnBridgeProp\BlinkOnBridgeProp.ino" />
|
||||||
<None Include="$(MSBuildThisFileDirectory)examples\BlinkOnBridgePubSub\BlinkOnBridgePubSub.ino" />
|
<None Include="$(MSBuildThisFileDirectory)examples\BlinkOnBridgePubSub\BlinkOnBridgePubSub.ino" />
|
||||||
<None Include="$(MSBuildThisFileDirectory)examples\BlinkOnEthernetProps\BlinkOnEthernetProps.ino" />
|
<None Include="$(MSBuildThisFileDirectory)examples\BlinkOnEthernetProp\BlinkOnEthernetProp.ino" />
|
||||||
<None Include="$(MSBuildThisFileDirectory)examples\BlinkOnWifiProps\BlinkOnWifiProps.ino" />
|
<None Include="$(MSBuildThisFileDirectory)examples\BlinkOnWifiProp\BlinkOnWifiProp.ino" />
|
||||||
<None Include="$(MSBuildThisFileDirectory)help\Arduino_Props.md" />
|
<None Include="$(MSBuildThisFileDirectory)help\Arduino_Props.md" />
|
||||||
<None Include="$(MSBuildThisFileDirectory)help\Props.md" />
|
<None Include="$(MSBuildThisFileDirectory)help\Props.md" />
|
||||||
<None Include="$(MSBuildThisFileDirectory)help\PropsAction.md" />
|
<None Include="$(MSBuildThisFileDirectory)help\PropsAction.md" />
|
||||||
@@ -36,21 +37,21 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\ArduinoProps.cpp" />
|
<ClCompile Include="$(MSBuildThisFileDirectory)src\ArduinoProps.cpp" />
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\BridgeProps.cpp" />
|
<ClCompile Include="$(MSBuildThisFileDirectory)src\BridgeProp.cpp" />
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\EthernetProps.cpp" />
|
<ClCompile Include="$(MSBuildThisFileDirectory)src\EthernetProp.cpp" />
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\Props.cpp" />
|
<ClCompile Include="$(MSBuildThisFileDirectory)src\Prop.cpp" />
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\PropsAction.cpp" />
|
<ClCompile Include="$(MSBuildThisFileDirectory)src\PropAction.cpp" />
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\PropsData.cpp" />
|
<ClCompile Include="$(MSBuildThisFileDirectory)src\PropData.cpp" />
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\WifiProps.cpp" />
|
<ClCompile Include="$(MSBuildThisFileDirectory)src\WifiProp.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\ArduinoProps.h" />
|
<ClInclude Include="$(MSBuildThisFileDirectory)src\ArduinoProps.h" />
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\BridgeProps.h" />
|
<ClInclude Include="$(MSBuildThisFileDirectory)src\BridgeProp.h" />
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\EthernetProps.h" />
|
<ClInclude Include="$(MSBuildThisFileDirectory)src\EthernetProp.h" />
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\Props.h" />
|
<ClInclude Include="$(MSBuildThisFileDirectory)src\Prop.h" />
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\PropsAction.h" />
|
<ClInclude Include="$(MSBuildThisFileDirectory)src\PropAction.h" />
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\PropsData.h" />
|
<ClInclude Include="$(MSBuildThisFileDirectory)src\PropData.h" />
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\WifiProps.h" />
|
<ClInclude Include="$(MSBuildThisFileDirectory)src\WifiProp.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Image Include="$(MSBuildThisFileDirectory)help\dependencies-shot.png" />
|
<Image Include="$(MSBuildThisFileDirectory)help\dependencies-shot.png" />
|
||||||
|
|||||||
@@ -24,18 +24,6 @@
|
|||||||
<None Include="$(MSBuildThisFileDirectory)LICENSE.md" />
|
<None Include="$(MSBuildThisFileDirectory)LICENSE.md" />
|
||||||
<None Include="$(MSBuildThisFileDirectory)README.md" />
|
<None Include="$(MSBuildThisFileDirectory)README.md" />
|
||||||
<None Include="$(MSBuildThisFileDirectory)EXAMPLES.md" />
|
<None Include="$(MSBuildThisFileDirectory)EXAMPLES.md" />
|
||||||
<None Include="$(MSBuildThisFileDirectory)examples\BlinkOnBridgeProps\BlinkOnBridgeProps.ino">
|
|
||||||
<Filter>Examples</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="$(MSBuildThisFileDirectory)examples\BlinkOnBridgePubSub\BlinkOnBridgePubSub.ino">
|
|
||||||
<Filter>Examples</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="$(MSBuildThisFileDirectory)examples\BlinkOnEthernetProps\BlinkOnEthernetProps.ino">
|
|
||||||
<Filter>Examples</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="$(MSBuildThisFileDirectory)examples\BlinkOnWifiProps\BlinkOnWifiProps.ino">
|
|
||||||
<Filter>Examples</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="$(MSBuildThisFileDirectory)ArduinoProps.zip" />
|
<None Include="$(MSBuildThisFileDirectory)ArduinoProps.zip" />
|
||||||
<None Include="$(MSBuildThisFileDirectory)create-library-zip.bat" />
|
<None Include="$(MSBuildThisFileDirectory)create-library-zip.bat" />
|
||||||
<None Include="$(MSBuildThisFileDirectory)help\Arduino_Props.md">
|
<None Include="$(MSBuildThisFileDirectory)help\Arduino_Props.md">
|
||||||
@@ -54,27 +42,42 @@
|
|||||||
<Filter>Help</Filter>
|
<Filter>Help</Filter>
|
||||||
</None>
|
</None>
|
||||||
<None Include="$(MSBuildThisFileDirectory)LICENSE" />
|
<None Include="$(MSBuildThisFileDirectory)LICENSE" />
|
||||||
|
<None Include="$(MSBuildThisFileDirectory)examples\BlinkOnBridgeProp\BlinkOnBridgeProp.ino">
|
||||||
|
<Filter>Examples</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="$(MSBuildThisFileDirectory)examples\BlinkOnBridgePropInFench\BlinkOnBridgePropInFench.ino">
|
||||||
|
<Filter>Examples</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="$(MSBuildThisFileDirectory)examples\BlinkOnBridgePubSub\BlinkOnBridgePubSub.ino">
|
||||||
|
<Filter>Examples</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="$(MSBuildThisFileDirectory)examples\BlinkOnEthernetProp\BlinkOnEthernetProp.ino">
|
||||||
|
<Filter>Examples</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="$(MSBuildThisFileDirectory)examples\BlinkOnWifiProp\BlinkOnWifiProp.ino">
|
||||||
|
<Filter>Examples</Filter>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\ArduinoProps.cpp">
|
<ClCompile Include="$(MSBuildThisFileDirectory)src\ArduinoProps.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\BridgeProps.cpp">
|
<ClCompile Include="D:\GitHub\fauresystems\ArduinoProps\src\BridgeProp.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\EthernetProps.cpp">
|
<ClCompile Include="D:\GitHub\fauresystems\ArduinoProps\src\EthernetProp.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\Props.cpp">
|
<ClCompile Include="D:\GitHub\fauresystems\ArduinoProps\src\Prop.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\PropsAction.cpp">
|
<ClCompile Include="D:\GitHub\fauresystems\ArduinoProps\src\PropAction.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\PropsData.cpp">
|
<ClCompile Include="D:\GitHub\fauresystems\ArduinoProps\src\PropData.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\WifiProps.cpp">
|
<ClCompile Include="D:\GitHub\fauresystems\ArduinoProps\src\WifiProp.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@@ -82,22 +85,22 @@
|
|||||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\ArduinoProps.h">
|
<ClInclude Include="$(MSBuildThisFileDirectory)src\ArduinoProps.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\BridgeProps.h">
|
<ClInclude Include="D:\GitHub\fauresystems\ArduinoProps\src\BridgeProp.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\EthernetProps.h">
|
<ClInclude Include="D:\GitHub\fauresystems\ArduinoProps\src\EthernetProp.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\Props.h">
|
<ClInclude Include="D:\GitHub\fauresystems\ArduinoProps\src\Prop.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\PropsAction.h">
|
<ClInclude Include="D:\GitHub\fauresystems\ArduinoProps\src\PropAction.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\PropsData.h">
|
<ClInclude Include="D:\GitHub\fauresystems\ArduinoProps\src\PropData.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\WifiProps.h">
|
<ClInclude Include="D:\GitHub\fauresystems\ArduinoProps\src\WifiProp.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
Binary file not shown.
+56
-56
@@ -1,35 +1,35 @@
|
|||||||
# ArduinoProps library examples
|
# ArduinoProps library examples
|
||||||
An adaptation of the internal led Blink example (https://www.arduino.cc/en/tutorial/blink) as a simple MQTT props.
|
An adaptation of the internal led Blink example (https://www.arduino.cc/en/tutorial/blink) as a simple MQTT prop.
|
||||||
|
|
||||||
1. **BlinkOnBridgeProps**: the Blink example on a Yun props with *ArduinoProps library*
|
1. **BlinkOnBridgeProp**: the Blink example on a Yun prop with *ArduinoProps library*
|
||||||
2. **BlinkOnEthernetProps**: the Blink example on an Ethernet props with *ArduinoProps library*
|
2. **BlinkOnEthernetProp**: the Blink example on an Ethernet prop with *ArduinoProps library*
|
||||||
3. **BlinkOnWifiProps**: the Blink example on a Wifi props with *ArduinoProps library*
|
3. **BlinkOnWifiProp**: the Blink example on a Wifi prop with *ArduinoProps library*
|
||||||
4. **BlinkOnBridgePubSub**: the Blink example on props using *PubSubClient* directly
|
4. **BlinkOnBridgePubSub**: the Blink example on prop 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 < 100 milliseconds).
|
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.
|
With *Prop* class, the prop code is more readable because all MQTT *PubSubClient* stuff are hidden in *Prop* calls, therefore the prop code is easier to write and maintain.
|
||||||
|
|
||||||
Asynchronous-like behavior is obtained using *PropsAction*, *TimedAction* or *VariableTimedAction*.
|
Asynchronous-like behavior is obtained using *PropAction*, *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 prop, you will only be limited by your imagination.***
|
||||||
|
|
||||||
|
|
||||||
## 1. *BlinkOnBridgeProps*: the Blink example on a Yun props with *ArduinoProps library*
|
## 1. *BlinkOnBridgeProp*: the Blink example on a Yun prop with *ArduinoProps library*
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
/* BlinkOnBridgeProps.ino
|
/* BlinkOnBridgeProp.ino
|
||||||
MIT License (c) Marie Faure <dev at faure dot systems>
|
MIT License (c) Marie Faure <dev at faure dot systems>
|
||||||
|
|
||||||
Adapt the Blink example (https://www.arduino.cc/en/tutorial/blink) as a
|
Adapt the Blink example (https://www.arduino.cc/en/tutorial/blink) as a
|
||||||
simple MQTT props. Avoid delay() calls (except short ones) in loop() to
|
simple MQTT prop. Avoid delay() calls (except short ones) in loop() to
|
||||||
ensure CPU for MQTT protocol. Use PropsAction checks instead.
|
ensure CPU for MQTT protocol. Use PropAction checks instead.
|
||||||
|
|
||||||
Copy and change it to build your first Arduino connected props, you will
|
Copy and change it to build your first Arduino connected prop, you will
|
||||||
only be limited by your imagination.
|
only be limited by your imagination.
|
||||||
|
|
||||||
Requirements: install ArduinoProps.zip library.
|
Requirements: install ArduinoProps.zip library.
|
||||||
@@ -38,30 +38,30 @@ The library comes with a number of example sketches. See **File > Examples > Ard
|
|||||||
#include "ArduinoProps.h"
|
#include "ArduinoProps.h"
|
||||||
|
|
||||||
// If you're running our Escape Room control software (Room 2.0) you have to respect
|
// If you're running our Escape Room control software (Room 2.0) you have to respect
|
||||||
// prpos inbox/outbox syntax Room/[escape room name]/Props/[propsname]/inbox|outbox
|
// prpos inbox/outbox syntax Room/[escape room name]/Props/[prop name]/inbox|outbox
|
||||||
// https://live-escape.net/go/room
|
// https://live-escape.net/go/room
|
||||||
|
|
||||||
BridgeProps props(u8"Arduino Contrôleur", // as MQTT client id, should be unique per client for given broker
|
BridgeProp prop(u8"Arduino Contrôleur", // as MQTT client id, should be unique per client for given broker
|
||||||
u8"Room/Demoniak/Props/Arduino Contrôleur/inbox",
|
u8"Room/Demoniak/Props/Arduino Contrôleur/inbox",
|
||||||
u8"Room/Demoniak/Props/Arduino Contrôleur/outbox",
|
u8"Room/Demoniak/Props/Arduino Contrôleur/outbox",
|
||||||
"192.168.1.42", // your MQTT server IP address
|
"192.168.1.42", // your MQTT server IP address
|
||||||
1883); // your MQTT server port;
|
1883); // your MQTT server port;
|
||||||
|
|
||||||
PropsDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
PropDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
||||||
PropsDataLogical led(u8"led");
|
PropDataLogical led(u8"led");
|
||||||
|
|
||||||
void clignote(); // forward
|
void clignote(); // forward
|
||||||
PropsAction clignoteAction = PropsAction(1000, clignote);
|
PropAction clignoteAction = PropAction(1000, clignote);
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Bridge.begin();
|
Bridge.begin();
|
||||||
//updateBrokerAdressFromFile("/root/broker", &props); // if you're running our Escape Room control software (Room 2.0)
|
//updateBrokerAdressFromFile("/root/broker", &prop); // if you're running our Escape Room control software (Room 2.0)
|
||||||
|
|
||||||
props.addData(&clignoter);
|
prop.addData(&clignoter);
|
||||||
props.addData(&led);
|
prop.addData(&led);
|
||||||
|
|
||||||
props.begin(InboxMessage::run);
|
prop.begin(InboxMessage::run);
|
||||||
|
|
||||||
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output
|
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ void setup()
|
|||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
props.loop();
|
prop.loop();
|
||||||
|
|
||||||
led.setValue(digitalRead(LED_BUILTIN)); // read I/O
|
led.setValue(digitalRead(LED_BUILTIN)); // read I/O
|
||||||
|
|
||||||
@@ -89,31 +89,31 @@ void InboxMessage::run(String a) {
|
|||||||
|
|
||||||
if (a == u8"app:startup")
|
if (a == u8"app:startup")
|
||||||
{
|
{
|
||||||
props.sendAllData();
|
prop.sendAllData();
|
||||||
props.sendDone(a);
|
prop.sendDone(a);
|
||||||
}
|
}
|
||||||
else if (a == "clignoter:1")
|
else if (a == "clignoter:1")
|
||||||
{
|
{
|
||||||
clignoter.setValue(true);
|
clignoter.setValue(true);
|
||||||
|
|
||||||
props.sendAllData(); // all data change, we don't have to be selctive then
|
prop.sendAllData(); // all data change, we don't have to be selctive then
|
||||||
props.sendDone(a); // acknowledge props command action
|
prop.sendDone(a); // acknowledge prop command action
|
||||||
}
|
}
|
||||||
else if (a == "clignoter:0")
|
else if (a == "clignoter:0")
|
||||||
{
|
{
|
||||||
clignoter.setValue(false);
|
clignoter.setValue(false);
|
||||||
|
|
||||||
props.sendAllData(); // all data change, we don't have to be selctive then
|
prop.sendAllData(); // all data change, we don't have to be selctive then
|
||||||
props.sendDone(a); // acknowledge props command action
|
prop.sendDone(a); // acknowledge prop command action
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// acknowledge omition of the props command
|
// acknowledge omition of the prop command
|
||||||
props.sendOmit(a);
|
prop.sendOmit(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateBrokerAdressFromFile(const char* broker_file, BridgeProps* props)
|
void updateBrokerAdressFromFile(const char* broker_file, BridgeProp* prop)
|
||||||
{
|
{
|
||||||
// broker IP address is stored in Linino file systems and updated with ssh command by Room 2.0
|
// broker IP address is stored in Linino file systems and updated with ssh command by Room 2.0
|
||||||
IPAddress ip;
|
IPAddress ip;
|
||||||
@@ -129,7 +129,7 @@ void updateBrokerAdressFromFile(const char* broker_file, BridgeProps* props)
|
|||||||
}
|
}
|
||||||
b.trim();
|
b.trim();
|
||||||
|
|
||||||
if (ip.fromString(b.c_str())) props->setBrokerIpAddress(ip);
|
if (ip.fromString(b.c_str())) prop->setBrokerIpAddress(ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -149,9 +149,9 @@ Global variables use 980 bytes (11%) of dynamic memory, which leaves 7210 bytes
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## 2. *BlinkOnEthernetProps*: the Blink example on an Ethernet props with *ArduinoProps library*
|
## 2. *BlinkOnEthernetProp*: the Blink example on an Ethernet prop with *ArduinoProps library*
|
||||||
|
|
||||||
Sketch with *EthernetProps* differs slightly from code with *BridgeProps*.
|
Sketch with *EthernetProp* differs slightly from code with *BridgeProp*.
|
||||||
|
|
||||||
#### Pay atention to the board MAC address:
|
#### Pay atention to the board MAC address:
|
||||||
MAC adresses are hardware identifiers on the network so they must be unique.
|
MAC adresses are hardware identifiers on the network so they must be unique.
|
||||||
@@ -164,9 +164,9 @@ byte mac[] = { 0x46, 0x4F, 0xEA, 0x10, 0x20, 0x03 }; //<<< MAKE SURE IT'S UNIQUE
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## 3. *BlinkOnWifiProps*: the Blink example on a Wifi props with *ArduinoProps library*
|
## 3. *BlinkOnWifiProp*: the Blink example on a Wifi prop with *ArduinoProps library*
|
||||||
|
|
||||||
Sketch with *WifiProps* differs slightly from code with *BridgeProps*.
|
Sketch with *WifiProp* differs slightly from code with *BridgeProp*.
|
||||||
|
|
||||||
#### The board WiFiNINA firmware must be recent (> 1.0):
|
#### The board WiFiNINA firmware must be recent (> 1.0):
|
||||||
Uupdating WiFiNINA firmware is easy: [WiFiNINA firmware update](help/WifiNinaFirmware.md).
|
Uupdating WiFiNINA firmware is easy: [WiFiNINA firmware update](help/WifiNinaFirmware.md).
|
||||||
@@ -180,7 +180,7 @@ void loop()
|
|||||||
if (!wifiBegun) {
|
if (!wifiBegun) {
|
||||||
WiFi.begin(ssid, passphrase);
|
WiFi.begin(ssid, passphrase);
|
||||||
Serial.println(WiFi.firmwareVersion());
|
Serial.println(WiFi.firmwareVersion());
|
||||||
delay(250); // acceptable freeze for this props (otherwise use PropsAction for async-like behavior)
|
delay(250); // acceptable freeze for this prop (otherwise use PropAction for async-like behavior)
|
||||||
// do static IP configuration disabling the dhcp client, must be called after every WiFi.begin()
|
// do static IP configuration disabling the dhcp client, must be called after every WiFi.begin()
|
||||||
String fv = WiFi.firmwareVersion();
|
String fv = WiFi.firmwareVersion();
|
||||||
if (fv.startsWith("1.0")) {
|
if (fv.startsWith("1.0")) {
|
||||||
@@ -206,7 +206,7 @@ void loop()
|
|||||||
wifiBegun = false;
|
wifiBegun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
props.loop();
|
prop.loop();
|
||||||
|
|
||||||
led.setValue(digitalRead(LED_BUILTIN)); // read I/O
|
led.setValue(digitalRead(LED_BUILTIN)); // read I/O
|
||||||
|
|
||||||
@@ -215,7 +215,7 @@ void loop()
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## 4. *BlinkOnBridgePubSub*: the Blink example on props using *PubSubClient* directly
|
## 4. *BlinkOnBridgePubSub*: the Blink example on prop using *PubSubClient* directly
|
||||||
|
|
||||||
Using *PubSubClient* directly does not save much memory and makes the sketch code less readable, the processing code will be a bit lost in the MQTT code
|
Using *PubSubClient* directly does not save much memory and makes the sketch code less readable, the processing code will be a bit lost in the MQTT code
|
||||||
|
|
||||||
@@ -230,7 +230,7 @@ However, this can help in special cases.
|
|||||||
License: MIT License (c) Marie Faure <dev at faure dot systems>
|
License: MIT License (c) Marie Faure <dev at faure dot systems>
|
||||||
|
|
||||||
Adapt the Blink example (https://www.arduino.cc/en/tutorial/blink) as a
|
Adapt the Blink example (https://www.arduino.cc/en/tutorial/blink) as a
|
||||||
simple MQTT props with PubSubClient.
|
simple MQTT prop with PubSubClient.
|
||||||
*/
|
*/
|
||||||
#include <Bridge.h>
|
#include <Bridge.h>
|
||||||
#include <BridgeClient.h>
|
#include <BridgeClient.h>
|
||||||
@@ -239,13 +239,13 @@ However, this can help in special cases.
|
|||||||
#include <VariableTimedAction.h>
|
#include <VariableTimedAction.h>
|
||||||
|
|
||||||
#define BROKER "192.168.1.42" // your MQTT server IP address
|
#define BROKER "192.168.1.42" // your MQTT server IP address
|
||||||
#define PROPS_NAME u8"Arduino Contrôleur" // as MQTT client id, should be unique per client for given broker
|
#define PROP_NAME u8"Arduino Contrôleur" // as MQTT client id, should be unique per client for given broker
|
||||||
|
|
||||||
// If you're running our Escape Room control software (Room 2.0) you have to respect
|
// If you're running our Escape Room control software (Room 2.0) you have to respect
|
||||||
// props inbox/outbox syntax Room/[escape room name]/Props/[propsname]/inbox|outbox
|
// prop inbox/outbox syntax Room/[escape room name]/Props/[prop name]/inbox|outbox
|
||||||
// https://github.com/fauresystems/escape-room#room-control-software
|
// https://github.com/fauresystems/escape-room#room-control-software
|
||||||
#define PROPS_INBOX u8"Room/Demoniak/Props/Arduino Contrôleur/inbox"
|
#define PROP_INBOX u8"Room/Demoniak/Props/Arduino Contrôleur/inbox"
|
||||||
#define PROPS_OUTBOX u8"Room/Demoniak/Props/Arduino Contrôleur/outbox"
|
#define PROP_OUTBOX u8"Room/Demoniak/Props/Arduino Contrôleur/outbox"
|
||||||
|
|
||||||
// Yun can store broker IP address in Linino file systems, and updatred with ssh command
|
// Yun can store broker IP address in Linino file systems, and updatred with ssh command
|
||||||
#define YUN_BROKER_FILE "/root/broker"
|
#define YUN_BROKER_FILE "/root/broker"
|
||||||
@@ -346,10 +346,10 @@ void loop()
|
|||||||
{
|
{
|
||||||
lastReconnection += 5000L;
|
lastReconnection += 5000L;
|
||||||
|
|
||||||
if (_client.connect(PROPS_NAME, PROPS_OUTBOX, 2, true, "DISCONNECTED"))
|
if (_client.connect(PROP_NAME, PROP_OUTBOX, 2, true, "DISCONNECTED"))
|
||||||
{
|
{
|
||||||
_client.publish(PROPS_OUTBOX, "CONNECTED", true);
|
_client.publish(PROP_OUTBOX, "CONNECTED", true);
|
||||||
_client.subscribe(PROPS_INBOX, 1); // max QoS is 1 for PubSubClient subsciption
|
_client.subscribe(PROP_INBOX, 1); // max QoS is 1 for PubSubClient subsciption
|
||||||
lastReconnection = 0L;
|
lastReconnection = 0L;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -371,7 +371,7 @@ void publishAll()
|
|||||||
buf += u8" clignote=" + (blinking.blink ? String("oui") : String("non"));
|
buf += u8" clignote=" + (blinking.blink ? String("oui") : String("non"));
|
||||||
blink_ref = blinking.blink;
|
blink_ref = blinking.blink;
|
||||||
|
|
||||||
_client.publish(PROPS_OUTBOX, buf.c_str());
|
_client.publish(PROP_OUTBOX, buf.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void publishChanges()
|
void publishChanges()
|
||||||
@@ -393,13 +393,13 @@ void publishChanges()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (buf.length() > 4)
|
if (buf.length() > 4)
|
||||||
_client.publish(PROPS_OUTBOX, buf.c_str());
|
_client.publish(PROP_OUTBOX, buf.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void publishDone(String a)
|
void publishDone(String a)
|
||||||
{
|
{
|
||||||
a = "DONE " + a;
|
a = "DONE " + a;
|
||||||
_client.publish(PROPS_OUTBOX, a.c_str());
|
_client.publish(PROP_OUTBOX, a.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void onInboxMessage(String a) {
|
void onInboxMessage(String a) {
|
||||||
@@ -415,7 +415,7 @@ void onInboxMessage(String a) {
|
|||||||
blinking.blink = true;
|
blinking.blink = true;
|
||||||
|
|
||||||
publishAll(); // all data change, we don't have to be selctive then
|
publishAll(); // all data change, we don't have to be selctive then
|
||||||
publishDone(a); // acknowledge props command action
|
publishDone(a); // acknowledge prop command action
|
||||||
}
|
}
|
||||||
else if (a == "clignoter:0")
|
else if (a == "clignoter:0")
|
||||||
{
|
{
|
||||||
@@ -423,12 +423,12 @@ void onInboxMessage(String a) {
|
|||||||
blinking.blink = false;
|
blinking.blink = false;
|
||||||
|
|
||||||
publishAll(); // all data change, we don't have to be selctive then
|
publishAll(); // all data change, we don't have to be selctive then
|
||||||
publishDone(a); // acknowledge props command action
|
publishDone(a); // acknowledge prop command action
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// acknowledge omition of the props command
|
// acknowledge omition of the prop command
|
||||||
_client.publish(PROPS_OUTBOX, String("OMIT " + a).c_str());
|
_client.publish(PROP_OUTBOX, String("OMIT " + a).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -440,7 +440,7 @@ void callback(char* topic, byte* payload, unsigned int len)
|
|||||||
memcpy(p, payload, len);
|
memcpy(p, payload, len);
|
||||||
p[len] = '\0';
|
p[len] = '\0';
|
||||||
if (String(p) == "@PING")
|
if (String(p) == "@PING")
|
||||||
_client.publish(PROPS_OUTBOX, "PONG");
|
_client.publish(PROP_OUTBOX, "PONG");
|
||||||
else
|
else
|
||||||
onInboxMessage(p);
|
onInboxMessage(p);
|
||||||
free(p);
|
free(p);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
# ArduinoProps library
|
# ArduinoProps library
|
||||||
1. Installation and usage
|
1. Installation and usage
|
||||||
2. Escape room 2.0 props with Arduino
|
2. Escape room 2.0 prop with Arduino
|
||||||
3. *ArduinoProps library* value for escape room 2.0
|
3. *ArduinoProps library* value for escape room 2.0
|
||||||
4. Application protocol for escape room 2.0 props
|
4. Application protocol for escape room 2.0 prop
|
||||||
5. Compatible hardware
|
5. Compatible hardware
|
||||||
6. Advantages of Arduino Yun and Dragino Yun shield
|
6. Advantages of Arduino Yun and Dragino Yun shield
|
||||||
7. Advantages of the *ArduinoProps library*
|
7. Advantages of the *ArduinoProps library*
|
||||||
@@ -23,10 +23,10 @@ Download library dependencies for Library Manager:
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
### Start coding your own props
|
### Start coding your own prop
|
||||||
Add `#include "ArduinoProps.h"` on top of your sketch and start coding.
|
Add `#include "ArduinoProps.h"` on top of your sketch and start coding.
|
||||||
|
|
||||||
A fork of one the examples is the fastest way to create your own props.
|
A fork of one the examples is the fastest way to create your own prop.
|
||||||
|
|
||||||
### Find help in the documentation
|
### Find help in the documentation
|
||||||
|
|
||||||
@@ -35,34 +35,34 @@ Reading [EXAMPLES.md](EXAMPLES.md) will be helpful.
|
|||||||
|ArduinoProps library documentation |
|
|ArduinoProps library documentation |
|
||||||
|-------------------------------------------------------------|
|
|-------------------------------------------------------------|
|
||||||
| [This README file](README.md) |
|
| [This README file](README.md) |
|
||||||
| [Props class reference](help/Props.md) |
|
| [Props class reference](help/Prop.md) |
|
||||||
| [PropsData class reference](help/PropsData.md) |
|
| [PropData class reference](help/PropData.md) |
|
||||||
| [PropsAction class reference](help/PropsAction.md) |
|
| [PropAction class reference](help/PropAction.md) |
|
||||||
| [ArduinoProps library examples](EXAMPLES.md) |
|
| [ArduinoProps library examples](EXAMPLES.md) |
|
||||||
| [Arduino Props for Escape Room 2.0](help/Arduino_Props.md) |
|
| [Arduino Props for Escape Room 2.0](help/Arduino_Props.md) |
|
||||||
| [WiFiNINA firmware update](help/WifiNinaFirmware.md) |
|
| [WiFiNINA firmware update](help/WifiNinaFirmware.md) |
|
||||||
|
|
||||||
|
|
||||||
## 2. Escape room 2.0 props with Arduino
|
## 2. Escape room 2.0 prop 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* allows to build *escape room 2.0 prop* 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 *<a href="https://github.com/knolleary/pubsubclient" target="_blank">Nick O'Leary PubSubClient</a>* library for MQTT. MQTT is a lightweight
|
The *ArduinoProps library* relies on *<a href="https://github.com/knolleary/pubsubclient" target="_blank">Nick O'Leary PubSubClient</a>* library for MQTT. MQTT is a lightweight
|
||||||

|

|
||||||
publish/subscribe messaging protocol designed for M2M (machine to machine) telemetry in low bandwidth environments.
|
publish/subscribe messaging protocol designed for M2M (machine to machine) telemetry in low bandwidth environments.
|
||||||
|
|
||||||
### Props with *Raspberry*
|
### 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 <a href="https://github.com/eclipse/paho.mqtt.python" target="_blank">Eclipse Paho™ MQTT Python Client</a>.
|
Escape room 2.0 prop can be powered with Raspberry Pi or any Pythonic nanocomputer using *MqttApp*, our pure Python 3 class based on <a href="https://github.com/eclipse/paho.mqtt.python" target="_blank">Eclipse Paho™ MQTT Python Client</a>.
|
||||||
|
|
||||||
You will find Raspberry Pi libraries for escape room 2.0 props at [https://github.com/fauresystems](https://github.com/fauresystems), to build props with RPi.GPIO, Pi Hats, Guizero, Pygames, PyQt5 or Kivi.
|
You will find Raspberry Pi libraries for escape room 2.0 prop at [https://github.com/fauresystems](https://github.com/fauresystems), to build prop with RPi.GPIO, Pi Hats, Guizero, Pygames, PyQt5 or Kivi.
|
||||||
|
|
||||||
|
|
||||||
## 3. *ArduinoProps library* value for escape room 2.0
|
## 3. *ArduinoProps library* value for escape room 2.0
|
||||||
*Nick O'Leary PubSubClient* library is sufficient to write escape room 2.0 props Arduino code.
|
*Nick O'Leary PubSubClient* library is sufficient to write escape room 2.0 prop Arduino code.
|
||||||
|
|
||||||
The *ArduinoProps library* relies on *Nick O'Leary PubSubClient* for MQTT messaging and provides a framework and protocol for helping and accelerating the coding of Arduino props. If you will help build simple and complex props with reliable code.
|
The *ArduinoProps library* relies on *Nick O'Leary PubSubClient* for MQTT messaging and provides a framework and protocol for helping and accelerating the coding of Arduino prop. If you will help build simple and complex prop with reliable code.
|
||||||
|
|
||||||
Since 2016, *ArduinoProps library* is used extensively in many escape rooms with up to 20 props per room (which is no limit at all), with a high level of availability and sustainability.
|
Since 2016, *ArduinoProps library* is used extensively in many escape rooms with up to 20 prop per room (which is no limit at all), with a high level of availability and sustainability.
|
||||||
|
|
||||||
### Inbox/oubox messaging
|
### Inbox/oubox messaging
|
||||||
Instead of usual MQTT topic structure which sends every data value in a different topic for every variable, *ArduinoProps library* sends data via a unique outbox topic.
|
Instead of usual MQTT topic structure which sends every data value in a different topic for every variable, *ArduinoProps library* sends data via a unique outbox topic.
|
||||||
@@ -83,9 +83,9 @@ example:
|
|||||||
MQTT supports UTF-8 encoding.
|
MQTT supports UTF-8 encoding.
|
||||||
|
|
||||||
### Sending messages only when appropriate
|
### Sending messages only when appropriate
|
||||||
Usually Arduino IoT sketches send MQTT data for every variable at every loop. When the loop is fast, you can get tons of useless messages, and usually a sleeping delay is added at every loop to slow down the message flow ; this can slow down significantly the props response time to human supervision and automation commands.
|
Usually Arduino IoT sketches send MQTT data for every variable at every loop. When the loop is fast, you can get tons of useless messages, and usually a sleeping delay is added at every loop to slow down the message flow ; this can slow down significantly the prop response time to human supervision and automation commands.
|
||||||
|
|
||||||
While Arduino sketch is sending a message it isn't doing props sensor/actuator processing, and it takes about 20 to 40 milliseconds to send a message. With too many messsages it's too much processing time wasted.
|
While Arduino sketch is sending a message it isn't doing prop sensor/actuator processing, and it takes about 20 to 40 milliseconds to send a message. With too many messsages it's too much processing time wasted.
|
||||||
|
|
||||||
*ArduinoProps library* sends all data periodically every 30 seconds (default parameter) and sends data changes over a period of time you choose (typical 400 milliseconds for real-time behavior, but you may choose every 100 milliseconds, 1 or 3 seconds: your choice for your application).
|
*ArduinoProps library* sends all data periodically every 30 seconds (default parameter) and sends data changes over a period of time you choose (typical 400 milliseconds for real-time behavior, but you may choose every 100 milliseconds, 1 or 3 seconds: your choice for your application).
|
||||||
|
|
||||||
@@ -103,14 +103,14 @@ And on Yun this same code line can switch MQTT server IP address (can be helpful
|
|||||||
### Simple human-readable text protocol
|
### Simple human-readable text protocol
|
||||||
An escape room 2.0 is typically centrally controlled from a Windows PC which provides the Game Master with monitoring and control information as well as some automation.
|
An escape room 2.0 is typically centrally controlled from a Windows PC which provides the Game Master with monitoring and control information as well as some automation.
|
||||||
|
|
||||||
To unifiy escape room 2.0 development, *ArduinoProps library* provides a simple [protocol](https://github.com/xcape-io/PyProps/blob/master/PROTOCOL.md) between props and room controller at application level:
|
To unifiy escape room 2.0 development, *ArduinoProps library* provides a simple [protocol](https://github.com/xcape-io/PyProps/blob/master/PROTOCOL.md) between prop and room controller at application level:
|
||||||
```csharp
|
```csharp
|
||||||
DATA -> send variables to control
|
DATA -> send variables to control
|
||||||
MESG -> send text to display in control
|
MESG -> send text to display in control
|
||||||
DONE -> acknowledge that a command has been performed
|
DONE -> acknowledge that a command has been performed
|
||||||
OMIT -> acknowledge that a command has been ignored
|
OMIT -> acknowledge that a command has been ignored
|
||||||
OVER -> notify that a challenge is over
|
OVER -> notify that a challenge is over
|
||||||
REQU -> request a command to another props
|
REQU -> request a command to another prop
|
||||||
PROG -> request a control program
|
PROG -> request a control program
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -127,9 +127,9 @@ DATA messages when many I/O like on Arduino Mega 2560 and MESG information messa
|
|||||||
|
|
||||||
*ArduinoProps library* seamlessly splits long messages smartly when required.
|
*ArduinoProps library* seamlessly splits long messages smartly when required.
|
||||||
|
|
||||||
## 4. Application protocol for escape room 2.0 props
|
## 4. Application protocol for escape room 2.0 prop
|
||||||
|
|
||||||
A *level 7* [protocol](https://github.com/xcape-io/PyProps/blob/master/PROTOCOL.md) (*application level*) is necessary for connected props to report data and to be controlled for the escape room automation and game play.
|
A *level 7* [protocol](https://github.com/xcape-io/PyProps/blob/master/PROTOCOL.md) (*application level*) is necessary for connected prop to report data and to be controlled for the escape room automation and game play.
|
||||||
|
|
||||||
We have defined a simple human-readable text protocol. Messages are encoded in UTF-8, in Arduino sketches use:
|
We have defined a simple human-readable text protocol. Messages are encoded in UTF-8, in Arduino sketches use:
|
||||||
```csharp
|
```csharp
|
||||||
@@ -148,7 +148,7 @@ Props connection state is handled in the outbox topic:
|
|||||||
|
|
||||||
More MQTT topics can be use for anything (room scenario, etc.).
|
More MQTT topics can be use for anything (room scenario, etc.).
|
||||||
|
|
||||||
#### Messages sent from the Arduino props are formatted
|
#### Messages sent from the Arduino prop are formatted
|
||||||
```csharp
|
```csharp
|
||||||
DATA sensor=24.26 light=on challenge=pinball
|
DATA sensor=24.26 light=on challenge=pinball
|
||||||
MESG Warning: sensor not detected
|
MESG Warning: sensor not detected
|
||||||
@@ -159,7 +159,7 @@ More MQTT topics can be use for anything (room scenario, etc.).
|
|||||||
PROG audio-final:start
|
PROG audio-final:start
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Message received by the Arduino props have no particular format
|
#### Message received by the Arduino prop have no particular format
|
||||||
```csharp
|
```csharp
|
||||||
power:1 for example to power on the room
|
power:1 for example to power on the room
|
||||||
porte-salon:ouvrir for example to open a door
|
porte-salon:ouvrir for example to open a door
|
||||||
@@ -169,7 +169,7 @@ More MQTT topics can be use for anything (room scenario, etc.).
|
|||||||
|
|
||||||
#### @PING-PONG special messages
|
#### @PING-PONG special messages
|
||||||
```csharp
|
```csharp
|
||||||
@PING is received in inbox then the props sends just PONG in outbox
|
@PING is received in inbox then the prop sends just PONG in outbox
|
||||||
-> so the escape room controller can monitor response time at application level
|
-> so the escape room controller can monitor response time at application level
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -184,10 +184,10 @@ More MQTT topics can be use for anything (room scenario, etc.).
|
|||||||
- Arduino MKR VIDOR 4000
|
- Arduino MKR VIDOR 4000
|
||||||
- Any Arduino + Ethernet Shield
|
- Any Arduino + Ethernet Shield
|
||||||
|
|
||||||
For WiFi props, please update the WiFiNINA firmware: [WiFiNINA firmware update](help/WifiNinaFirmware.md).
|
For WiFi prop, please update the WiFiNINA firmware: [WiFiNINA firmware update](help/WifiNinaFirmware.md).
|
||||||
|
|
||||||
|
|
||||||
To use other WiFi hardware compatible with any *<a href="https://github.com/knolleary/pubsubclient" target="_blank">Nick O'Leary PubSubClient</a>* library you have to fork `WifiProps.h` and `WifiProps.cpp` and to replace `WiFiNINA.h` with appropriate WiFi library (`ESP8266WiFi.h` for example):
|
To use other WiFi hardware compatible with any *<a href="https://github.com/knolleary/pubsubclient" target="_blank">Nick O'Leary PubSubClient</a>* library you have to fork `WifiProp.h` and `WifiProp.cpp` and to replace `WiFiNINA.h` with appropriate WiFi library (`ESP8266WiFi.h` for example):
|
||||||
- Arduino WiFi Shield
|
- Arduino WiFi Shield
|
||||||
- Sparkfun WiFly Shield – [library](https://github.com/dpslwk/WiFly)
|
- Sparkfun WiFly Shield – [library](https://github.com/dpslwk/WiFly)
|
||||||
- TI CC3000 WiFi - [library](https://github.com/sparkfun/SFE_CC3000_Library)
|
- TI CC3000 WiFi - [library](https://github.com/sparkfun/SFE_CC3000_Library)
|
||||||
@@ -197,19 +197,19 @@ To use other WiFi hardware compatible with any *<a href="https://github.com/knol
|
|||||||
|
|
||||||
|
|
||||||
## 6. Advantages of Arduino Yun and Dragino Yun shield
|
## 6. Advantages of Arduino Yun and Dragino Yun shield
|
||||||
In escape room 2.0, props are usually powered by Arduino Yun or Arduino Mega 2560 + Dragino Yun shield (or Raspberry Pi) because they are cheap and appropriate for DIY projects.
|
In escape room 2.0, prop are usually powered by Arduino Yun or Arduino Mega 2560 + Dragino Yun shield (or Raspberry Pi) because they are cheap and appropriate for DIY projects.
|
||||||
|
|
||||||
***The advantage of Yun versus Ethernet/Wifi shields is that you can upload sketches remotely to the micro-controller during the whole props lifetime*** (no need to open boxes and break walls to plug an USB cable when a sketch modification is required).
|
***The advantage of Yun versus Ethernet/Wifi shields is that you can upload sketches remotely to the micro-controller during the whole prop lifetime*** (no need to open boxes and break walls to plug an USB cable when a sketch modification is required).
|
||||||
|
|
||||||
Arduino Mega 2560 + Dragino Yun shield offers much more memory and many more pins thann an Arduino Yun for same price.
|
Arduino Mega 2560 + Dragino Yun shield offers much more memory and many more pins thann an Arduino Yun for same price.
|
||||||
|
|
||||||
|
|
||||||
## 7. Advantages of the *ArduinoProps library*
|
## 7. Advantages of the *ArduinoProps library*
|
||||||
You can build escape room 2.0 Arduino-based props just with Nick O'Leary PubSubClient library for MQTT.
|
You can build escape room 2.0 Arduino-based prop just with Nick O'Leary PubSubClient library for MQTT.
|
||||||
|
|
||||||
With *ArduinoProps library*:
|
With *ArduinoProps library*:
|
||||||
- create connected props quickly thanks to the application protocol and examples
|
- create connected prop quickly thanks to the application protocol and examples
|
||||||
- targetted for escape room props, *ArduinoProps library* can be used for any IoT project
|
- targetted for escape room prop, *ArduinoProps library* can be used for any IoT project
|
||||||
- re-use your code when creating new escape rooms
|
- re-use your code when creating new escape rooms
|
||||||
- rely on *ArduinoProps library* robustness: for example, ***the library handles the Arduino Yun Bridge transfer size limitation by smartly splitting large messages (only) when necessary***.
|
- rely on *ArduinoProps library* robustness: for example, ***the library handles the Arduino Yun Bridge transfer size limitation by smartly splitting large messages (only) when necessary***.
|
||||||
|
|
||||||
@@ -219,7 +219,7 @@ With *ArduinoProps library*:
|
|||||||
|
|
||||||
|
|
||||||
## 8. Limitations due to *PubSubClient*
|
## 8. Limitations due to *PubSubClient*
|
||||||
These limitations are not an issue for escape room props:
|
These limitations are not an issue for escape room prop:
|
||||||
- It can only publish QoS 0 messages.
|
- It can only publish QoS 0 messages.
|
||||||
- It can subscribe at QoS 0 or QoS 1.
|
- It can subscribe at QoS 0 or QoS 1.
|
||||||
- The keepalive interval is set to 15 seconds by default. This is configurable
|
- The keepalive interval is set to 15 seconds by default. This is configurable
|
||||||
@@ -232,12 +232,12 @@ These limitations are not an issue for escape room props:
|
|||||||
|
|
||||||
The library comes with a number of example sketches. See **File > Examples > ArduinoProps** within the Arduino IDE application.
|
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 prop:
|
||||||
|
|
||||||
1. **BlinkOnBridgeProps**: the Blink example on a Yun props with *ArduinoProps library*
|
1. **BlinkOnBridgeProp**: the Blink example on a Yun prop with *ArduinoProps library*
|
||||||
2. **BlinkOnEthernetProps**: the Blink example on an Ethernet props with *ArduinoProps library*
|
2. **BlinkOnEthernetProp**: the Blink example on an Ethernet prop with *ArduinoProps library*
|
||||||
3. **BlinkOnWifiProps**: the Blink example on a Wifi props with *ArduinoProps library*
|
3. **BlinkOnWifiProp**: the Blink example on a Wifi prop with *ArduinoProps library*
|
||||||
4. **BlinkOnBridgePubSub**: the Blink example on props using *PubSubClient* directly
|
4. **BlinkOnBridgePubSub**: the Blink example on prop using *PubSubClient* directly
|
||||||
|
|
||||||
|
|
||||||
## Author
|
## Author
|
||||||
|
|||||||
+28
-28
@@ -1,11 +1,11 @@
|
|||||||
/* BlinkOnBridgeProps.ino
|
/* BlinkOnBridgeProp.ino
|
||||||
MIT License (c) Marie Faure <dev at faure dot systems>
|
MIT License (c) Marie Faure <dev at faure dot systems>
|
||||||
|
|
||||||
Adapt the Blink example (https://www.arduino.cc/en/tutorial/blink) as a
|
Adapt the Blink example (https://www.arduino.cc/en/tutorial/blink) as a
|
||||||
simple MQTT props. Avoid delay() calls (except short ones) in loop() to
|
simple MQTT prop. Avoid delay() calls (except short ones) in loop() to
|
||||||
ensure CPU for MQTT protocol. Use PropsAction checks instead.
|
ensure CPU for MQTT protocol. Use PropAction checks instead.
|
||||||
|
|
||||||
Copy and change it to build your first Arduino connected props, you will
|
Copy and change it to build your first Arduino connected prop, you will
|
||||||
only be limited by your imagination.
|
only be limited by your imagination.
|
||||||
|
|
||||||
Requirements:
|
Requirements:
|
||||||
@@ -14,36 +14,36 @@
|
|||||||
#include <Bridge.h>
|
#include <Bridge.h>
|
||||||
#include "ArduinoProps.h"
|
#include "ArduinoProps.h"
|
||||||
|
|
||||||
// If you're running xcape.io Room software you have to respect props inbox/outbox
|
// If you're running xcape.io Room software you have to respect prop inbox/outbox
|
||||||
// topicw syntax: Room/[escape room name]/Props/[propsname]/inbox|outbox
|
// topicw syntax: Room/[escape room name]/Props/[propsname]/inbox|outbox
|
||||||
// https://xcape.io/go/room
|
// https://xcape.io/go/room
|
||||||
|
|
||||||
BridgeProps props(u8"Arduino Blink", // as MQTT client id, should be unique per client for given broker
|
BridgeProp prop(u8"Arduino Blink", // as MQTT client id, should be unique per client for given broker
|
||||||
u8"Room/My room/Props/Arduino Blink/inbox",
|
u8"Room/My room/Props/Arduino Blink/inbox",
|
||||||
u8"Room/My room/Props/Arduino Blink/outbox",
|
u8"Room/My room/Props/Arduino Blink/outbox",
|
||||||
"192.168.1.53", // your MQTT server IP address
|
"192.168.1.53", // your MQTT server IP address
|
||||||
1883); // your MQTT server port;
|
1883); // your MQTT server port;
|
||||||
|
|
||||||
PropsDataLogical blinking(u8"blink", u8"yes", u8"no", true);
|
PropDataLogical blinking(u8"blink", u8"yes", u8"no", true);
|
||||||
PropsDataLogical led(u8"led");
|
PropDataLogical led(u8"led");
|
||||||
PropsDataText rssi(u8"rssi");
|
PropDataText rssi(u8"rssi");
|
||||||
|
|
||||||
void clignote(); // forward
|
void clignote(); // forward
|
||||||
PropsAction blinkingAction = PropsAction(1000, clignote);
|
PropAction blinkingAction = PropAction(1000, clignote);
|
||||||
|
|
||||||
void lireRssi(); // forward
|
void lireRssi(); // forward
|
||||||
PropsAction lireRssiAction = PropsAction(30000, lireRssi);
|
PropAction lireRssiAction = PropAction(30000, lireRssi);
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Bridge.begin();
|
Bridge.begin();
|
||||||
//updateBrokerAdressFromFile("/root/broker", &props); // if you're running our Escape Room control software (Room 2.0)
|
//updateBrokerAdressFromFile("/root/broker", &prop); // if you're running our Escape Room control software (Room 2.0)
|
||||||
|
|
||||||
props.addData(&blinking);
|
prop.addData(&blinking);
|
||||||
props.addData(&led);
|
prop.addData(&led);
|
||||||
props.addData(&rssi);
|
prop.addData(&rssi);
|
||||||
|
|
||||||
props.begin(InboxMessage::run);
|
prop.begin(InboxMessage::run);
|
||||||
|
|
||||||
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output
|
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ void setup()
|
|||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
props.loop();
|
prop.loop();
|
||||||
|
|
||||||
led.setValue(digitalRead(LED_BUILTIN)); // read I/O
|
led.setValue(digitalRead(LED_BUILTIN)); // read I/O
|
||||||
|
|
||||||
@@ -88,35 +88,35 @@ void InboxMessage::run(String a) {
|
|||||||
|
|
||||||
if (a == u8"app:startup")
|
if (a == u8"app:startup")
|
||||||
{
|
{
|
||||||
props.sendAllData();
|
prop.sendAllData();
|
||||||
props.sendDone(a);
|
prop.sendDone(a);
|
||||||
}
|
}
|
||||||
else if (a == u8"reset-mcu")
|
else if (a == u8"reset-mcu")
|
||||||
{
|
{
|
||||||
props.resetMcu(); // we prefer SSH command: echo %BROKER%> /root/broker && reset-mcu
|
prop.resetMcu(); // we prefer SSH command: echo %BROKER%> /root/broker && reset-mcu
|
||||||
}
|
}
|
||||||
else if (a == "blink:1")
|
else if (a == "blink:1")
|
||||||
{
|
{
|
||||||
blinking.setValue(true);
|
blinking.setValue(true);
|
||||||
|
|
||||||
props.sendAllData(); // all data change, we don't have to be selctive then
|
prop.sendAllData(); // all data change, we don't have to be selctive then
|
||||||
props.sendDone(a); // acknowledge props command action
|
prop.sendDone(a); // acknowledge prop command action
|
||||||
}
|
}
|
||||||
else if (a == "blink:0")
|
else if (a == "blink:0")
|
||||||
{
|
{
|
||||||
blinking.setValue(false);
|
blinking.setValue(false);
|
||||||
|
|
||||||
props.sendAllData(); // all data change, we don't have to be selctive then
|
prop.sendAllData(); // all data change, we don't have to be selctive then
|
||||||
props.sendDone(a); // acknowledge props command action
|
prop.sendDone(a); // acknowledge prop command action
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// acknowledge omition of the props command
|
// acknowledge omition of the prop command
|
||||||
props.sendOmit(a);
|
prop.sendOmit(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateBrokerAdressFromFile(const char* broker_file, BridgeProps* props)
|
void updateBrokerAdressFromFile(const char* broker_file, BridgeProp* prop)
|
||||||
{
|
{
|
||||||
// broker IP address is stored in Linino file systems and updated with ssh command by Room 2.0
|
// broker IP address is stored in Linino file systems and updated with ssh command by Room 2.0
|
||||||
IPAddress ip;
|
IPAddress ip;
|
||||||
@@ -132,5 +132,5 @@ void updateBrokerAdressFromFile(const char* broker_file, BridgeProps* props)
|
|||||||
}
|
}
|
||||||
b.trim();
|
b.trim();
|
||||||
|
|
||||||
if (ip.fromString(b.c_str())) props->setBrokerIpAddress(ip);
|
if (ip.fromString(b.c_str())) prop->setBrokerIpAddress(ip);
|
||||||
}
|
}
|
||||||
+29
-29
@@ -1,11 +1,11 @@
|
|||||||
/* BlinkOnBridgeProps.ino
|
/* BlinkOnBridgeProp.ino
|
||||||
MIT License (c) Marie Faure <dev at faure dot systems>
|
MIT License (c) Marie Faure <dev at faure dot systems>
|
||||||
|
|
||||||
Adapt the Blink example (https://www.arduino.cc/en/tutorial/blink) as a
|
Adapt the Blink example (https://www.arduino.cc/en/tutorial/blink) as a
|
||||||
simple MQTT props. Avoid delay() calls (except short ones) in loop() to
|
simple MQTT prop. Avoid delay() calls (except short ones) in loop() to
|
||||||
ensure CPU for MQTT protocol. Use PropsAction checks instead.
|
ensure CPU for MQTT protocol. Use PropAction checks instead.
|
||||||
|
|
||||||
Copy and change it to build your first Arduino connected props, you will
|
Copy and change it to build your first Arduino connected prop, you will
|
||||||
only be limited by your imagination.
|
only be limited by your imagination.
|
||||||
|
|
||||||
Requirements:
|
Requirements:
|
||||||
@@ -14,36 +14,36 @@
|
|||||||
#include <Bridge.h>
|
#include <Bridge.h>
|
||||||
#include "ArduinoProps.h"
|
#include "ArduinoProps.h"
|
||||||
|
|
||||||
// If you're running xcape.io Room software you have to respect props inbox/outbox
|
// If you're running xcape.io Room software you have to respect prop inbox/outbox
|
||||||
// topicw syntax: Room/[escape room name]/Props/[propsname]/inbox|outbox
|
// topicw syntax: Room/[escape room name]/Props/[propname]/inbox|outbox
|
||||||
// https://xcape.io/go/room
|
// https://xcape.io/go/room
|
||||||
|
|
||||||
BridgeProps props(u8"Arduino Blink", // as MQTT client id, should be unique per client for given broker
|
BridgeProp prop(u8"Arduino Blink", // as MQTT client id, should be unique per client for given broker
|
||||||
u8"Room/My room/Props/Arduino Blink/inbox",
|
u8"Room/My room/Props/Arduino Blink/inbox",
|
||||||
u8"Room/My room/Props/Arduino Blink/outbox",
|
u8"Room/My room/Props/Arduino Blink/outbox",
|
||||||
"192.168.1.53", // your MQTT server IP address
|
"192.168.1.53", // your MQTT server IP address
|
||||||
1883); // your MQTT server port;
|
1883); // your MQTT server port;
|
||||||
|
|
||||||
PropsDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
PropDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
||||||
PropsDataLogical led(u8"led");
|
PropDataLogical led(u8"led");
|
||||||
PropsDataText rssi(u8"rssi");
|
PropDataText rssi(u8"rssi");
|
||||||
|
|
||||||
void clignote(); // forward
|
void clignote(); // forward
|
||||||
PropsAction clignoteAction = PropsAction(1000, clignote);
|
PropAction clignoteAction = PropAction(1000, clignote);
|
||||||
|
|
||||||
void lireRssi(); // forward
|
void lireRssi(); // forward
|
||||||
PropsAction lireRssiAction = PropsAction(30000, lireRssi);
|
PropAction lireRssiAction = PropAction(30000, lireRssi);
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Bridge.begin();
|
Bridge.begin();
|
||||||
//updateBrokerAdressFromFile("/root/broker", &props); // if you're running our Escape Room control software (Room 2.0)
|
//updateBrokerAdressFromFile("/root/broker", &prop); // if you're running our Escape Room control software (Room 2.0)
|
||||||
|
|
||||||
props.addData(&clignoter);
|
prop.addData(&clignoter);
|
||||||
props.addData(&led);
|
prop.addData(&led);
|
||||||
props.addData(&rssi);
|
prop.addData(&rssi);
|
||||||
|
|
||||||
props.begin(InboxMessage::run);
|
prop.begin(InboxMessage::run);
|
||||||
|
|
||||||
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output
|
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ void setup()
|
|||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
props.loop();
|
prop.loop();
|
||||||
|
|
||||||
led.setValue(digitalRead(LED_BUILTIN)); // read I/O
|
led.setValue(digitalRead(LED_BUILTIN)); // read I/O
|
||||||
|
|
||||||
@@ -88,35 +88,35 @@ void InboxMessage::run(String a) {
|
|||||||
|
|
||||||
if (a == u8"app:startup")
|
if (a == u8"app:startup")
|
||||||
{
|
{
|
||||||
props.sendAllData();
|
prop.sendAllData();
|
||||||
props.sendDone(a);
|
prop.sendDone(a);
|
||||||
}
|
}
|
||||||
else if (a == u8"reset-mcu")
|
else if (a == u8"reset-mcu")
|
||||||
{
|
{
|
||||||
props.resetMcu(); // we prefer SSH command: echo %BROKER%> /root/broker && reset-mcu
|
prop.resetMcu(); // we prefer SSH command: echo %BROKER%> /root/broker && reset-mcu
|
||||||
}
|
}
|
||||||
else if (a == "clignoter:1")
|
else if (a == "clignoter:1")
|
||||||
{
|
{
|
||||||
clignoter.setValue(true);
|
clignoter.setValue(true);
|
||||||
|
|
||||||
props.sendAllData(); // all data change, we don't have to be selctive then
|
prop.sendAllData(); // all data change, we don't have to be selctive then
|
||||||
props.sendDone(a); // acknowledge props command action
|
prop.sendDone(a); // acknowledge prop command action
|
||||||
}
|
}
|
||||||
else if (a == "clignoter:0")
|
else if (a == "clignoter:0")
|
||||||
{
|
{
|
||||||
clignoter.setValue(false);
|
clignoter.setValue(false);
|
||||||
|
|
||||||
props.sendAllData(); // all data change, we don't have to be selctive then
|
prop.sendAllData(); // all data change, we don't have to be selctive then
|
||||||
props.sendDone(a); // acknowledge props command action
|
prop.sendDone(a); // acknowledge prop command action
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// acknowledge omition of the props command
|
// acknowledge omition of the prop command
|
||||||
props.sendOmit(a);
|
prop.sendOmit(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateBrokerAdressFromFile(const char* broker_file, BridgeProps* props)
|
void updateBrokerAdressFromFile(const char* broker_file, BridgeProp* prop)
|
||||||
{
|
{
|
||||||
// broker IP address is stored in Linino file systems and updated with ssh command by Room 2.0
|
// broker IP address is stored in Linino file systems and updated with ssh command by Room 2.0
|
||||||
IPAddress ip;
|
IPAddress ip;
|
||||||
@@ -132,5 +132,5 @@ void updateBrokerAdressFromFile(const char* broker_file, BridgeProps* props)
|
|||||||
}
|
}
|
||||||
b.trim();
|
b.trim();
|
||||||
|
|
||||||
if (ip.fromString(b.c_str())) props->setBrokerIpAddress(ip);
|
if (ip.fromString(b.c_str())) prop->setBrokerIpAddress(ip);
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
MIT License (c) Marie Faure <dev at faure dot systems>
|
MIT License (c) Marie Faure <dev at faure dot systems>
|
||||||
|
|
||||||
Adapt the Blink example (https://www.arduino.cc/en/tutorial/blink) as a
|
Adapt the Blink example (https://www.arduino.cc/en/tutorial/blink) as a
|
||||||
simple MQTT props with PubSubClient.
|
simple MQTT prop with PubSubClient.
|
||||||
*/
|
*/
|
||||||
#include <Bridge.h>
|
#include <Bridge.h>
|
||||||
#include <BridgeClient.h>
|
#include <BridgeClient.h>
|
||||||
@@ -10,14 +10,14 @@
|
|||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
#include <VariableTimedAction.h>
|
#include <VariableTimedAction.h>
|
||||||
|
|
||||||
// If you're running xcape.io Room software you have to respect props inbox/outbox
|
// If you're running xcape.io Room software you have to respect prop inbox/outbox
|
||||||
// topicw syntax: Room/[escape room name]/Props/[propsname]/inbox|outbox
|
// topicw syntax: Room/[escape room name]/Props/[propsname]/inbox|outbox
|
||||||
// https://xcape.io/go/room
|
// https://xcape.io/go/room
|
||||||
|
|
||||||
#define BROKER "192.168.1.53" // your MQTT server IP address
|
#define BROKER "192.168.1.53" // your MQTT server IP address
|
||||||
#define PROPS_NAME u8"Arduino Blink" // as MQTT client id, should be unique per client for given broker
|
#define PROP_NAME u8"Arduino Blink" // as MQTT client id, should be unique per client for given broker
|
||||||
#define PROPS_INBOX u8"Room/My room/Props/Arduino Blink/inbox"
|
#define PROP_INBOX u8"Room/My room/Props/Arduino Blink/inbox"
|
||||||
#define PROPS_OUTBOX u8"Room/My room/Props/Arduino Blink/outbox"
|
#define PROP_OUTBOX u8"Room/My room/Props/Arduino Blink/outbox"
|
||||||
|
|
||||||
// Yun can store broker IP address in Linino file systems, and updatred with ssh command
|
// Yun can store broker IP address in Linino file systems, and updatred with ssh command
|
||||||
#define YUN_BROKER_FILE "/root/broker"
|
#define YUN_BROKER_FILE "/root/broker"
|
||||||
@@ -118,10 +118,10 @@ void loop()
|
|||||||
{
|
{
|
||||||
lastReconnection += 5000L;
|
lastReconnection += 5000L;
|
||||||
|
|
||||||
if (_client.connect(PROPS_NAME, PROPS_OUTBOX, 2, true, "DISCONNECTED"))
|
if (_client.connect(PROP_NAME, PROP_OUTBOX, 2, true, "DISCONNECTED"))
|
||||||
{
|
{
|
||||||
_client.publish(PROPS_OUTBOX, "CONNECTED", true);
|
_client.publish(PROP_OUTBOX, "CONNECTED", true);
|
||||||
_client.subscribe(PROPS_INBOX, 1); // max QoS is 1 for PubSubClient subsciption
|
_client.subscribe(PROP_INBOX, 1); // max QoS is 1 for PubSubClient subsciption
|
||||||
lastReconnection = 0L;
|
lastReconnection = 0L;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,7 +143,7 @@ void publishAll()
|
|||||||
buf += u8" clignote=" + (blinking.blink ? String("oui") : String("non"));
|
buf += u8" clignote=" + (blinking.blink ? String("oui") : String("non"));
|
||||||
blink_ref = blinking.blink;
|
blink_ref = blinking.blink;
|
||||||
|
|
||||||
_client.publish(PROPS_OUTBOX, buf.c_str());
|
_client.publish(PROP_OUTBOX, buf.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void publishChanges()
|
void publishChanges()
|
||||||
@@ -165,13 +165,13 @@ void publishChanges()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (buf.length() > 4)
|
if (buf.length() > 4)
|
||||||
_client.publish(PROPS_OUTBOX, buf.c_str());
|
_client.publish(PROP_OUTBOX, buf.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void publishDone(String a)
|
void publishDone(String a)
|
||||||
{
|
{
|
||||||
a = "DONE " + a;
|
a = "DONE " + a;
|
||||||
_client.publish(PROPS_OUTBOX, a.c_str());
|
_client.publish(PROP_OUTBOX, a.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void onInboxMessage(String a) {
|
void onInboxMessage(String a) {
|
||||||
@@ -187,7 +187,7 @@ void onInboxMessage(String a) {
|
|||||||
blinking.blink = true;
|
blinking.blink = true;
|
||||||
|
|
||||||
publishAll(); // all data change, we don't have to be selctive then
|
publishAll(); // all data change, we don't have to be selctive then
|
||||||
publishDone(a); // acknowledge props command action
|
publishDone(a); // acknowledge prop command action
|
||||||
}
|
}
|
||||||
else if (a == "clignoter:0")
|
else if (a == "clignoter:0")
|
||||||
{
|
{
|
||||||
@@ -195,12 +195,12 @@ void onInboxMessage(String a) {
|
|||||||
blinking.blink = false;
|
blinking.blink = false;
|
||||||
|
|
||||||
publishAll(); // all data change, we don't have to be selctive then
|
publishAll(); // all data change, we don't have to be selctive then
|
||||||
publishDone(a); // acknowledge props command action
|
publishDone(a); // acknowledge prop command action
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// acknowledge omition of the props command
|
// acknowledge omition of the prop command
|
||||||
_client.publish(PROPS_OUTBOX, String("OMIT " + a).c_str());
|
_client.publish(PROP_OUTBOX, String("OMIT " + a).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +212,7 @@ void callback(char* topic, byte* payload, unsigned int len)
|
|||||||
memcpy(p, payload, len);
|
memcpy(p, payload, len);
|
||||||
p[len] = '\0';
|
p[len] = '\0';
|
||||||
if (String(p) == "@PING")
|
if (String(p) == "@PING")
|
||||||
_client.publish(PROPS_OUTBOX, "PONG");
|
_client.publish(PROP_OUTBOX, "PONG");
|
||||||
else
|
else
|
||||||
onInboxMessage(p);
|
onInboxMessage(p);
|
||||||
free(p);
|
free(p);
|
||||||
|
|||||||
+22
-22
@@ -1,11 +1,11 @@
|
|||||||
/* BlinkOnEthernetProps.ino
|
/* BlinkOnEthernetProp.ino
|
||||||
MIT License (c) Marie Faure <dev at faure dot systems>
|
MIT License (c) Marie Faure <dev at faure dot systems>
|
||||||
|
|
||||||
Adapt the Blink example (https://www.arduino.cc/en/tutorial/blink) as a
|
Adapt the Blink example (https://www.arduino.cc/en/tutorial/blink) as a
|
||||||
simple MQTT props. Avoid delay() calls (except short ones) in loop() to
|
simple MQTT prop. Avoid delay() calls (except short ones) in loop() to
|
||||||
ensure CPU for MQTT protocol. Use PropsAction checks instead.
|
ensure CPU for MQTT protocol. Use PropAction checks instead.
|
||||||
|
|
||||||
Copy and change it to build your first Arduino connected props, you will
|
Copy and change it to build your first Arduino connected prop, you will
|
||||||
only be limited by your imagination.
|
only be limited by your imagination.
|
||||||
|
|
||||||
Requirements:
|
Requirements:
|
||||||
@@ -15,11 +15,11 @@
|
|||||||
#include <IPAddress.h>
|
#include <IPAddress.h>
|
||||||
#include "ArduinoProps.h"
|
#include "ArduinoProps.h"
|
||||||
|
|
||||||
// If you're running xcape.io Room software you have to respect props inbox/outbox
|
// If you're running xcape.io Room software you have to respect prop inbox/outbox
|
||||||
// topicw syntax: Room/[escape room name]/Props/[propsname]/inbox|outbox
|
// topicw syntax: Room/[escape room name]/Props/[propsname]/inbox|outbox
|
||||||
// https://xcape.io/go/room
|
// https://xcape.io/go/room
|
||||||
|
|
||||||
EthernetProps props(u8"Arduino Blink", // as MQTT client id, should be unique per client for given broker
|
EthernetProp prop(u8"Arduino Blink", // as MQTT client id, should be unique per client for given broker
|
||||||
u8"Room/My room/Props/Arduino Blink/inbox",
|
u8"Room/My room/Props/Arduino Blink/inbox",
|
||||||
u8"Room/My room/Props/Arduino Blink/outbox",
|
u8"Room/My room/Props/Arduino Blink/outbox",
|
||||||
"192.168.1.53", // your MQTT server IP address
|
"192.168.1.53", // your MQTT server IP address
|
||||||
@@ -32,11 +32,11 @@ String ip = "192.168.1.19"; //<<< ENTER YOUR IP ADDRESS HERE ("" for DHCP)
|
|||||||
#undef LED_BUILTIN
|
#undef LED_BUILTIN
|
||||||
#define LED_BUILTIN 8
|
#define LED_BUILTIN 8
|
||||||
|
|
||||||
PropsDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
PropDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
||||||
PropsDataLogical led(u8"led");
|
PropDataLogical led(u8"led");
|
||||||
|
|
||||||
void clignote(); // forward
|
void clignote(); // forward
|
||||||
PropsAction clignoteAction = PropsAction(1000, clignote);
|
PropAction clignoteAction = PropAction(1000, clignote);
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
@@ -59,10 +59,10 @@ void setup()
|
|||||||
//Ethernet.setGatewayIP(IPAddress(192, 168, 1, 1));
|
//Ethernet.setGatewayIP(IPAddress(192, 168, 1, 1));
|
||||||
//Ethernet.setDnsServerIP(IPAddress(192, 168, 1, 1));
|
//Ethernet.setDnsServerIP(IPAddress(192, 168, 1, 1));
|
||||||
|
|
||||||
props.addData(&clignoter);
|
prop.addData(&clignoter);
|
||||||
props.addData(&led);
|
prop.addData(&led);
|
||||||
|
|
||||||
props.begin(InboxMessage::run);
|
prop.begin(InboxMessage::run);
|
||||||
|
|
||||||
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output
|
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ void setup()
|
|||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
props.loop();
|
prop.loop();
|
||||||
|
|
||||||
led.setValue(digitalRead(LED_BUILTIN)); // read I/O
|
led.setValue(digitalRead(LED_BUILTIN)); // read I/O
|
||||||
|
|
||||||
@@ -90,30 +90,30 @@ void InboxMessage::run(String a) {
|
|||||||
|
|
||||||
if (a == u8"app:startup")
|
if (a == u8"app:startup")
|
||||||
{
|
{
|
||||||
props.sendAllData();
|
prop.sendAllData();
|
||||||
props.sendDone(a);
|
prop.sendDone(a);
|
||||||
}
|
}
|
||||||
else if (a == u8"reset-mcu")
|
else if (a == u8"reset-mcu")
|
||||||
{
|
{
|
||||||
props.resetMcu();
|
prop.resetMcu();
|
||||||
}
|
}
|
||||||
else if (a == "clignoter:1")
|
else if (a == "clignoter:1")
|
||||||
{
|
{
|
||||||
clignoter.setValue(true);
|
clignoter.setValue(true);
|
||||||
|
|
||||||
props.sendAllData(); // all data change, we don't have to be selctive then
|
prop.sendAllData(); // all data change, we don't have to be selctive then
|
||||||
props.sendDone(a); // acknowledge props command action
|
prop.sendDone(a); // acknowledge prop command action
|
||||||
}
|
}
|
||||||
else if (a == "clignoter:0")
|
else if (a == "clignoter:0")
|
||||||
{
|
{
|
||||||
clignoter.setValue(false);
|
clignoter.setValue(false);
|
||||||
|
|
||||||
props.sendAllData(); // all data change, we don't have to be selctive then
|
prop.sendAllData(); // all data change, we don't have to be selctive then
|
||||||
props.sendDone(a); // acknowledge props command action
|
prop.sendDone(a); // acknowledge prop command action
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// acknowledge omition of the props command
|
// acknowledge omition of the prop command
|
||||||
props.sendOmit(a);
|
prop.sendOmit(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+25
-25
@@ -1,11 +1,11 @@
|
|||||||
/* BlinkOnWifiProps.ino
|
/* BlinkOnWifiProp.ino
|
||||||
MIT License (c) Marie Faure <dev at faure dot systems>
|
MIT License (c) Marie Faure <dev at faure dot systems>
|
||||||
|
|
||||||
Adapt the Blink example (https://www.arduino.cc/en/tutorial/blink) as a
|
Adapt the Blink example (https://www.arduino.cc/en/tutorial/blink) as a
|
||||||
simple MQTT props. Avoid delay() calls (except short ones) in loop() to
|
simple MQTT prop. Avoid delay() calls (except short ones) in loop() to
|
||||||
ensure CPU for MQTT protocol. Use PropsAction checks instead.
|
ensure CPU for MQTT protocol. Use PropAction checks instead.
|
||||||
|
|
||||||
Copy and change it to build your first Arduino connected props, you will
|
Copy and change it to build your first Arduino connected prop, you will
|
||||||
only be limited by your imagination.
|
only be limited by your imagination.
|
||||||
|
|
||||||
Requirements:
|
Requirements:
|
||||||
@@ -17,11 +17,11 @@
|
|||||||
const char* ssid = "";
|
const char* ssid = "";
|
||||||
const char *passphrase = "";
|
const char *passphrase = "";
|
||||||
|
|
||||||
// If you're running xcape.io Room software you have to respect props inbox/outbox
|
// If you're running xcape.io Room software you have to respect prop inbox/outbox
|
||||||
// topicw syntax: Room/[escape room name]/Props/[propsname]/inbox|outbox
|
// topicw syntax: Room/[escape room name]/Props/[propsname]/inbox|outbox
|
||||||
// https://xcape.io/go/room
|
// https://xcape.io/go/room
|
||||||
|
|
||||||
WifiProps props(u8"Arduino Blink", // as MQTT client id, should be unique per client for given broker
|
WifiProp prop(u8"Arduino Blink", // as MQTT client id, should be unique per client for given broker
|
||||||
u8"Room/My room/Props/Arduino Blink/inbox",
|
u8"Room/My room/Props/Arduino Blink/inbox",
|
||||||
u8"Room/My room/Props/Arduino Blink/outbox",
|
u8"Room/My room/Props/Arduino Blink/outbox",
|
||||||
"192.168.1.53", // your MQTT server IP address
|
"192.168.1.53", // your MQTT server IP address
|
||||||
@@ -31,12 +31,12 @@ WifiProps props(u8"Arduino Blink", // as MQTT client id, should be unique per cl
|
|||||||
#undef LED_BUILTIN
|
#undef LED_BUILTIN
|
||||||
#define LED_BUILTIN 8
|
#define LED_BUILTIN 8
|
||||||
|
|
||||||
PropsDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
PropDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
||||||
PropsDataLogical led(u8"led");
|
PropDataLogical led(u8"led");
|
||||||
PropsDataText rssi(u8"rssi");
|
PropDataText rssi(u8"rssi");
|
||||||
|
|
||||||
void clignote(); // forward
|
void clignote(); // forward
|
||||||
PropsAction clignoteAction = PropsAction(1000, clignote);
|
PropAction clignoteAction = PropAction(1000, clignote);
|
||||||
|
|
||||||
bool wifiBegun(false);
|
bool wifiBegun(false);
|
||||||
|
|
||||||
@@ -44,11 +44,11 @@ void setup()
|
|||||||
{
|
{
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
props.addData(&clignoter);
|
prop.addData(&clignoter);
|
||||||
props.addData(&led);
|
prop.addData(&led);
|
||||||
props.addData(&rssi);
|
prop.addData(&rssi);
|
||||||
|
|
||||||
props.begin(InboxMessage::run);
|
prop.begin(InboxMessage::run);
|
||||||
|
|
||||||
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output
|
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ void loop()
|
|||||||
if (!wifiBegun) {
|
if (!wifiBegun) {
|
||||||
WiFi.begin(ssid, passphrase);
|
WiFi.begin(ssid, passphrase);
|
||||||
Serial.println(WiFi.firmwareVersion());
|
Serial.println(WiFi.firmwareVersion());
|
||||||
delay(250); // acceptable freeze for this props (otherwise use PropsAction for async-like behavior)
|
delay(250); // acceptable freeze for this prop (otherwise use PropAction for async-like behavior)
|
||||||
// do static IP configuration disabling the dhcp client, must be called after every WiFi.begin()
|
// do static IP configuration disabling the dhcp client, must be called after every WiFi.begin()
|
||||||
String fv = WiFi.firmwareVersion();
|
String fv = WiFi.firmwareVersion();
|
||||||
if (fv.startsWith("1.0")) {
|
if (fv.startsWith("1.0")) {
|
||||||
@@ -86,7 +86,7 @@ void loop()
|
|||||||
wifiBegun = false;
|
wifiBegun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
props.loop();
|
prop.loop();
|
||||||
|
|
||||||
rssi.setValue(WiFi.RSSI() + String(" dBm")); // https://www.metageek.com/training/resources/understanding-rssi.html
|
rssi.setValue(WiFi.RSSI() + String(" dBm")); // https://www.metageek.com/training/resources/understanding-rssi.html
|
||||||
|
|
||||||
@@ -107,30 +107,30 @@ void InboxMessage::run(String a) {
|
|||||||
|
|
||||||
if (a == u8"app:startup")
|
if (a == u8"app:startup")
|
||||||
{
|
{
|
||||||
props.sendAllData();
|
prop.sendAllData();
|
||||||
props.sendDone(a);
|
prop.sendDone(a);
|
||||||
}
|
}
|
||||||
else if (a == u8"reset-mcu")
|
else if (a == u8"reset-mcu")
|
||||||
{
|
{
|
||||||
props.resetMcu();
|
prop.resetMcu();
|
||||||
}
|
}
|
||||||
else if (a == "clignoter:1")
|
else if (a == "clignoter:1")
|
||||||
{
|
{
|
||||||
clignoter.setValue(true);
|
clignoter.setValue(true);
|
||||||
|
|
||||||
props.sendAllData(); // all data change, we don't have to be selctive then
|
prop.sendAllData(); // all data change, we don't have to be selctive then
|
||||||
props.sendDone(a); // acknowledge props command action
|
prop.sendDone(a); // acknowledge prop command action
|
||||||
}
|
}
|
||||||
else if (a == "clignoter:0")
|
else if (a == "clignoter:0")
|
||||||
{
|
{
|
||||||
clignoter.setValue(false);
|
clignoter.setValue(false);
|
||||||
|
|
||||||
props.sendAllData(); // all data change, we don't have to be selctive then
|
prop.sendAllData(); // all data change, we don't have to be selctive then
|
||||||
props.sendDone(a); // acknowledge props command action
|
prop.sendDone(a); // acknowledge prop command action
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// acknowledge omition of the props command
|
// acknowledge omition of the prop command
|
||||||
props.sendOmit(a);
|
prop.sendOmit(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+11
-11
@@ -1,8 +1,8 @@
|
|||||||
# Arduino Props for Escape Room 2.0
|
# Arduino Props for Escape Room 2.0
|
||||||
|
|
||||||
The *ArduinoProps library* for Arduino has been designed to build *escape room 2.0 props*.
|
The *ArduinoProps library* for Arduino has been designed to build *escape room 2.0 prop*.
|
||||||
|
|
||||||
Specificities of props for escape rooms:
|
Specificities of prop for escape rooms:
|
||||||
- very high uptime (near 100%)
|
- very high uptime (near 100%)
|
||||||
- fast problem fixing
|
- fast problem fixing
|
||||||
- real-time (human scale) notification and control
|
- real-time (human scale) notification and control
|
||||||
@@ -15,7 +15,7 @@ Benefits and specificities of the *ArduinoProps library*
|
|||||||
- constant sustaining of Arduino code (YUN)
|
- constant sustaining of Arduino code (YUN)
|
||||||
- real-time notification, monitoring and control (human scale)
|
- real-time notification, monitoring and control (human scale)
|
||||||
|
|
||||||
# Escape room 2.0 constraints on props
|
# Escape room 2.0 constraints on prop
|
||||||
Escape game are opened 7 days a week and particularly booked during weekends and usually until midnight. Therefore their uptime must be close to 100% and incidents must be worked-around immediately by the game master (manual commands).
|
Escape game are opened 7 days a week and particularly booked during weekends and usually until midnight. Therefore their uptime must be close to 100% and incidents must be worked-around immediately by the game master (manual commands).
|
||||||
|
|
||||||
Escape Room Props operation and performance impact directly escape game customer experience. Therefore notifications must be processed in human-scale real-time, automatically or manually by a non-technological user (the game master).
|
Escape Room Props operation and performance impact directly escape game customer experience. Therefore notifications must be processed in human-scale real-time, automatically or manually by a non-technological user (the game master).
|
||||||
@@ -24,7 +24,7 @@ Escape Room Props TCO (Total Cost of Ownership) must be affordable by escape gam
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
IT professional 24/7 support must be avoided for cost reasons. Therefore props code must be the most reliable.
|
IT professional 24/7 support must be avoided for cost reasons. Therefore prop code must be the most reliable.
|
||||||
|
|
||||||
|
|
||||||
# *ArduinoProps library* for escape room 2.0
|
# *ArduinoProps library* for escape room 2.0
|
||||||
@@ -39,10 +39,10 @@ IT professional 24/7 support must be avoided for cost reasons. Therefore props c
|
|||||||
|
|
||||||
How does *ArduinoProps library* use MQTT efficiently in escape rooms:
|
How does *ArduinoProps library* use MQTT efficiently in escape rooms:
|
||||||
|
|
||||||
- Every props has two MQTT topics assigned as inbox and outbox.
|
- Every prop has two MQTT topics assigned as inbox and outbox.
|
||||||
- More MQTT topics can be used to share game countdown, scenario or any common useful dynamic data for the escape game.
|
- More MQTT topics can be used to share game countdown, scenario or any common useful dynamic data for the escape game.
|
||||||
- Notifying the props is done by publishing a message on its inbox topic.
|
- Notifying the prop is done by publishing a message on its inbox topic.
|
||||||
- Other props or software controllers can subscribe to the props outbox topic to receive all its notifications.
|
- Other prop or software controllers can subscribe to the prop outbox topic to receive all its notifications.
|
||||||
- *ArduinoProps library* includes a ping process at application level, in LAN network the round-trip-delay is around 50 milliseconds.
|
- *ArduinoProps library* includes a ping process at application level, in LAN network the round-trip-delay is around 50 milliseconds.
|
||||||
- *ArduinoProps library* is defaulted to publish QoS 0 messages and to subscribe at QoS 1.
|
- *ArduinoProps library* is defaulted to publish QoS 0 messages and to subscribe at QoS 1.
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ Arduino YUN can be rebooted or its MCU resetted remotely with simple SSH command
|
|||||||
|
|
||||||
Moreover, SSH command can be used to remotely change the MQTT server IP address, *ArduinoProps library* read this address at sketch start.
|
Moreover, SSH command can be used to remotely change the MQTT server IP address, *ArduinoProps library* read this address at sketch start.
|
||||||
|
|
||||||
Therefore, **Arduino YUN or YUN shield is the preferred solution for props with Arduino boards** because it will be very easy to sustain over time and greatly facilitates fallback plans to ensure maximum uptime:
|
Therefore, **Arduino YUN or YUN shield is the preferred solution for prop with Arduino boards** because it will be very easy to sustain over time and greatly facilitates fallback plans to ensure maximum uptime:
|
||||||
- **Arduino Yún**
|
- **Arduino Yún**
|
||||||
- **Arduino Yún Rev 2**
|
- **Arduino Yún Rev 2**
|
||||||
- **Arduino Mega 2560 Rev3 + Dragino Yún Shield**
|
- **Arduino Mega 2560 Rev3 + Dragino Yún Shield**
|
||||||
@@ -71,7 +71,7 @@ Therefore, **Arduino YUN or YUN shield is the preferred solution for props with
|
|||||||
|
|
||||||
|
|
||||||
# Arduino Ethernet and Wifi
|
# Arduino Ethernet and Wifi
|
||||||
Arduino with Ethernet or Wifi shield is suitable to build an Escape Room Props, however the sketch must be uploaded with an USB cable, so it is not convenient for props design and worse for props in production, which can lead to an unexpected significant increase in TCO.
|
Arduino with Ethernet or Wifi shield is suitable to build an Escape Room Props, however the sketch must be uploaded with an USB cable, so it is not convenient for prop design and worse for prop in production, which can lead to an unexpected significant increase in TCO.
|
||||||
|
|
||||||
|
|
||||||
# Compatible hardware
|
# Compatible hardware
|
||||||
@@ -85,9 +85,9 @@ Arduino with Ethernet or Wifi shield is suitable to build an Escape Room Props,
|
|||||||
- Arduino Ethernet
|
- Arduino Ethernet
|
||||||
- Arduino Ethernet Shield
|
- Arduino Ethernet Shield
|
||||||
|
|
||||||
For WiFi props, please update the WiFiNINA firmware: [WiFiNINA firmware update](WifiNinaFirmware.md).
|
For WiFi prop, please update the WiFiNINA firmware: [WiFiNINA firmware update](WifiNinaFirmware.md).
|
||||||
|
|
||||||
To use other WiFi hardware compatible with any *<a href="https://github.com/knolleary/pubsubclient" target="_blank">Nick O'Leary PubSubClient</a>* library you have to fork `WifiProps.h` and `WifiProps.cpp` and to replace `WiFiNINA.h` whih appropriate WiFi library (`ESP8266WiFi.h` for example):
|
To use other WiFi hardware compatible with any *<a href="https://github.com/knolleary/pubsubclient" target="_blank">Nick O'Leary PubSubClient</a>* library you have to fork `WifiProp.h` and `WifiProp.cpp` and to replace `WiFiNINA.h` whih appropriate WiFi library (`ESP8266WiFi.h` for example):
|
||||||
- Arduino WiFi Shield
|
- Arduino WiFi Shield
|
||||||
- Sparkfun WiFly Shield – [library](https://github.com/dpslwk/WiFly)
|
- Sparkfun WiFly Shield – [library](https://github.com/dpslwk/WiFly)
|
||||||
- TI CC3000 WiFi - [library](https://github.com/sparkfun/SFE_CC3000_Library)
|
- TI CC3000 WiFi - [library](https://github.com/sparkfun/SFE_CC3000_Library)
|
||||||
|
|||||||
@@ -1,28 +1,28 @@
|
|||||||
# *Props* class reference
|
# *Prop* class reference
|
||||||
|
|
||||||
*Props* is a base class for 3 connected props, depending on their network interface:
|
*Prop* is a base class for 3 connected prop, depending on their network interface:
|
||||||
* ***BridgeProps*** for Yun board and Yun shield
|
* ***BridgeProp*** for Yun board and Yun shield
|
||||||
* ***EthernetProps*** for Ethernet shield
|
* ***EthernetProp*** for Ethernet shield
|
||||||
* ***WifiProps*** for WiFiNINA boards
|
* ***WifiProp*** for WiFiNINA boards
|
||||||
|
|
||||||
*Props* class reference:
|
*Prop* class reference:
|
||||||
1. Define the *Props*
|
1. Define the *Prop*
|
||||||
* Defining a *BridgeProps*
|
* Defining a *BridgeProp*
|
||||||
* Defining an *EthernetProps*
|
* Defining an *EthernetProp*
|
||||||
* Defining a *WifiProps*
|
* Defining a *WifiProp*
|
||||||
2. Setup the *Props*
|
2. Setup the *Prop*
|
||||||
* Change timings
|
* Change timings
|
||||||
3. Call in sketch *loop()*
|
3. Call in sketch *loop()*
|
||||||
4. Implement `InboxMessage::run()` callback
|
4. Implement `InboxMessage::run()` callback
|
||||||
5. Update broker address from SSH (*BridgeProps*)
|
5. Update broker address from SSH (*BridgeProp*)
|
||||||
6. Examples
|
6. Examples
|
||||||
7. Compatible hardware
|
7. Compatible hardware
|
||||||
|
|
||||||
|
|
||||||
## 1. Defines the *Props*
|
## 1. Defines the *Prop*
|
||||||
Defining a Bridge (Yun), Ethernet or Wifi *Props* is slighlty different.
|
Defining a Bridge (Yun), Ethernet or Wifi *Prop* is slighlty different.
|
||||||
|
|
||||||
### Defining a *BridgeProps*
|
### Defining a *BridgeProp*
|
||||||
```csharp
|
```csharp
|
||||||
#include <Bridge.h>
|
#include <Bridge.h>
|
||||||
#include "ArduinoProps.h"
|
#include "ArduinoProps.h"
|
||||||
@@ -31,23 +31,23 @@ Defining a Bridge (Yun), Ethernet or Wifi *Props* is slighlty different.
|
|||||||
// prpos inbox/outbox syntax Room/[escape room name]/Props/[propsname]/inbox|outbox
|
// prpos inbox/outbox syntax Room/[escape room name]/Props/[propsname]/inbox|outbox
|
||||||
// https://live-escape.net/go/room
|
// https://live-escape.net/go/room
|
||||||
|
|
||||||
BridgeProps props(u8"Arduino Contrôleur", // as MQTT client id, should be unique per client for given broker
|
BridgeProp prop(u8"Arduino Contrôleur", // as MQTT client id, should be unique per client for given broker
|
||||||
u8"Room/Demoniak/Props/Arduino Contrôleur/inbox",
|
u8"Room/Demoniak/Props/Arduino Contrôleur/inbox",
|
||||||
u8"Room/Demoniak/Props/Arduino Contrôleur/outbox",
|
u8"Room/Demoniak/Props/Arduino Contrôleur/outbox",
|
||||||
"192.168.1.42", // your MQTT server IP address
|
"192.168.1.42", // your MQTT server IP address
|
||||||
1883); // your MQTT server port;
|
1883); // your MQTT server port;
|
||||||
|
|
||||||
PropsDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
PropDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
||||||
PropsDataLogical led(u8"led");
|
PropDataLogical led(u8"led");
|
||||||
|
|
||||||
void clignote(); // forward
|
void clignote(); // forward
|
||||||
PropsAction clignoteAction = PropsAction(1000, clignote);
|
PropAction clignoteAction = PropAction(1000, clignote);
|
||||||
```
|
```
|
||||||
Create *BridgeProps* instance with MQTT parameters, then create *PropsData* instances and *PropsActions*.
|
Create *BridgeProp* instance with MQTT parameters, then create *PropData* instances and *PropsActions*.
|
||||||
|
|
||||||
The *Bridge* instance is created by `#include <Bridge.h>`.
|
The *Bridge* instance is created by `#include <Bridge.h>`.
|
||||||
|
|
||||||
### Defining an *EthernetProps*
|
### Defining an *EthernetProp*
|
||||||
```csharp
|
```csharp
|
||||||
#include <Ethernet.h>
|
#include <Ethernet.h>
|
||||||
#include <IPAddress.h>
|
#include <IPAddress.h>
|
||||||
@@ -64,25 +64,25 @@ String ip = "192.168.1.19"; //<<< ENTER YOUR IP ADDRESS HERE ("" for DHCP)
|
|||||||
// prpos inbox/outbox syntax Room/[escape room name]/Props/[propsname]/inbox|outbox
|
// prpos inbox/outbox syntax Room/[escape room name]/Props/[propsname]/inbox|outbox
|
||||||
// https://live-escape.net/go/room
|
// https://live-escape.net/go/room
|
||||||
|
|
||||||
EthernetProps props(u8"Arduino Contrôleur", // as MQTT client id, should be unique per client for given broker
|
EthernetProp prop(u8"Arduino Contrôleur", // as MQTT client id, should be unique per client for given broker
|
||||||
u8"Room/Demoniak/Props/Arduino Contrôleur/inbox",
|
u8"Room/Demoniak/Props/Arduino Contrôleur/inbox",
|
||||||
u8"Room/Demoniak/Props/Arduino Contrôleur/outbox",
|
u8"Room/Demoniak/Props/Arduino Contrôleur/outbox",
|
||||||
"192.168.1.42", // your MQTT server IP address
|
"192.168.1.42", // your MQTT server IP address
|
||||||
1883); // your MQTT server port;
|
1883); // your MQTT server port;
|
||||||
|
|
||||||
PropsDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
PropDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
||||||
PropsDataLogical led(u8"led");
|
PropDataLogical led(u8"led");
|
||||||
|
|
||||||
void clignote(); // forward
|
void clignote(); // forward
|
||||||
PropsAction clignoteAction = PropsAction(1000, clignote);
|
PropAction clignoteAction = PropAction(1000, clignote);
|
||||||
```
|
```
|
||||||
Create MAC address (which must be unique, it's the hardware ID in the netwprk).
|
Create MAC address (which must be unique, it's the hardware ID in the netwprk).
|
||||||
|
|
||||||
Create *EthernetProps* instance with MQTT parameters, then create *PropsData* instances and *PropsActions*.
|
Create *EthernetProp* instance with MQTT parameters, then create *PropData* instances and *PropsActions*.
|
||||||
|
|
||||||
The *Ethernet* instance is created by `#include <Ethernet.h>`.
|
The *Ethernet* instance is created by `#include <Ethernet.h>`.
|
||||||
|
|
||||||
### Defining a *WifiProps*
|
### Defining a *WifiProp*
|
||||||
```csharp
|
```csharp
|
||||||
#include "ArduinoProps.h"
|
#include "ArduinoProps.h"
|
||||||
|
|
||||||
@@ -98,69 +98,69 @@ const char *passphrase = "";
|
|||||||
// prpos inbox/outbox syntax Room/[escape room name]/Props/[propsname]/inbox|outbox
|
// prpos inbox/outbox syntax Room/[escape room name]/Props/[propsname]/inbox|outbox
|
||||||
// https://live-escape.net/go/room
|
// https://live-escape.net/go/room
|
||||||
|
|
||||||
WifiProps props(u8"Arduino Contrôleur", // as MQTT client id, should be unique per client for given broker
|
WifiProp prop(u8"Arduino Contrôleur", // as MQTT client id, should be unique per client for given broker
|
||||||
u8"Room/Demoniak/Props/Arduino Contrôleur/inbox",
|
u8"Room/Demoniak/Props/Arduino Contrôleur/inbox",
|
||||||
u8"Room/Demoniak/Props/Arduino Contrôleur/outbox",
|
u8"Room/Demoniak/Props/Arduino Contrôleur/outbox",
|
||||||
"192.168.1.42", // your MQTT server IP address
|
"192.168.1.42", // your MQTT server IP address
|
||||||
1883); // your MQTT server port;
|
1883); // your MQTT server port;
|
||||||
|
|
||||||
PropsDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
PropDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
||||||
PropsDataLogical led(u8"led");
|
PropDataLogical led(u8"led");
|
||||||
|
|
||||||
void clignote(); // forward
|
void clignote(); // forward
|
||||||
PropsAction clignoteAction = PropsAction(1000, clignote);
|
PropAction clignoteAction = PropAction(1000, clignote);
|
||||||
```
|
```
|
||||||
The *AduinoProps* library uses **<a href="https://github.com/arduino-libraries/WiFiNINA" target="_blank">WiFiNINA</a>** WiFi library for **Arduino Uno WiFi Rev 2**, **Arduino NANO 33 IoT**, **Arduino MKR WiFi 1010** and **Arduino MKR VIDOR 4000**.
|
The *AduinoProps* library uses **<a href="https://github.com/arduino-libraries/WiFiNINA" target="_blank">WiFiNINA</a>** WiFi library for **Arduino Uno WiFi Rev 2**, **Arduino NANO 33 IoT**, **Arduino MKR WiFi 1010** and **Arduino MKR VIDOR 4000**.
|
||||||
|
|
||||||
Please update the WiFiNINA firmware: [WiFiNINA firmware update](WifiNinaFirmware.md).
|
Please update the WiFiNINA firmware: [WiFiNINA firmware update](WifiNinaFirmware.md).
|
||||||
|
|
||||||
Create *WifiProps* instance with MQTT parameters, then create *PropsData* instances and *PropsActions*.
|
Create *WifiProp* instance with MQTT parameters, then create *PropData* instances and *PropsActions*.
|
||||||
|
|
||||||
#### MQTT topics
|
#### MQTT topics
|
||||||
The props listens to the *inbox* topic for command messages and send data and messages into the *outbox* topic.
|
The prop listens to the *inbox* topic for command messages and send data and messages into the *outbox* topic.
|
||||||
|
|
||||||
If you're running Live Escape Room 2.0 control software, you have to respect *inbox*/*outbox* syntax:
|
If you're running Live Escape Room 2.0 control software, you have to respect *inbox*/*outbox* syntax:
|
||||||
|
|
||||||
Room 2.0 *inbox* topic:
|
Room 2.0 *inbox* topic:
|
||||||
```csharp
|
```csharp
|
||||||
format: Room/[escape room name]/Props/[props name]/inbox
|
format: Room/[escape room name]/Props/[prop name]/inbox
|
||||||
example: u8"Room/Demoniak/Props/Arduino Contrôleur/inbox"
|
example: u8"Room/Demoniak/Props/Arduino Contrôleur/inbox"
|
||||||
```
|
```
|
||||||
Room 2.0 *outbox* topic:
|
Room 2.0 *outbox* topic:
|
||||||
```csharp
|
```csharp
|
||||||
format: Room/[escape room name]/Props/[props name]/outbox
|
format: Room/[escape room name]/Props/[prop name]/outbox
|
||||||
example: u8"Room/Demoniak/Props/Arduino Contrôleur/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 prop**.
|
||||||
|
|
||||||
#### *PropsData* instances
|
#### *PropData* instances
|
||||||
*PropsData* provides a facility to monitor data sent into MQTT outbox.
|
*PropData* provides a facility to monitor data sent into MQTT outbox.
|
||||||
|
|
||||||
See [PropsData.md](PropsData.md) for *PropsData* reference.
|
See [PropData.md](PropData.md) for *PropData* reference.
|
||||||
|
|
||||||
#### *PropsAction* instances
|
#### *PropAction* instances
|
||||||
To maintain a non-blocking asynchronous behavior of your props, use *PropsAction* objects to trigger action periodically.
|
To maintain a non-blocking asynchronous behavior of your prop, use *PropAction* objects to trigger action periodically.
|
||||||
|
|
||||||
Reading I/O and simple computing (arithmetics) can be done at every sketch loop but long computing have to run periodically.
|
Reading I/O and simple computing (arithmetics) can be done at every sketch loop but long computing have to run periodically.
|
||||||
|
|
||||||
For example, to blink a led, don't block the skecth with a `delay(1000)` call to switch the output: instead, ***check if 1 second is elapsed to switch the output***.
|
For example, to blink a led, don't block the skecth with a `delay(1000)` call to switch the output: instead, ***check if 1 second is elapsed to switch the output***.
|
||||||
|
|
||||||
See [PropsAction.md](PropsData.md) for *PropsAction* reference.
|
See [PropAction.md](PropData.md) for *PropAction* reference.
|
||||||
|
|
||||||
|
|
||||||
## 2. Setup the *Props*
|
## 2. Setup the *Prop*
|
||||||
`InboxMessage::run` is the callback executed when a message is received in the MQTT inbox.
|
`InboxMessage::run` is the callback executed when a message is received in the MQTT inbox.
|
||||||
```csharp
|
```csharp
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
// CODE TO BEGIN THE INTERNET CONNECTION
|
// CODE TO BEGIN THE INTERNET CONNECTION
|
||||||
... see below the different code for BridgeProps, EthenetProps and WifiProps
|
... see below the different code for BridgeProp, EthenetProps and WifiProp
|
||||||
|
|
||||||
// SAME CODE FOR ALL PROPS
|
// SAME CODE FOR ALL PROPS
|
||||||
props.addData(&clignoter);
|
prop.addData(&clignoter);
|
||||||
props.addData(&led);
|
prop.addData(&led);
|
||||||
|
|
||||||
props.begin(InboxMessage::run);
|
prop.begin(InboxMessage::run);
|
||||||
|
|
||||||
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output
|
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output
|
||||||
|
|
||||||
@@ -169,20 +169,20 @@ void setup()
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
*BridgeProps*, *EthenetProps* and *WifiProps* has the exactly same setup:
|
*BridgeProp*, *EthenetProps* and *WifiProp* has the exactly same setup:
|
||||||
|
|
||||||
- add *PropsData* references to the props
|
- add *PropData* references to the prop
|
||||||
- call `props.begin(InboxMessage::run)`
|
- call `prop.begin(InboxMessage::run)`
|
||||||
|
|
||||||
The setup code is slighlty different to start the network client (bridge, ethernet of wifi):
|
The setup code is slighlty different to start the network client (bridge, ethernet of wifi):
|
||||||
```csharp
|
```csharp
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
#if defined(BRIDGEPROPS_H)
|
#if defined(BRIDGEPROP_H)
|
||||||
Bridge.begin();
|
Bridge.begin();
|
||||||
updateBrokerAdressFromFile("/root/broker", &props); // if you're running our Escape Room control software (Room 2.0)
|
updateBrokerAdressFromFile("/root/broker", &prop); // if you're running our Escape Room control software (Room 2.0)
|
||||||
|
|
||||||
#elif defined(ETHERNETPROPS_H)
|
#elif defined(ETHERNETPROP_H)
|
||||||
// can do more static IP configuration
|
// can do more static IP configuration
|
||||||
//Ethernet.setSubnetMask(IPAddress());
|
//Ethernet.setSubnetMask(IPAddress());
|
||||||
//Ethernet.setGatewayIP(IPAddress());
|
//Ethernet.setGatewayIP(IPAddress());
|
||||||
@@ -201,7 +201,7 @@ void setup()
|
|||||||
}
|
}
|
||||||
delay(1500); // time for shield stuff
|
delay(1500); // time for shield stuff
|
||||||
|
|
||||||
#elif defined(WIFIPROPS_H)
|
#elif defined(WIFIPROP_H)
|
||||||
// can do more static IP configuration
|
// can do more static IP configuration
|
||||||
//WiFi.config(IPAddress(), IPAddress(), IPAddress());
|
//WiFi.config(IPAddress(), IPAddress(), IPAddress());
|
||||||
//WiFi.config(IPAddress(), IPAddress());
|
//WiFi.config(IPAddress(), IPAddress());
|
||||||
@@ -221,11 +221,11 @@ void setup()
|
|||||||
### Change timings
|
### Change timings
|
||||||
Default timings are:
|
Default timings are:
|
||||||
* check data changes every 400 milliseconds
|
* check data changes every 400 milliseconds
|
||||||
* *Props* remains silent for up to 30 seconds
|
* *Prop* remains silent for up to 30 seconds
|
||||||
|
|
||||||
Timings can be changed anywhere in the code with `resetIntervals()`:
|
Timings can be changed anywhere in the code with `resetIntervals()`:
|
||||||
```csharp
|
```csharp
|
||||||
props.resetIntervals(250, 15); // check data changes every 250 milliseconds, silent up to 15 seconds
|
prop.resetIntervals(250, 15); // check data changes every 250 milliseconds, silent up to 15 seconds
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -233,7 +233,7 @@ Timings can be changed anywhere in the code with `resetIntervals()`:
|
|||||||
```csharp
|
```csharp
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
props.loop();
|
prop.loop();
|
||||||
|
|
||||||
led.setValue(digitalRead(LED_BUILTIN)); // read I/O
|
led.setValue(digitalRead(LED_BUILTIN)); // read I/O
|
||||||
|
|
||||||
@@ -243,7 +243,7 @@ void loop()
|
|||||||
```
|
```
|
||||||
Couldn't be more simple!
|
Couldn't be more simple!
|
||||||
|
|
||||||
Just call `props.loop()` when entering the sketch `loop()`, it will maintain MQTT broker connection and run callback when receiving MQTT messages.
|
Just call `prop.loop()` when entering the sketch `loop()`, it will maintain MQTT broker connection and run callback when receiving MQTT messages.
|
||||||
|
|
||||||
|
|
||||||
## 4. Implement `InboxMessage::run()` callback
|
## 4. Implement `InboxMessage::run()` callback
|
||||||
@@ -255,40 +255,40 @@ void InboxMessage::run(String a) {
|
|||||||
|
|
||||||
if (a == u8"app:startup")
|
if (a == u8"app:startup")
|
||||||
{
|
{
|
||||||
props.sendAllData();
|
prop.sendAllData();
|
||||||
props.sendDone(a);
|
prop.sendDone(a);
|
||||||
}
|
}
|
||||||
else if (a == "clignoter:1")
|
else if (a == "clignoter:1")
|
||||||
{
|
{
|
||||||
clignoter.setValue(true);
|
clignoter.setValue(true);
|
||||||
|
|
||||||
props.sendAllData(); // all data change, we don't have to be selctive then
|
prop.sendAllData(); // all data change, we don't have to be selctive then
|
||||||
props.sendDone(a); // acknowledge props command action
|
prop.sendDone(a); // acknowledge prop command action
|
||||||
}
|
}
|
||||||
else if (a == "clignoter:0")
|
else if (a == "clignoter:0")
|
||||||
{
|
{
|
||||||
clignoter.setValue(false);
|
clignoter.setValue(false);
|
||||||
|
|
||||||
props.sendAllData(); // all data change, we don't have to be selctive then
|
prop.sendAllData(); // all data change, we don't have to be selctive then
|
||||||
props.sendDone(a); // acknowledge props command action
|
prop.sendDone(a); // acknowledge prop command action
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// acknowledge omition of the props command
|
// acknowledge omition of the prop command
|
||||||
props.sendOmit(a);
|
prop.sendOmit(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## 5. Update broker address from SSH (*BridgeProps*)
|
## 5. Update broker address from SSH (*BridgeProp*)
|
||||||
Room 2.0 use a SSH command to change remotely the broker IP address (in /root/broker file) and to relaunch to sketch:
|
Room 2.0 use a SSH command to change remotely the broker IP address (in /root/broker file) and to relaunch to sketch:
|
||||||
```bash
|
```bash
|
||||||
ssh 'echo 192.168.1.14> /root/broker && reset-mcu'
|
ssh 'echo 192.168.1.14> /root/broker && reset-mcu'
|
||||||
```
|
```
|
||||||
On the *BridgeProps* you can read the broker IP address from Linino filesystem with this code:
|
On the *BridgeProp* you can read the broker IP address from Linino filesystem with this code:
|
||||||
```csharp
|
```csharp
|
||||||
void updateBrokerAdressFromFile(const char* broker_file, BridgeProps* props)
|
void updateBrokerAdressFromFile(const char* broker_file, BridgeProp* prop)
|
||||||
{
|
{
|
||||||
// broker IP address is stored in Linino file systems and updated with ssh command by Room 2.0
|
// broker IP address is stored in Linino file systems and updated with ssh command by Room 2.0
|
||||||
IPAddress ip;
|
IPAddress ip;
|
||||||
@@ -304,7 +304,7 @@ void updateBrokerAdressFromFile(const char* broker_file, BridgeProps* props)
|
|||||||
}
|
}
|
||||||
b.trim();
|
b.trim();
|
||||||
|
|
||||||
if (ip.fromString(b.c_str())) props->setBrokerIpAddress(ip);
|
if (ip.fromString(b.c_str())) prop->setBrokerIpAddress(ip);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -312,12 +312,12 @@ void updateBrokerAdressFromFile(const char* broker_file, BridgeProps* props)
|
|||||||
## 6. Examples
|
## 6. Examples
|
||||||
The library comes with a number of example sketches. See **File > Examples > ArduinoProps** within the Arduino IDE application.
|
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 prop:
|
||||||
|
|
||||||
1. **BlinkOnBridgeProps**: the Blink example on a Yun props with *ArduinoProps library*
|
1. **BlinkOnBridgeProps**: the Blink example on a Yun prop with *ArduinoProps library*
|
||||||
2. **BlinkOnEthernetProps**: the Blink example on an Ethernet props with *ArduinoProps library*
|
2. **BlinkOnEthernetProps**: the Blink example on an Ethernet prop with *ArduinoProps library*
|
||||||
3. **BlinkOnWifiProps**: the Blink example on a Wifi props with *ArduinoProps library*
|
3. **BlinkOnWifiProps**: the Blink example on a Wifi prop with *ArduinoProps library*
|
||||||
4. **BlinkOnBridgePubSub**: the Blink example on props using *PubSubClient* directly
|
4. **BlinkOnBridgePubSub**: the Blink example on prop using *PubSubClient* directly
|
||||||
|
|
||||||
|
|
||||||
## 7. Compatible hardware
|
## 7. Compatible hardware
|
||||||
@@ -331,9 +331,9 @@ See [EXAMPLES.md](../EXAMPLES.md) for an adaptation of the Blink example (https:
|
|||||||
- Arduino Ethernet
|
- Arduino Ethernet
|
||||||
- Arduino Ethernet Shield
|
- Arduino Ethernet Shield
|
||||||
|
|
||||||
For WiFi props, please update the WiFiNINA firmware: [WiFiNINA firmware update](WifiNinaFirmware.md).
|
For WiFi prop, please update the WiFiNINA firmware: [WiFiNINA firmware update](WifiNinaFirmware.md).
|
||||||
|
|
||||||
To use other WiFi hardware compatible with any *<a href="https://github.com/knolleary/pubsubclient" target="_blank">Nick O'Leary PubSubClient</a>* library you have to fork `WifiProps.h` and `WifiProps.cpp` and to replace `WiFiNINA.h` whih appropriate WiFi library (`ESP8266WiFi.h` for example):
|
To use other WiFi hardware compatible with any *<a href="https://github.com/knolleary/pubsubclient" target="_blank">Nick O'Leary PubSubClient</a>* library you have to fork `WifiProp.h` and `WifiProp.cpp` and to replace `WiFiNINA.h` whih appropriate WiFi library (`ESP8266WiFi.h` for example):
|
||||||
- Arduino WiFi Shield
|
- Arduino WiFi Shield
|
||||||
- Sparkfun WiFly Shield – [library](https://github.com/dpslwk/WiFly)
|
- Sparkfun WiFly Shield – [library](https://github.com/dpslwk/WiFly)
|
||||||
- TI CC3000 WiFi - [library](https://github.com/sparkfun/SFE_CC3000_Library)
|
- TI CC3000 WiFi - [library](https://github.com/sparkfun/SFE_CC3000_Library)
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
# *PropsAction* class reference
|
# *PropAction* class reference
|
||||||
|
|
||||||
*PropsAction* brings asynchronous-like behavior to sketch `loop()`.
|
*PropAction* brings asynchronous-like behavior to sketch `loop()`.
|
||||||
|
|
||||||
|
|
||||||
## Constructors
|
## Constructors
|
||||||
* `PropsAction()`
|
* `PropAction()`
|
||||||
* `PropsAction(unsigned long interval, void (*function)())`
|
* `PropAction(unsigned long interval, void (*function)())`
|
||||||
|
|
||||||
`function` is the callback executed at every `interval` milliseconds.
|
`function` is the callback executed at every `interval` milliseconds.
|
||||||
|
|
||||||
@@ -30,9 +30,9 @@ void clignote()
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Create a *PropsAction* instance
|
### Create a *PropAction* instance
|
||||||
```csharp
|
```csharp
|
||||||
PropsAction clignoteAction = PropsAction(1000, clignote); // interval every 1000 milliseconds
|
PropAction clignoteAction = PropAction(1000, clignote); // interval every 1000 milliseconds
|
||||||
```
|
```
|
||||||
|
|
||||||
### Call the instance `check()` method ine the sketch `loop()`
|
### Call the instance `check()` method ine the sketch `loop()`
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
# *PropData* reference
|
||||||
|
|
||||||
|
*PropData* tracks data changes and provides escape room 2.0 propocol `DATA` ready string format.
|
||||||
|
|
||||||
|
See **4. Application protocol for escape room 2.0 prop** in [README.md](../README.md).
|
||||||
|
|
||||||
|
*PropData* is an interface (base class) implemented by 4 classes:
|
||||||
|
* ***PropDataDecimal***
|
||||||
|
* ***PropDataInteger***
|
||||||
|
* ***PropDataLogical***
|
||||||
|
* ***PropDataText***
|
||||||
|
|
||||||
|
## Constructors
|
||||||
|
* `PropDataDecimal(const char *, uint8_t digits = 2, double precision = 0.1, double initial = 0)`
|
||||||
|
* `PropDataInteger(const char *, double precision = 0.1, long initial = 0)`
|
||||||
|
* `PropDataLogical(const char *, const char *trueval = NULL, const char *falseval = NULL, bool initial = false)`
|
||||||
|
* `PropDataText(const char *)`
|
||||||
|
|
||||||
|
By default for *PropDataLogical*, `trueval` is `"1"` band `falseval` is `"0"`.
|
||||||
|
|
||||||
|
For *PropDataDecimal*, `digits` is the number of decimal digits in the display string.
|
||||||
|
|
||||||
|
For *PropDataDecimal* and *PropDataInteger*, `precision` is the percentage threshold for deciding whether a change has occurred or not.
|
||||||
|
|
||||||
|
## Interface
|
||||||
|
* `String fetch()`
|
||||||
|
* `String fetchChange()`
|
||||||
|
|
||||||
|
*fetch()* always returns the `"var=value "` string ready to be sent in a `DATA` protocol message and update the `_previous` value.
|
||||||
|
|
||||||
|
*fetchChange()* checks whether a change has occurred or not. If a change occured, returns the `"var=value "` string ready to be sent in a `DATA` protocol message and update the `_previous` value. If no change occured, returns and empty string.
|
||||||
|
|
||||||
|
## Accessors and Mutators
|
||||||
|
* `void setValue(const double|long|bool|String)`
|
||||||
|
* `double|long|bool|String value() const`
|
||||||
|
|
||||||
|
Accessors and Mutators are typed according to *PropData* type.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### Create a *PropData* instance
|
||||||
|
```csharp
|
||||||
|
PropDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Add the *PropData* instance to managed data of the *Props*
|
||||||
|
```csharp
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
...
|
||||||
|
|
||||||
|
Props::addManagedLogicalData(&clignoter);
|
||||||
|
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Use the *PropData* instance anywhere
|
||||||
|
```csharp
|
||||||
|
clignoter.setValue(true);
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
if (clignoter.value()) {
|
||||||
|
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
|
||||||
|
led.setValue(digitalRead(LED_BUILTIN));
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Author
|
||||||
|
|
||||||
|
**Marie FAURE** (Oct 18th, 2019)
|
||||||
|
* company: FAURE SYSTEMS SAS
|
||||||
|
* mail: *dev at faure dot systems*
|
||||||
|
* github: <a href="https://github.com/fauresystems?tab=repositories" target="_blank">fauresystems</a>
|
||||||
|
* web: <a href="https://faure.systems/" target="_blank">Faure Systems</a>
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
# *PropsData* reference
|
|
||||||
|
|
||||||
*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).
|
|
||||||
|
|
||||||
*PropsData* is an interface (base class) implemented by 4 classes:
|
|
||||||
* ***PropsDataDecimal***
|
|
||||||
* ***PropsDataInteger***
|
|
||||||
* ***PropsDataLogical***
|
|
||||||
* ***PropsDataText***
|
|
||||||
|
|
||||||
## Constructors
|
|
||||||
* `PropsDataDecimal(const char *, uint8_t digits = 2, double precision = 0.1, double initial = 0)`
|
|
||||||
* `PropsDataInteger(const char *, double precision = 0.1, long initial = 0)`
|
|
||||||
* `PropsDataLogical(const char *, const char *trueval = NULL, const char *falseval = NULL, bool initial = false)`
|
|
||||||
* `PropsDataText(const char *)`
|
|
||||||
|
|
||||||
By default for *PropsDataLogical*, `trueval` is `"1"` band `falseval` is `"0"`.
|
|
||||||
|
|
||||||
For *PropsDataDecimal*, `digits` is the number of decimal digits in the display string.
|
|
||||||
|
|
||||||
For *PropsDataDecimal* and *PropsDataInteger*, `precision` is the percentage threshold for deciding whether a change has occurred or not.
|
|
||||||
|
|
||||||
## Interface
|
|
||||||
* `String fetch()`
|
|
||||||
* `String fetchChange()`
|
|
||||||
|
|
||||||
*fetch()* always returns the `"var=value "` string ready to be sent in a `DATA` protocol message and update the `_previous` value.
|
|
||||||
|
|
||||||
*fetchChange()* checks whether a change has occurred or not. If a change occured, returns the `"var=value "` string ready to be sent in a `DATA` protocol message and update the `_previous` value. If no change occured, returns and empty string.
|
|
||||||
|
|
||||||
## Accessors and Mutators
|
|
||||||
* `void setValue(const double|long|bool|String)`
|
|
||||||
* `double|long|bool|String value() const`
|
|
||||||
|
|
||||||
Accessors and Mutators are typed according to *PropsData* type.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
### Create a *PropsData* instance
|
|
||||||
```csharp
|
|
||||||
PropsDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
|
||||||
```
|
|
||||||
|
|
||||||
### Add the *PropsData* instance to managed data of the *Props*
|
|
||||||
```csharp
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
...
|
|
||||||
|
|
||||||
Props::addManagedLogicalData(&clignoter);
|
|
||||||
|
|
||||||
...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Use the *PropsData* instance anywhere
|
|
||||||
```csharp
|
|
||||||
clignoter.setValue(true);
|
|
||||||
|
|
||||||
...
|
|
||||||
|
|
||||||
if (clignoter.value()) {
|
|
||||||
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
|
|
||||||
led.setValue(digitalRead(LED_BUILTIN));
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Author
|
|
||||||
|
|
||||||
**Marie FAURE** (Oct 18th, 2019)
|
|
||||||
* company: FAURE SYSTEMS SAS
|
|
||||||
* mail: *dev at faure dot systems*
|
|
||||||
* github: <a href="https://github.com/fauresystems?tab=repositories" target="_blank">fauresystems</a>
|
|
||||||
* web: <a href="https://faure.systems/" target="_blank">Faure Systems</a>
|
|
||||||
+9
-9
@@ -7,15 +7,15 @@
|
|||||||
#######################################
|
#######################################
|
||||||
|
|
||||||
Props KEYWORD1
|
Props KEYWORD1
|
||||||
BridgeProps KEYWORD1
|
BridgeProp KEYWORD1
|
||||||
EthernetProps KEYWORD1
|
EthernetProp KEYWORD1
|
||||||
WifiProps KEYWORD1
|
WifiProp KEYWORD1
|
||||||
PropsAction KEYWORD1
|
PropAction KEYWORD1
|
||||||
PropsData KEYWORD1
|
PropData KEYWORD1
|
||||||
PropsDataDecimal KEYWORD1
|
PropDataDecimal KEYWORD1
|
||||||
PropsDataInteger KEYWORD1
|
PropDataInteger KEYWORD1
|
||||||
PropsDataLogical KEYWORD1
|
PropDataLogical KEYWORD1
|
||||||
PropsDataText KEYWORD1
|
PropDataText KEYWORD1
|
||||||
PropsCallback KEYWORD1
|
PropsCallback KEYWORD1
|
||||||
PropsMessageReceived KEYWORD1
|
PropsMessageReceived KEYWORD1
|
||||||
InboxMessage KEYWORD1
|
InboxMessage KEYWORD1
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
Editor: https://github.com/fauresystems
|
Editor: https://github.com/fauresystems
|
||||||
License: MIT License (c) Marie Faure <dev at faure dot systems>
|
License: MIT License (c) Marie Faure <dev at faure dot systems>
|
||||||
|
|
||||||
Library to make props sketch for Escape Room 2.0 (connected props).
|
Library to make prop sketch for Escape Room 2.0 (connected prop).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ArduinoProps.h"
|
#include "ArduinoProps.h"
|
||||||
|
|||||||
+6
-6
@@ -5,7 +5,7 @@
|
|||||||
Editor: https://github.com/fauresystems
|
Editor: https://github.com/fauresystems
|
||||||
License: MIT License (c) Marie Faure <dev at faure dot systems>
|
License: MIT License (c) Marie Faure <dev at faure dot systems>
|
||||||
|
|
||||||
Library to make props sketch for Escape Room 2.0 (connected props).
|
Library to make prop sketch for Escape Room 2.0 (connected prop).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _ArduinoProps_h
|
#ifndef _ArduinoProps_h
|
||||||
@@ -17,10 +17,10 @@
|
|||||||
#include "WProgram.h"
|
#include "WProgram.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "BridgeProps.h"
|
#include "BridgeProp.h"
|
||||||
#include "EthernetProps.h"
|
#include "EthernetProp.h"
|
||||||
#include "WifiProps.h"
|
#include "WifiProp.h"
|
||||||
#include "PropsAction.h"
|
#include "PropAction.h"
|
||||||
#include "PropsData.h"
|
#include "PropData.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Name: BridgeProps.cpp
|
Name: BridgeProp.cpp
|
||||||
Created: 29/10/2019 09:20:31
|
Created: 29/10/2019 09:20:31
|
||||||
Author: Marie Faure <dev at faure dot systems>
|
Author: Marie Faure <dev at faure dot systems>
|
||||||
Editor: https://github.com/fauresystems
|
Editor: https://github.com/fauresystems
|
||||||
@@ -8,20 +8,20 @@
|
|||||||
Class Props for Arduino Yun and Dragino Yun shield.
|
Class Props for Arduino Yun and Dragino Yun shield.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "BridgeProps.h"
|
#include "BridgeProp.h"
|
||||||
|
|
||||||
BridgeProps::BridgeProps(const char* client_id, const char* in_box, const char* out_box, const char* broker, const int port)
|
BridgeProp::BridgeProp(const char* client_id, const char* in_box, const char* out_box, const char* broker, const int port)
|
||||||
: Props(client_id, in_box, out_box, broker, port)
|
: Props(client_id, in_box, out_box, broker, port)
|
||||||
{
|
{
|
||||||
_client.setClient(_bridgeClient);
|
_client.setClient(_bridgeClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BridgeProps::begin(void(*on_message)(String))
|
void BridgeProp::begin(void(*on_message)(String))
|
||||||
{
|
{
|
||||||
if (on_message) onInboxMessageReceived = on_message;
|
if (on_message) onInboxMessageReceived = on_message;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BridgeProps::setBrokerIpAddress(IPAddress ip, uint16_t port)
|
void BridgeProp::setBrokerIpAddress(IPAddress ip, uint16_t port)
|
||||||
{
|
{
|
||||||
_brokerIpAddress = ip;
|
_brokerIpAddress = ip;
|
||||||
_client.setServer(_brokerIpAddress, port);
|
_client.setServer(_brokerIpAddress, port);
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Name: BridgeProps.h
|
Name: BridgeProp.h
|
||||||
Created: 29/10/2019 09:20:31
|
Created: 29/10/2019 09:20:31
|
||||||
Author: Marie Faure <dev at faure dot systems>
|
Author: Marie Faure <dev at faure dot systems>
|
||||||
Editor: https://github.com/fauresystems
|
Editor: https://github.com/fauresystems
|
||||||
@@ -7,17 +7,17 @@
|
|||||||
|
|
||||||
Class Props for Arduino Yun and Dragino Yun shield.
|
Class Props for Arduino Yun and Dragino Yun shield.
|
||||||
*/
|
*/
|
||||||
#ifndef BRIDGEPROPS_H
|
#ifndef BRIDGEPROP_H
|
||||||
#define BRIDGEPROPS_H
|
#define BRIDGEPROP_H
|
||||||
|
|
||||||
#include <BridgeClient.h>
|
#include <BridgeClient.h>
|
||||||
#include <IPAddress.h>
|
#include <IPAddress.h>
|
||||||
#include "Props.h"
|
#include "Prop.h"
|
||||||
|
|
||||||
class BridgeProps : public Props
|
class BridgeProp : public Props
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BridgeProps(const char*, const char*, const char*, const char*, const int);
|
BridgeProp(const char*, const char*, const char*, const char*, const int);
|
||||||
void begin(void(*)(String) = NULL);
|
void begin(void(*)(String) = NULL);
|
||||||
void setBrokerIpAddress(IPAddress, uint16_t port = 1883);
|
void setBrokerIpAddress(IPAddress, uint16_t port = 1883);
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Name: EthernetProps.cpp
|
Name: EthernetProp.cpp
|
||||||
Created: 29/10/2019 09:20:31
|
Created: 29/10/2019 09:20:31
|
||||||
Author: Marie Faure <dev at faure dot systems>
|
Author: Marie Faure <dev at faure dot systems>
|
||||||
Editor: https://github.com/fauresystems
|
Editor: https://github.com/fauresystems
|
||||||
@@ -8,15 +8,15 @@
|
|||||||
Class Props for Arduino with Ethernet shield.
|
Class Props for Arduino with Ethernet shield.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "EthernetProps.h"
|
#include "EthernetProp.h"
|
||||||
|
|
||||||
EthernetProps::EthernetProps(const char* client_id, const char* in_box, const char* out_box, const char* broker, const int port)
|
EthernetProp::EthernetProp(const char* client_id, const char* in_box, const char* out_box, const char* broker, const int port)
|
||||||
: Props(client_id, in_box, out_box, broker, port)
|
: Props(client_id, in_box, out_box, broker, port)
|
||||||
{
|
{
|
||||||
_client.setClient(_ethernetClient);
|
_client.setClient(_ethernetClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EthernetProps::begin(void(*on_message)(String))
|
void EthernetProp::begin(void(*on_message)(String))
|
||||||
{
|
{
|
||||||
if (on_message) onInboxMessageReceived = on_message;
|
if (on_message) onInboxMessageReceived = on_message;
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Name: EthernetProps.h
|
Name: EthernetProp.h
|
||||||
Created: 29/10/2019 09:20:31
|
Created: 29/10/2019 09:20:31
|
||||||
Author: Marie Faure <dev at faure dot systems>
|
Author: Marie Faure <dev at faure dot systems>
|
||||||
Editor: https://github.com/fauresystems
|
Editor: https://github.com/fauresystems
|
||||||
@@ -7,19 +7,19 @@
|
|||||||
|
|
||||||
Class Props for Arduino with Ethernet shield.
|
Class Props for Arduino with Ethernet shield.
|
||||||
*/
|
*/
|
||||||
#ifndef ETHERNETPROPS_H
|
#ifndef ETHERNETPROP_H
|
||||||
#define ETHERNETPROPS_H
|
#define ETHERNETPROP_H
|
||||||
|
|
||||||
|
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <Ethernet.h>
|
#include <Ethernet.h>
|
||||||
#include <EthernetClient.h>
|
#include <EthernetClient.h>
|
||||||
#include "Props.h"
|
#include "Prop.h"
|
||||||
|
|
||||||
class EthernetProps : public Props
|
class EthernetProp : public Props
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
EthernetProps(const char*, const char*, const char*, const char*, const int);
|
EthernetProp(const char*, const char*, const char*, const char*, const int);
|
||||||
void begin(void(*)(String) = NULL);
|
void begin(void(*)(String) = NULL);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -5,10 +5,10 @@
|
|||||||
Editor: https://github.com/fauresystems
|
Editor: https://github.com/fauresystems
|
||||||
License: MIT License (c) Marie Faure <dev at faure dot systems>
|
License: MIT License (c) Marie Faure <dev at faure dot systems>
|
||||||
|
|
||||||
Base class to make props sketch for Escape Room 2.0 (connected).
|
Base class to make prop sketch for Escape Room 2.0 (connected).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Props.h"
|
#include "Prop.h"
|
||||||
#include <Process.h>
|
#include <Process.h>
|
||||||
#if defined(__AVR__)
|
#if defined(__AVR__)
|
||||||
#include <avr/wdt.h>
|
#include <avr/wdt.h>
|
||||||
@@ -58,7 +58,7 @@ Props::Props(const char* client_id, const char* in_box, const char* out_box, con
|
|||||||
_sendDataAction.reset(400); // check data changes every 400 milliseconds
|
_sendDataAction.reset(400); // check data changes every 400 milliseconds
|
||||||
}
|
}
|
||||||
|
|
||||||
void Props::addData(PropsData* d)
|
void Props::addData(PropData* d)
|
||||||
{
|
{
|
||||||
_dataTable.Add(d);
|
_dataTable.Add(d);
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Name: Props.h
|
Name: Prop.h
|
||||||
Created: 29/10/2019 09:20:31
|
Created: 29/10/2019 09:20:31
|
||||||
Author: Marie Faure <dev at faure dot systems>
|
Author: Marie Faure <dev at faure dot systems>
|
||||||
Editor: https://github.com/fauresystems
|
Editor: https://github.com/fauresystems
|
||||||
License: MIT License (c) Marie Faure <dev at faure dot systems>
|
License: MIT License (c) Marie Faure <dev at faure dot systems>
|
||||||
|
|
||||||
Base class to make props sketch for Escape Room 2.0 (connected).
|
Base class to make prop sketch for Escape Room 2.0 (connected).
|
||||||
*/
|
*/
|
||||||
#ifndef PROPS_H
|
#ifndef PROP_H
|
||||||
#define PROPS_H
|
#define PROP_H
|
||||||
|
|
||||||
#if defined(ARDUINO) && ARDUINO >= 100
|
#if defined(ARDUINO) && ARDUINO >= 100
|
||||||
#include "arduino.h"
|
#include "arduino.h"
|
||||||
@@ -19,8 +19,8 @@
|
|||||||
#include <BridgeClient.h>
|
#include <BridgeClient.h>
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
#include <ListLib.h>
|
#include <ListLib.h>
|
||||||
#include "PropsAction.h"
|
#include "PropAction.h"
|
||||||
#include "PropsData.h"
|
#include "PropData.h"
|
||||||
|
|
||||||
#ifndef MQTT_MAX_PACKET_SIZE
|
#ifndef MQTT_MAX_PACKET_SIZE
|
||||||
#define MQTT_MAX_PACKET_SIZE 128 // Bridge tranfer stuff (see PubSubClient)
|
#define MQTT_MAX_PACKET_SIZE 128 // Bridge tranfer stuff (see PubSubClient)
|
||||||
@@ -53,7 +53,7 @@ class Props
|
|||||||
public:
|
public:
|
||||||
Props(const char*, const char*, const char*, const char*, const int=1883);
|
Props(const char*, const char*, const char*, const char*, const int=1883);
|
||||||
virtual void begin(void(*)(String) = NULL) = 0;
|
virtual void begin(void(*)(String) = NULL) = 0;
|
||||||
void addData(PropsData*);
|
void addData(PropData*);
|
||||||
void loop();
|
void loop();
|
||||||
void resetIntervals(const int changes, const int silent);
|
void resetIntervals(const int changes, const int silent);
|
||||||
void resetMcu();
|
void resetMcu();
|
||||||
@@ -86,8 +86,8 @@ class Props
|
|||||||
uint8_t _maximumSilentPeriod;
|
uint8_t _maximumSilentPeriod;
|
||||||
unsigned long _nextReconAttempt;
|
unsigned long _nextReconAttempt;
|
||||||
uint8_t _payloadMax;
|
uint8_t _payloadMax;
|
||||||
PropsAction _sendDataAction;
|
PropAction _sendDataAction;
|
||||||
List<PropsData*> _dataTable;
|
List<PropData*> _dataTable;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Name: PropsAction.h
|
Name: PropAction.h
|
||||||
Created: 29/10/2019 09:20:31
|
Created: 29/10/2019 09:20:31
|
||||||
Author: Marie Faure <dev at faure dot systems>
|
Author: Marie Faure <dev at faure dot systems>
|
||||||
Editor: https://github.com/fauresystems
|
Editor: https://github.com/fauresystems
|
||||||
@@ -8,9 +8,9 @@
|
|||||||
Provide an easy way of triggering functions at a set _interval.
|
Provide an easy way of triggering functions at a set _interval.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "PropsAction.h"
|
#include "PropAction.h"
|
||||||
|
|
||||||
PropsAction::PropsAction()
|
PropAction::PropAction()
|
||||||
{
|
{
|
||||||
_active = true;
|
_active = true;
|
||||||
_previous = 0;
|
_previous = 0;
|
||||||
@@ -18,7 +18,7 @@ PropsAction::PropsAction()
|
|||||||
_execute = NULL;
|
_execute = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PropsAction::PropsAction(unsigned long intervl, void (*function)())
|
PropAction::PropAction(unsigned long intervl, void (*function)())
|
||||||
{
|
{
|
||||||
_active = true;
|
_active = true;
|
||||||
_previous = 0;
|
_previous = 0;
|
||||||
@@ -26,24 +26,24 @@ PropsAction::PropsAction(unsigned long intervl, void (*function)())
|
|||||||
_execute = function;
|
_execute = function;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropsAction::reset(unsigned long intervl)
|
void PropAction::reset(unsigned long intervl)
|
||||||
{
|
{
|
||||||
_active = true;
|
_active = true;
|
||||||
_previous = 0;
|
_previous = 0;
|
||||||
_interval = intervl;
|
_interval = intervl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropsAction::disable()
|
void PropAction::disable()
|
||||||
{
|
{
|
||||||
_active = false;
|
_active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropsAction::enable()
|
void PropAction::enable()
|
||||||
{
|
{
|
||||||
_active = true;
|
_active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropsAction::check() {
|
void PropAction::check() {
|
||||||
if (_active && (millis() - _previous >= _interval))
|
if (_active && (millis() - _previous >= _interval))
|
||||||
{
|
{
|
||||||
_previous = millis();
|
_previous = millis();
|
||||||
@@ -51,7 +51,7 @@ void PropsAction::check() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PropsAction::tick() {
|
bool PropAction::tick() {
|
||||||
if (_active && (millis() - _previous >= _interval))
|
if (_active && (millis() - _previous >= _interval))
|
||||||
{
|
{
|
||||||
_previous = millis();
|
_previous = millis();
|
||||||
@@ -60,7 +60,7 @@ bool PropsAction::tick() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long PropsAction::getInterval()
|
unsigned long PropAction::getInterval()
|
||||||
{
|
{
|
||||||
return _interval;
|
return _interval;
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Name: PropsAction.h
|
Name: PropAction.h
|
||||||
Created: 29/10/2019 09:20:31
|
Created: 29/10/2019 09:20:31
|
||||||
Author: Marie Faure <dev at faure dot systems>
|
Author: Marie Faure <dev at faure dot systems>
|
||||||
Editor: https://github.com/fauresystems
|
Editor: https://github.com/fauresystems
|
||||||
@@ -19,11 +19,11 @@
|
|||||||
|
|
||||||
class Props;
|
class Props;
|
||||||
|
|
||||||
class PropsAction {
|
class PropAction {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PropsAction();
|
PropAction();
|
||||||
PropsAction(unsigned long interval, void (*function)());
|
PropAction(unsigned long interval, void (*function)());
|
||||||
|
|
||||||
void reset(unsigned long interval);
|
void reset(unsigned long interval);
|
||||||
void disable();
|
void disable();
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
Name: PropsData.cpp
|
Name: PropData.cpp
|
||||||
Created: 29/10/2019 09:20:31
|
Created: 29/10/2019 09:20:31
|
||||||
Author: Marie Faure <dev at faure dot systems>
|
Author: Marie Faure <dev at faure dot systems>
|
||||||
Editor: https://github.com/fauresystems
|
Editor: https://github.com/fauresystems
|
||||||
License: MIT License (c) Marie Faure <dev at faure dot systems>
|
License: MIT License (c) Marie Faure <dev at faure dot systems>
|
||||||
|
|
||||||
Variable wrapper for connected props.
|
Variable wrapper for connected prop.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "PropsData.h"
|
#include "PropData.h"
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
// ---- Decimal
|
// ---- Decimal
|
||||||
PropsDataDecimal::PropsDataDecimal(const char * id, uint8_t digits, double precision, double initial) {
|
PropDataDecimal::PropDataDecimal(const char * id, uint8_t digits, double precision, double initial) {
|
||||||
_id = id;
|
_id = id;
|
||||||
_current = initial;
|
_current = initial;
|
||||||
_previous = _current;
|
_previous = _current;
|
||||||
@@ -20,12 +20,12 @@ PropsDataDecimal::PropsDataDecimal(const char * id, uint8_t digits, double preci
|
|||||||
_digits = digits;
|
_digits = digits;
|
||||||
}
|
}
|
||||||
|
|
||||||
String PropsDataDecimal::fetch() {
|
String PropDataDecimal::fetch() {
|
||||||
_previous = _current;
|
_previous = _current;
|
||||||
return String(_id) + "=" + String(_current, _digits) + " ";
|
return String(_id) + "=" + String(_current, _digits) + " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
String PropsDataDecimal::fetchChange() {
|
String PropDataDecimal::fetchChange() {
|
||||||
if (_current != _previous && _current && abs(_current - _previous) / _current >= _precision) {
|
if (_current != _previous && _current && abs(_current - _previous) / _current >= _precision) {
|
||||||
return fetch();
|
return fetch();
|
||||||
}
|
}
|
||||||
@@ -35,28 +35,28 @@ String PropsDataDecimal::fetchChange() {
|
|||||||
return String();
|
return String();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropsDataDecimal::setValue(const double v) {
|
void PropDataDecimal::setValue(const double v) {
|
||||||
_current = v;
|
_current = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
double PropsDataDecimal::value() const {
|
double PropDataDecimal::value() const {
|
||||||
return _current;
|
return _current;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Integer
|
// ---- Integer
|
||||||
PropsDataInteger::PropsDataInteger(const char * id, double precision, long initial) {
|
PropDataInteger::PropDataInteger(const char * id, double precision, long initial) {
|
||||||
_id = id;
|
_id = id;
|
||||||
_current = initial;
|
_current = initial;
|
||||||
_previous = _current;
|
_previous = _current;
|
||||||
_precision = precision;
|
_precision = precision;
|
||||||
}
|
}
|
||||||
|
|
||||||
String PropsDataInteger::fetch() {
|
String PropDataInteger::fetch() {
|
||||||
_previous = _current;
|
_previous = _current;
|
||||||
return String(_id) + "=" + String(_current) + " ";
|
return String(_id) + "=" + String(_current) + " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
String PropsDataInteger::fetchChange() {
|
String PropDataInteger::fetchChange() {
|
||||||
if (_current != _previous && _current && abs(_current - _previous) / _current >= _precision) {
|
if (_current != _previous && _current && abs(_current - _previous) / _current >= _precision) {
|
||||||
return fetch();
|
return fetch();
|
||||||
}
|
}
|
||||||
@@ -66,16 +66,16 @@ String PropsDataInteger::fetchChange() {
|
|||||||
return String();
|
return String();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropsDataInteger::setValue(const long v) {
|
void PropDataInteger::setValue(const long v) {
|
||||||
_current = v;
|
_current = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
long PropsDataInteger::value() const {
|
long PropDataInteger::value() const {
|
||||||
return _current;
|
return _current;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Logical
|
// ---- Logical
|
||||||
PropsDataLogical::PropsDataLogical(const char * id, const char *trueval, const char *falseval, bool initial) {
|
PropDataLogical::PropDataLogical(const char * id, const char *trueval, const char *falseval, bool initial) {
|
||||||
_id = id;
|
_id = id;
|
||||||
_current = initial;
|
_current = initial;
|
||||||
_previous = _current;
|
_previous = _current;
|
||||||
@@ -83,7 +83,7 @@ PropsDataLogical::PropsDataLogical(const char * id, const char *trueval, const c
|
|||||||
_falseString = falseval;
|
_falseString = falseval;
|
||||||
}
|
}
|
||||||
|
|
||||||
String PropsDataLogical::fetch() {
|
String PropDataLogical::fetch() {
|
||||||
String str(String(_id) + "=");
|
String str(String(_id) + "=");
|
||||||
if (_current) {
|
if (_current) {
|
||||||
str += _trueString ? _trueString : "1";
|
str += _trueString ? _trueString : "1";
|
||||||
@@ -95,42 +95,42 @@ String PropsDataLogical::fetch() {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
String PropsDataLogical::fetchChange() {
|
String PropDataLogical::fetchChange() {
|
||||||
if (_current != _previous) {
|
if (_current != _previous) {
|
||||||
return fetch();
|
return fetch();
|
||||||
}
|
}
|
||||||
return String();
|
return String();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropsDataLogical::setValue(const bool v) {
|
void PropDataLogical::setValue(const bool v) {
|
||||||
_current = v;
|
_current = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PropsDataLogical::value() const {
|
bool PropDataLogical::value() const {
|
||||||
return _current;
|
return _current;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Text
|
// ---- Text
|
||||||
PropsDataText::PropsDataText(const char * id) {
|
PropDataText::PropDataText(const char * id) {
|
||||||
_id = id;
|
_id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
String PropsDataText::fetch() {
|
String PropDataText::fetch() {
|
||||||
_previous = _current;
|
_previous = _current;
|
||||||
return String(_id) + "=" + _current + " ";
|
return String(_id) + "=" + _current + " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
String PropsDataText::fetchChange() {
|
String PropDataText::fetchChange() {
|
||||||
if (_current != _previous) {
|
if (_current != _previous) {
|
||||||
return fetch();
|
return fetch();
|
||||||
}
|
}
|
||||||
return String();
|
return String();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropsDataText::setValue(String v) {
|
void PropDataText::setValue(String v) {
|
||||||
_current = v;
|
_current = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
String PropsDataText::value() const {
|
String PropDataText::value() const {
|
||||||
return _current;
|
return _current;
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
Name: PropsData.h
|
Name: PropData.h
|
||||||
Created: 29/10/2019 09:20:31
|
Created: 29/10/2019 09:20:31
|
||||||
Author: Marie Faure <dev at faure dot systems>
|
Author: Marie Faure <dev at faure dot systems>
|
||||||
Editor: https://github.com/fauresystems
|
Editor: https://github.com/fauresystems
|
||||||
License: MIT License (c) Marie Faure <dev at faure dot systems>
|
License: MIT License (c) Marie Faure <dev at faure dot systems>
|
||||||
|
|
||||||
Variable wrapper for connected props.
|
Variable wrapper for connected prop.
|
||||||
*/
|
*/
|
||||||
#ifndef PROPSDATA_H
|
#ifndef PROPSDATA_H
|
||||||
#define PROPSDATA_H
|
#define PROPSDATA_H
|
||||||
@@ -19,17 +19,17 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <WString.h>
|
#include <WString.h>
|
||||||
|
|
||||||
class PropsData
|
class PropData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual String fetch() = 0;
|
virtual String fetch() = 0;
|
||||||
virtual String fetchChange() = 0;
|
virtual String fetchChange() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PropsDataDecimal : public PropsData
|
class PropDataDecimal : public PropData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PropsDataDecimal(const char *, uint8_t digits = 2, double precision = 0.1, double initial = 0);
|
PropDataDecimal(const char *, uint8_t digits = 2, double precision = 0.1, double initial = 0);
|
||||||
String fetch();
|
String fetch();
|
||||||
String fetchChange();
|
String fetchChange();
|
||||||
void setValue(const double);
|
void setValue(const double);
|
||||||
@@ -42,10 +42,10 @@ class PropsDataDecimal : public PropsData
|
|||||||
uint8_t _digits;
|
uint8_t _digits;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PropsDataInteger : public PropsData
|
class PropDataInteger : public PropData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PropsDataInteger(const char *, double precision = 0.1, long initial = 0);
|
PropDataInteger(const char *, double precision = 0.1, long initial = 0);
|
||||||
String fetch();
|
String fetch();
|
||||||
String fetchChange();
|
String fetchChange();
|
||||||
void setValue(const long);
|
void setValue(const long);
|
||||||
@@ -57,10 +57,10 @@ class PropsDataInteger : public PropsData
|
|||||||
double _precision;
|
double _precision;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PropsDataLogical : public PropsData
|
class PropDataLogical : public PropData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PropsDataLogical(const char *, const char *trueval = NULL, const char *falseval = NULL, bool initial = false);
|
PropDataLogical(const char *, const char *trueval = NULL, const char *falseval = NULL, bool initial = false);
|
||||||
String fetch();
|
String fetch();
|
||||||
String fetchChange();
|
String fetchChange();
|
||||||
void setValue(const bool);
|
void setValue(const bool);
|
||||||
@@ -73,10 +73,10 @@ class PropsDataLogical : public PropsData
|
|||||||
const char *_falseString;
|
const char *_falseString;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PropsDataText : public PropsData
|
class PropDataText : public PropData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PropsDataText(const char *);
|
PropDataText(const char *);
|
||||||
String fetch();
|
String fetch();
|
||||||
String fetchChange();
|
String fetchChange();
|
||||||
void setValue(String);
|
void setValue(String);
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Name: WifiProps.cpp
|
Name: WifiProp.cpp
|
||||||
Created: 29/10/2019 09:20:31
|
Created: 29/10/2019 09:20:31
|
||||||
Author: Marie Faure <dev at faure dot systems>
|
Author: Marie Faure <dev at faure dot systems>
|
||||||
Editor: https://github.com/fauresystems
|
Editor: https://github.com/fauresystems
|
||||||
@@ -8,19 +8,19 @@
|
|||||||
Class Props for Arduino with WiFiNINA.
|
Class Props for Arduino with WiFiNINA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "WifiProps.h"
|
#include "WifiProp.h"
|
||||||
|
|
||||||
|
|
||||||
#if defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_SAMD_MKRVIDOR4000)
|
#if defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_SAMD_MKRVIDOR4000)
|
||||||
|
|
||||||
|
|
||||||
WifiProps::WifiProps(const char* client_id, const char* in_box, const char* out_box, const char* broker, const int port)
|
WifiProp::WifiProp(const char* client_id, const char* in_box, const char* out_box, const char* broker, const int port)
|
||||||
: Props(client_id, in_box, out_box, broker, port)
|
: Props(client_id, in_box, out_box, broker, port)
|
||||||
{
|
{
|
||||||
_client.setClient(_wifiClient);
|
_client.setClient(_wifiClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WifiProps::begin(void(*on_message)(String))
|
void WifiProp::begin(void(*on_message)(String))
|
||||||
{
|
{
|
||||||
if (on_message) onInboxMessageReceived = on_message;
|
if (on_message) onInboxMessageReceived = on_message;
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Name: WifiProps.h
|
Name: WifiProp.h
|
||||||
Created: 29/10/2019 09:20:31
|
Created: 29/10/2019 09:20:31
|
||||||
Author: Marie Faure <dev at faure dot systems>
|
Author: Marie Faure <dev at faure dot systems>
|
||||||
Editor: https://github.com/fauresystems
|
Editor: https://github.com/fauresystems
|
||||||
@@ -7,8 +7,8 @@
|
|||||||
|
|
||||||
Class Props for Arduino with WiFiNINA.
|
Class Props for Arduino with WiFiNINA.
|
||||||
*/
|
*/
|
||||||
#ifndef WIFIPROPS_H
|
#ifndef WIFIPROP_H
|
||||||
#define WIFIPROPS_H
|
#define WIFIPROP_H
|
||||||
|
|
||||||
|
|
||||||
#if defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_SAMD_MKRVIDOR4000)
|
#if defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_SAMD_MKRVIDOR4000)
|
||||||
@@ -18,12 +18,12 @@
|
|||||||
|
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <WiFiClient.h>
|
#include <WiFiClient.h>
|
||||||
#include "Props.h"
|
#include "Prop.h"
|
||||||
|
|
||||||
class WifiProps : public Props
|
class WifiProp : public Props
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WifiProps(const char*, const char*, const char*, const char*, const int);
|
WifiProp(const char*, const char*, const char*, const char*, const int);
|
||||||
void begin(void(*)(String) = NULL);
|
void begin(void(*)(String) = NULL);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Reference in New Issue
Block a user