Props to prop no plural
This commit is contained in:
+16
-15
@@ -21,10 +21,11 @@
|
||||
<None Include="$(MSBuildThisFileDirectory)ArduinoProps.zip" />
|
||||
<None Include="$(MSBuildThisFileDirectory)create-library-zip.bat" />
|
||||
<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\BlinkOnEthernetProps\BlinkOnEthernetProps.ino" />
|
||||
<None Include="$(MSBuildThisFileDirectory)examples\BlinkOnWifiProps\BlinkOnWifiProps.ino" />
|
||||
<None Include="$(MSBuildThisFileDirectory)examples\BlinkOnEthernetProp\BlinkOnEthernetProp.ino" />
|
||||
<None Include="$(MSBuildThisFileDirectory)examples\BlinkOnWifiProp\BlinkOnWifiProp.ino" />
|
||||
<None Include="$(MSBuildThisFileDirectory)help\Arduino_Props.md" />
|
||||
<None Include="$(MSBuildThisFileDirectory)help\Props.md" />
|
||||
<None Include="$(MSBuildThisFileDirectory)help\PropsAction.md" />
|
||||
@@ -36,21 +37,21 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\ArduinoProps.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\BridgeProps.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\EthernetProps.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\Props.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\PropsAction.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\PropsData.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\WifiProps.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\BridgeProp.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\EthernetProp.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\Prop.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\PropAction.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\PropData.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\WifiProp.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\ArduinoProps.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\BridgeProps.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\EthernetProps.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\Props.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\PropsAction.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\PropsData.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\WifiProps.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\BridgeProp.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\EthernetProp.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\Prop.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\PropAction.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\PropData.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\WifiProp.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="$(MSBuildThisFileDirectory)help\dependencies-shot.png" />
|
||||
|
||||
@@ -24,18 +24,6 @@
|
||||
<None Include="$(MSBuildThisFileDirectory)LICENSE.md" />
|
||||
<None Include="$(MSBuildThisFileDirectory)README.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)create-library-zip.bat" />
|
||||
<None Include="$(MSBuildThisFileDirectory)help\Arduino_Props.md">
|
||||
@@ -54,27 +42,42 @@
|
||||
<Filter>Help</Filter>
|
||||
</None>
|
||||
<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>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\ArduinoProps.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\BridgeProps.cpp">
|
||||
<ClCompile Include="D:\GitHub\fauresystems\ArduinoProps\src\BridgeProp.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\EthernetProps.cpp">
|
||||
<ClCompile Include="D:\GitHub\fauresystems\ArduinoProps\src\EthernetProp.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\Props.cpp">
|
||||
<ClCompile Include="D:\GitHub\fauresystems\ArduinoProps\src\Prop.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\PropsAction.cpp">
|
||||
<ClCompile Include="D:\GitHub\fauresystems\ArduinoProps\src\PropAction.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\PropsData.cpp">
|
||||
<ClCompile Include="D:\GitHub\fauresystems\ArduinoProps\src\PropData.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)src\WifiProps.cpp">
|
||||
<ClCompile Include="D:\GitHub\fauresystems\ArduinoProps\src\WifiProp.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
@@ -82,22 +85,22 @@
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\ArduinoProps.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\BridgeProps.h">
|
||||
<ClInclude Include="D:\GitHub\fauresystems\ArduinoProps\src\BridgeProp.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\EthernetProps.h">
|
||||
<ClInclude Include="D:\GitHub\fauresystems\ArduinoProps\src\EthernetProp.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\Props.h">
|
||||
<ClInclude Include="D:\GitHub\fauresystems\ArduinoProps\src\Prop.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\PropsAction.h">
|
||||
<ClInclude Include="D:\GitHub\fauresystems\ArduinoProps\src\PropAction.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\PropsData.h">
|
||||
<ClInclude Include="D:\GitHub\fauresystems\ArduinoProps\src\PropData.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)src\WifiProps.h">
|
||||
<ClInclude Include="D:\GitHub\fauresystems\ArduinoProps\src\WifiProp.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
|
||||
Binary file not shown.
+56
-56
@@ -1,35 +1,35 @@
|
||||
# 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*
|
||||
2. **BlinkOnEthernetProps**: the Blink example on an Ethernet props with *ArduinoProps library*
|
||||
3. **BlinkOnWifiProps**: the Blink example on a Wifi props with *ArduinoProps library*
|
||||
4. **BlinkOnBridgePubSub**: the Blink example on props using *PubSubClient* directly
|
||||
1. **BlinkOnBridgeProp**: the Blink example on a Yun prop with *ArduinoProps library*
|
||||
2. **BlinkOnEthernetProp**: the Blink example on an Ethernet prop with *ArduinoProps library*
|
||||
3. **BlinkOnWifiProp**: the Blink example on a Wifi prop with *ArduinoProps library*
|
||||
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).
|
||||
|
||||
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.
|
||||
|
||||

|
||||
|
||||
```csharp
|
||||
/* BlinkOnBridgeProps.ino
|
||||
/* BlinkOnBridgeProp.ino
|
||||
MIT License (c) Marie Faure <dev at faure dot systems>
|
||||
|
||||
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
|
||||
ensure CPU for MQTT protocol. Use PropsAction checks instead.
|
||||
simple MQTT prop. Avoid delay() calls (except short ones) in loop() to
|
||||
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.
|
||||
|
||||
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"
|
||||
|
||||
// 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
|
||||
|
||||
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/outbox",
|
||||
"192.168.1.42", // your MQTT server IP address
|
||||
1883); // your MQTT server port;
|
||||
|
||||
PropsDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
||||
PropsDataLogical led(u8"led");
|
||||
PropDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
||||
PropDataLogical led(u8"led");
|
||||
|
||||
void clignote(); // forward
|
||||
PropsAction clignoteAction = PropsAction(1000, clignote);
|
||||
PropAction clignoteAction = PropAction(1000, clignote);
|
||||
|
||||
void setup()
|
||||
{
|
||||
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);
|
||||
props.addData(&led);
|
||||
prop.addData(&clignoter);
|
||||
prop.addData(&led);
|
||||
|
||||
props.begin(InboxMessage::run);
|
||||
prop.begin(InboxMessage::run);
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output
|
||||
|
||||
@@ -70,7 +70,7 @@ void setup()
|
||||
|
||||
void loop()
|
||||
{
|
||||
props.loop();
|
||||
prop.loop();
|
||||
|
||||
led.setValue(digitalRead(LED_BUILTIN)); // read I/O
|
||||
|
||||
@@ -89,31 +89,31 @@ void InboxMessage::run(String a) {
|
||||
|
||||
if (a == u8"app:startup")
|
||||
{
|
||||
props.sendAllData();
|
||||
props.sendDone(a);
|
||||
prop.sendAllData();
|
||||
prop.sendDone(a);
|
||||
}
|
||||
else if (a == "clignoter:1")
|
||||
{
|
||||
clignoter.setValue(true);
|
||||
|
||||
props.sendAllData(); // all data change, we don't have to be selctive then
|
||||
props.sendDone(a); // acknowledge props command action
|
||||
prop.sendAllData(); // all data change, we don't have to be selctive then
|
||||
prop.sendDone(a); // acknowledge prop command action
|
||||
}
|
||||
else if (a == "clignoter:0")
|
||||
{
|
||||
clignoter.setValue(false);
|
||||
|
||||
props.sendAllData(); // all data change, we don't have to be selctive then
|
||||
props.sendDone(a); // acknowledge props command action
|
||||
prop.sendAllData(); // all data change, we don't have to be selctive then
|
||||
prop.sendDone(a); // acknowledge prop command action
|
||||
}
|
||||
else
|
||||
{
|
||||
// acknowledge omition of the props command
|
||||
props.sendOmit(a);
|
||||
// acknowledge omition of the prop command
|
||||
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
|
||||
IPAddress ip;
|
||||
@@ -129,7 +129,7 @@ void updateBrokerAdressFromFile(const char* broker_file, BridgeProps* props)
|
||||
}
|
||||
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:
|
||||
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):
|
||||
Uupdating WiFiNINA firmware is easy: [WiFiNINA firmware update](help/WifiNinaFirmware.md).
|
||||
@@ -180,7 +180,7 @@ void loop()
|
||||
if (!wifiBegun) {
|
||||
WiFi.begin(ssid, passphrase);
|
||||
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()
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if (fv.startsWith("1.0")) {
|
||||
@@ -206,7 +206,7 @@ void loop()
|
||||
wifiBegun = false;
|
||||
}
|
||||
|
||||
props.loop();
|
||||
prop.loop();
|
||||
|
||||
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
|
||||
|
||||
@@ -230,7 +230,7 @@ However, this can help in special cases.
|
||||
License: MIT License (c) Marie Faure <dev at faure dot systems>
|
||||
|
||||
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 <BridgeClient.h>
|
||||
@@ -239,13 +239,13 @@ However, this can help in special cases.
|
||||
#include <VariableTimedAction.h>
|
||||
|
||||
#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
|
||||
// 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
|
||||
#define PROPS_INBOX u8"Room/Demoniak/Props/Arduino Contrôleur/inbox"
|
||||
#define PROPS_OUTBOX u8"Room/Demoniak/Props/Arduino Contrôleur/outbox"
|
||||
#define PROP_INBOX u8"Room/Demoniak/Props/Arduino Contrôleur/inbox"
|
||||
#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
|
||||
#define YUN_BROKER_FILE "/root/broker"
|
||||
@@ -346,10 +346,10 @@ void loop()
|
||||
{
|
||||
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.subscribe(PROPS_INBOX, 1); // max QoS is 1 for PubSubClient subsciption
|
||||
_client.publish(PROP_OUTBOX, "CONNECTED", true);
|
||||
_client.subscribe(PROP_INBOX, 1); // max QoS is 1 for PubSubClient subsciption
|
||||
lastReconnection = 0L;
|
||||
}
|
||||
}
|
||||
@@ -371,7 +371,7 @@ void publishAll()
|
||||
buf += u8" clignote=" + (blinking.blink ? String("oui") : String("non"));
|
||||
blink_ref = blinking.blink;
|
||||
|
||||
_client.publish(PROPS_OUTBOX, buf.c_str());
|
||||
_client.publish(PROP_OUTBOX, buf.c_str());
|
||||
}
|
||||
|
||||
void publishChanges()
|
||||
@@ -393,13 +393,13 @@ void publishChanges()
|
||||
}
|
||||
|
||||
if (buf.length() > 4)
|
||||
_client.publish(PROPS_OUTBOX, buf.c_str());
|
||||
_client.publish(PROP_OUTBOX, buf.c_str());
|
||||
}
|
||||
|
||||
void publishDone(String a)
|
||||
{
|
||||
a = "DONE " + a;
|
||||
_client.publish(PROPS_OUTBOX, a.c_str());
|
||||
_client.publish(PROP_OUTBOX, a.c_str());
|
||||
}
|
||||
|
||||
void onInboxMessage(String a) {
|
||||
@@ -415,7 +415,7 @@ void onInboxMessage(String a) {
|
||||
blinking.blink = true;
|
||||
|
||||
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")
|
||||
{
|
||||
@@ -423,12 +423,12 @@ void onInboxMessage(String a) {
|
||||
blinking.blink = false;
|
||||
|
||||
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
|
||||
{
|
||||
// acknowledge omition of the props command
|
||||
_client.publish(PROPS_OUTBOX, String("OMIT " + a).c_str());
|
||||
// acknowledge omition of the prop command
|
||||
_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);
|
||||
p[len] = '\0';
|
||||
if (String(p) == "@PING")
|
||||
_client.publish(PROPS_OUTBOX, "PONG");
|
||||
_client.publish(PROP_OUTBOX, "PONG");
|
||||
else
|
||||
onInboxMessage(p);
|
||||
free(p);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# ArduinoProps library
|
||||
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
|
||||
4. Application protocol for escape room 2.0 props
|
||||
4. Application protocol for escape room 2.0 prop
|
||||
5. Compatible hardware
|
||||
6. Advantages of Arduino Yun and Dragino Yun shield
|
||||
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.
|
||||
|
||||
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
|
||||
|
||||
@@ -35,34 +35,34 @@ Reading [EXAMPLES.md](EXAMPLES.md) will be helpful.
|
||||
|ArduinoProps library documentation |
|
||||
|-------------------------------------------------------------|
|
||||
| [This README file](README.md) |
|
||||
| [Props class reference](help/Props.md) |
|
||||
| [PropsData class reference](help/PropsData.md) |
|
||||
| [PropsAction class reference](help/PropsAction.md) |
|
||||
| [Props class reference](help/Prop.md) |
|
||||
| [PropData class reference](help/PropData.md) |
|
||||
| [PropAction class reference](help/PropAction.md) |
|
||||
| [ArduinoProps library examples](EXAMPLES.md) |
|
||||
| [Arduino Props for Escape Room 2.0](help/Arduino_Props.md) |
|
||||
| [WiFiNINA firmware update](help/WifiNinaFirmware.md) |
|
||||
|
||||
|
||||
## 2. Escape room 2.0 props with Arduino
|
||||
## 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
|
||||

|
||||
publish/subscribe messaging protocol designed for M2M (machine to machine) telemetry in low bandwidth environments.
|
||||
|
||||
### Props with *Raspberry*
|
||||
Escape room 2.0 props can be powered with Raspberry Pi or any Pythonic nanocomputer using *MqttApp*, our pure Python 3 class based on <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
|
||||
*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
|
||||
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.
|
||||
|
||||
### 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).
|
||||
|
||||
@@ -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
|
||||
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
|
||||
DATA -> send variables to control
|
||||
MESG -> send text to display in control
|
||||
DONE -> acknowledge that a command has been performed
|
||||
OMIT -> acknowledge that a command has been ignored
|
||||
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
|
||||
```
|
||||
|
||||
@@ -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.
|
||||
|
||||
## 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:
|
||||
```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.).
|
||||
|
||||
#### Messages sent from the Arduino props are formatted
|
||||
#### Messages sent from the Arduino prop are formatted
|
||||
```csharp
|
||||
DATA sensor=24.26 light=on challenge=pinball
|
||||
MESG Warning: sensor not detected
|
||||
@@ -159,7 +159,7 @@ More MQTT topics can be use for anything (room scenario, etc.).
|
||||
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
|
||||
power:1 for example to power on the room
|
||||
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
|
||||
```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
|
||||
```
|
||||
|
||||
@@ -184,10 +184,10 @@ More MQTT topics can be use for anything (room scenario, etc.).
|
||||
- Arduino MKR VIDOR 4000
|
||||
- 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
|
||||
- Sparkfun WiFly Shield – [library](https://github.com/dpslwk/WiFly)
|
||||
- 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
|
||||
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.
|
||||
|
||||
|
||||
## 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*:
|
||||
- create connected props quickly thanks to the application protocol and examples
|
||||
- targetted for escape room props, *ArduinoProps library* can be used for any IoT project
|
||||
- create connected prop quickly thanks to the application protocol and examples
|
||||
- targetted for escape room prop, *ArduinoProps library* can be used for any IoT project
|
||||
- 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***.
|
||||
|
||||
@@ -219,7 +219,7 @@ With *ArduinoProps library*:
|
||||
|
||||
|
||||
## 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 subscribe at QoS 0 or QoS 1.
|
||||
- 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.
|
||||
|
||||
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*
|
||||
2. **BlinkOnEthernetProps**: the Blink example on an Ethernet props with *ArduinoProps library*
|
||||
3. **BlinkOnWifiProps**: the Blink example on a Wifi props with *ArduinoProps library*
|
||||
4. **BlinkOnBridgePubSub**: the Blink example on props using *PubSubClient* directly
|
||||
1. **BlinkOnBridgeProp**: the Blink example on a Yun prop with *ArduinoProps library*
|
||||
2. **BlinkOnEthernetProp**: the Blink example on an Ethernet prop with *ArduinoProps library*
|
||||
3. **BlinkOnWifiProp**: the Blink example on a Wifi prop with *ArduinoProps library*
|
||||
4. **BlinkOnBridgePubSub**: the Blink example on prop using *PubSubClient* directly
|
||||
|
||||
|
||||
## Author
|
||||
|
||||
+28
-28
@@ -1,11 +1,11 @@
|
||||
/* BlinkOnBridgeProps.ino
|
||||
/* BlinkOnBridgeProp.ino
|
||||
MIT License (c) Marie Faure <dev at faure dot systems>
|
||||
|
||||
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
|
||||
ensure CPU for MQTT protocol. Use PropsAction checks instead.
|
||||
simple MQTT prop. Avoid delay() calls (except short ones) in loop() to
|
||||
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.
|
||||
|
||||
Requirements:
|
||||
@@ -14,36 +14,36 @@
|
||||
#include <Bridge.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
|
||||
// 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/outbox",
|
||||
"192.168.1.53", // your MQTT server IP address
|
||||
1883); // your MQTT server port;
|
||||
|
||||
PropsDataLogical blinking(u8"blink", u8"yes", u8"no", true);
|
||||
PropsDataLogical led(u8"led");
|
||||
PropsDataText rssi(u8"rssi");
|
||||
PropDataLogical blinking(u8"blink", u8"yes", u8"no", true);
|
||||
PropDataLogical led(u8"led");
|
||||
PropDataText rssi(u8"rssi");
|
||||
|
||||
void clignote(); // forward
|
||||
PropsAction blinkingAction = PropsAction(1000, clignote);
|
||||
PropAction blinkingAction = PropAction(1000, clignote);
|
||||
|
||||
void lireRssi(); // forward
|
||||
PropsAction lireRssiAction = PropsAction(30000, lireRssi);
|
||||
PropAction lireRssiAction = PropAction(30000, lireRssi);
|
||||
|
||||
void setup()
|
||||
{
|
||||
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);
|
||||
props.addData(&led);
|
||||
props.addData(&rssi);
|
||||
prop.addData(&blinking);
|
||||
prop.addData(&led);
|
||||
prop.addData(&rssi);
|
||||
|
||||
props.begin(InboxMessage::run);
|
||||
prop.begin(InboxMessage::run);
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output
|
||||
|
||||
@@ -54,7 +54,7 @@ void setup()
|
||||
|
||||
void loop()
|
||||
{
|
||||
props.loop();
|
||||
prop.loop();
|
||||
|
||||
led.setValue(digitalRead(LED_BUILTIN)); // read I/O
|
||||
|
||||
@@ -88,35 +88,35 @@ void InboxMessage::run(String a) {
|
||||
|
||||
if (a == u8"app:startup")
|
||||
{
|
||||
props.sendAllData();
|
||||
props.sendDone(a);
|
||||
prop.sendAllData();
|
||||
prop.sendDone(a);
|
||||
}
|
||||
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")
|
||||
{
|
||||
blinking.setValue(true);
|
||||
|
||||
props.sendAllData(); // all data change, we don't have to be selctive then
|
||||
props.sendDone(a); // acknowledge props command action
|
||||
prop.sendAllData(); // all data change, we don't have to be selctive then
|
||||
prop.sendDone(a); // acknowledge prop command action
|
||||
}
|
||||
else if (a == "blink:0")
|
||||
{
|
||||
blinking.setValue(false);
|
||||
|
||||
props.sendAllData(); // all data change, we don't have to be selctive then
|
||||
props.sendDone(a); // acknowledge props command action
|
||||
prop.sendAllData(); // all data change, we don't have to be selctive then
|
||||
prop.sendDone(a); // acknowledge prop command action
|
||||
}
|
||||
else
|
||||
{
|
||||
// acknowledge omition of the props command
|
||||
props.sendOmit(a);
|
||||
// acknowledge omition of the prop command
|
||||
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
|
||||
IPAddress ip;
|
||||
@@ -132,5 +132,5 @@ void updateBrokerAdressFromFile(const char* broker_file, BridgeProps* props)
|
||||
}
|
||||
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>
|
||||
|
||||
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
|
||||
ensure CPU for MQTT protocol. Use PropsAction checks instead.
|
||||
simple MQTT prop. Avoid delay() calls (except short ones) in loop() to
|
||||
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.
|
||||
|
||||
Requirements:
|
||||
@@ -14,36 +14,36 @@
|
||||
#include <Bridge.h>
|
||||
#include "ArduinoProps.h"
|
||||
|
||||
// If you're running xcape.io Room software you have to respect props inbox/outbox
|
||||
// topicw syntax: Room/[escape room name]/Props/[propsname]/inbox|outbox
|
||||
// If you're running xcape.io Room software you have to respect prop inbox/outbox
|
||||
// topicw syntax: Room/[escape room name]/Props/[propname]/inbox|outbox
|
||||
// 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/outbox",
|
||||
"192.168.1.53", // your MQTT server IP address
|
||||
1883); // your MQTT server port;
|
||||
|
||||
PropsDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
||||
PropsDataLogical led(u8"led");
|
||||
PropsDataText rssi(u8"rssi");
|
||||
PropDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
||||
PropDataLogical led(u8"led");
|
||||
PropDataText rssi(u8"rssi");
|
||||
|
||||
void clignote(); // forward
|
||||
PropsAction clignoteAction = PropsAction(1000, clignote);
|
||||
PropAction clignoteAction = PropAction(1000, clignote);
|
||||
|
||||
void lireRssi(); // forward
|
||||
PropsAction lireRssiAction = PropsAction(30000, lireRssi);
|
||||
PropAction lireRssiAction = PropAction(30000, lireRssi);
|
||||
|
||||
void setup()
|
||||
{
|
||||
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);
|
||||
props.addData(&led);
|
||||
props.addData(&rssi);
|
||||
prop.addData(&clignoter);
|
||||
prop.addData(&led);
|
||||
prop.addData(&rssi);
|
||||
|
||||
props.begin(InboxMessage::run);
|
||||
prop.begin(InboxMessage::run);
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output
|
||||
|
||||
@@ -54,7 +54,7 @@ void setup()
|
||||
|
||||
void loop()
|
||||
{
|
||||
props.loop();
|
||||
prop.loop();
|
||||
|
||||
led.setValue(digitalRead(LED_BUILTIN)); // read I/O
|
||||
|
||||
@@ -88,35 +88,35 @@ void InboxMessage::run(String a) {
|
||||
|
||||
if (a == u8"app:startup")
|
||||
{
|
||||
props.sendAllData();
|
||||
props.sendDone(a);
|
||||
prop.sendAllData();
|
||||
prop.sendDone(a);
|
||||
}
|
||||
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")
|
||||
{
|
||||
clignoter.setValue(true);
|
||||
|
||||
props.sendAllData(); // all data change, we don't have to be selctive then
|
||||
props.sendDone(a); // acknowledge props command action
|
||||
prop.sendAllData(); // all data change, we don't have to be selctive then
|
||||
prop.sendDone(a); // acknowledge prop command action
|
||||
}
|
||||
else if (a == "clignoter:0")
|
||||
{
|
||||
clignoter.setValue(false);
|
||||
|
||||
props.sendAllData(); // all data change, we don't have to be selctive then
|
||||
props.sendDone(a); // acknowledge props command action
|
||||
prop.sendAllData(); // all data change, we don't have to be selctive then
|
||||
prop.sendDone(a); // acknowledge prop command action
|
||||
}
|
||||
else
|
||||
{
|
||||
// acknowledge omition of the props command
|
||||
props.sendOmit(a);
|
||||
// acknowledge omition of the prop command
|
||||
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
|
||||
IPAddress ip;
|
||||
@@ -132,5 +132,5 @@ void updateBrokerAdressFromFile(const char* broker_file, BridgeProps* props)
|
||||
}
|
||||
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>
|
||||
|
||||
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 <BridgeClient.h>
|
||||
@@ -10,14 +10,14 @@
|
||||
#include <PubSubClient.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
|
||||
// https://xcape.io/go/room
|
||||
|
||||
#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 PROPS_INBOX u8"Room/My room/Props/Arduino Blink/inbox"
|
||||
#define PROPS_OUTBOX u8"Room/My room/Props/Arduino Blink/outbox"
|
||||
#define PROP_NAME u8"Arduino Blink" // as MQTT client id, should be unique per client for given broker
|
||||
#define PROP_INBOX u8"Room/My room/Props/Arduino Blink/inbox"
|
||||
#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
|
||||
#define YUN_BROKER_FILE "/root/broker"
|
||||
@@ -118,10 +118,10 @@ void loop()
|
||||
{
|
||||
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.subscribe(PROPS_INBOX, 1); // max QoS is 1 for PubSubClient subsciption
|
||||
_client.publish(PROP_OUTBOX, "CONNECTED", true);
|
||||
_client.subscribe(PROP_INBOX, 1); // max QoS is 1 for PubSubClient subsciption
|
||||
lastReconnection = 0L;
|
||||
}
|
||||
}
|
||||
@@ -143,7 +143,7 @@ void publishAll()
|
||||
buf += u8" clignote=" + (blinking.blink ? String("oui") : String("non"));
|
||||
blink_ref = blinking.blink;
|
||||
|
||||
_client.publish(PROPS_OUTBOX, buf.c_str());
|
||||
_client.publish(PROP_OUTBOX, buf.c_str());
|
||||
}
|
||||
|
||||
void publishChanges()
|
||||
@@ -165,13 +165,13 @@ void publishChanges()
|
||||
}
|
||||
|
||||
if (buf.length() > 4)
|
||||
_client.publish(PROPS_OUTBOX, buf.c_str());
|
||||
_client.publish(PROP_OUTBOX, buf.c_str());
|
||||
}
|
||||
|
||||
void publishDone(String a)
|
||||
{
|
||||
a = "DONE " + a;
|
||||
_client.publish(PROPS_OUTBOX, a.c_str());
|
||||
_client.publish(PROP_OUTBOX, a.c_str());
|
||||
}
|
||||
|
||||
void onInboxMessage(String a) {
|
||||
@@ -187,7 +187,7 @@ void onInboxMessage(String a) {
|
||||
blinking.blink = true;
|
||||
|
||||
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")
|
||||
{
|
||||
@@ -195,12 +195,12 @@ void onInboxMessage(String a) {
|
||||
blinking.blink = false;
|
||||
|
||||
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
|
||||
{
|
||||
// acknowledge omition of the props command
|
||||
_client.publish(PROPS_OUTBOX, String("OMIT " + a).c_str());
|
||||
// acknowledge omition of the prop command
|
||||
_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);
|
||||
p[len] = '\0';
|
||||
if (String(p) == "@PING")
|
||||
_client.publish(PROPS_OUTBOX, "PONG");
|
||||
_client.publish(PROP_OUTBOX, "PONG");
|
||||
else
|
||||
onInboxMessage(p);
|
||||
free(p);
|
||||
|
||||
+22
-22
@@ -1,11 +1,11 @@
|
||||
/* BlinkOnEthernetProps.ino
|
||||
/* BlinkOnEthernetProp.ino
|
||||
MIT License (c) Marie Faure <dev at faure dot systems>
|
||||
|
||||
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
|
||||
ensure CPU for MQTT protocol. Use PropsAction checks instead.
|
||||
simple MQTT prop. Avoid delay() calls (except short ones) in loop() to
|
||||
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.
|
||||
|
||||
Requirements:
|
||||
@@ -15,11 +15,11 @@
|
||||
#include <IPAddress.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
|
||||
// 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/outbox",
|
||||
"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
|
||||
#define LED_BUILTIN 8
|
||||
|
||||
PropsDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
||||
PropsDataLogical led(u8"led");
|
||||
PropDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
||||
PropDataLogical led(u8"led");
|
||||
|
||||
void clignote(); // forward
|
||||
PropsAction clignoteAction = PropsAction(1000, clignote);
|
||||
PropAction clignoteAction = PropAction(1000, clignote);
|
||||
|
||||
void setup()
|
||||
{
|
||||
@@ -59,10 +59,10 @@ void setup()
|
||||
//Ethernet.setGatewayIP(IPAddress(192, 168, 1, 1));
|
||||
//Ethernet.setDnsServerIP(IPAddress(192, 168, 1, 1));
|
||||
|
||||
props.addData(&clignoter);
|
||||
props.addData(&led);
|
||||
prop.addData(&clignoter);
|
||||
prop.addData(&led);
|
||||
|
||||
props.begin(InboxMessage::run);
|
||||
prop.begin(InboxMessage::run);
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output
|
||||
|
||||
@@ -71,7 +71,7 @@ void setup()
|
||||
|
||||
void loop()
|
||||
{
|
||||
props.loop();
|
||||
prop.loop();
|
||||
|
||||
led.setValue(digitalRead(LED_BUILTIN)); // read I/O
|
||||
|
||||
@@ -90,30 +90,30 @@ void InboxMessage::run(String a) {
|
||||
|
||||
if (a == u8"app:startup")
|
||||
{
|
||||
props.sendAllData();
|
||||
props.sendDone(a);
|
||||
prop.sendAllData();
|
||||
prop.sendDone(a);
|
||||
}
|
||||
else if (a == u8"reset-mcu")
|
||||
{
|
||||
props.resetMcu();
|
||||
prop.resetMcu();
|
||||
}
|
||||
else if (a == "clignoter:1")
|
||||
{
|
||||
clignoter.setValue(true);
|
||||
|
||||
props.sendAllData(); // all data change, we don't have to be selctive then
|
||||
props.sendDone(a); // acknowledge props command action
|
||||
prop.sendAllData(); // all data change, we don't have to be selctive then
|
||||
prop.sendDone(a); // acknowledge prop command action
|
||||
}
|
||||
else if (a == "clignoter:0")
|
||||
{
|
||||
clignoter.setValue(false);
|
||||
|
||||
props.sendAllData(); // all data change, we don't have to be selctive then
|
||||
props.sendDone(a); // acknowledge props command action
|
||||
prop.sendAllData(); // all data change, we don't have to be selctive then
|
||||
prop.sendDone(a); // acknowledge prop command action
|
||||
}
|
||||
else
|
||||
{
|
||||
// acknowledge omition of the props command
|
||||
props.sendOmit(a);
|
||||
// acknowledge omition of the prop command
|
||||
prop.sendOmit(a);
|
||||
}
|
||||
}
|
||||
+25
-25
@@ -1,11 +1,11 @@
|
||||
/* BlinkOnWifiProps.ino
|
||||
/* BlinkOnWifiProp.ino
|
||||
MIT License (c) Marie Faure <dev at faure dot systems>
|
||||
|
||||
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
|
||||
ensure CPU for MQTT protocol. Use PropsAction checks instead.
|
||||
simple MQTT prop. Avoid delay() calls (except short ones) in loop() to
|
||||
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.
|
||||
|
||||
Requirements:
|
||||
@@ -17,11 +17,11 @@
|
||||
const char* ssid = "";
|
||||
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
|
||||
// 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/outbox",
|
||||
"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
|
||||
#define LED_BUILTIN 8
|
||||
|
||||
PropsDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
||||
PropsDataLogical led(u8"led");
|
||||
PropsDataText rssi(u8"rssi");
|
||||
PropDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
||||
PropDataLogical led(u8"led");
|
||||
PropDataText rssi(u8"rssi");
|
||||
|
||||
void clignote(); // forward
|
||||
PropsAction clignoteAction = PropsAction(1000, clignote);
|
||||
PropAction clignoteAction = PropAction(1000, clignote);
|
||||
|
||||
bool wifiBegun(false);
|
||||
|
||||
@@ -44,11 +44,11 @@ void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
|
||||
props.addData(&clignoter);
|
||||
props.addData(&led);
|
||||
props.addData(&rssi);
|
||||
prop.addData(&clignoter);
|
||||
prop.addData(&led);
|
||||
prop.addData(&rssi);
|
||||
|
||||
props.begin(InboxMessage::run);
|
||||
prop.begin(InboxMessage::run);
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output
|
||||
|
||||
@@ -60,7 +60,7 @@ void loop()
|
||||
if (!wifiBegun) {
|
||||
WiFi.begin(ssid, passphrase);
|
||||
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()
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if (fv.startsWith("1.0")) {
|
||||
@@ -86,7 +86,7 @@ void loop()
|
||||
wifiBegun = false;
|
||||
}
|
||||
|
||||
props.loop();
|
||||
prop.loop();
|
||||
|
||||
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")
|
||||
{
|
||||
props.sendAllData();
|
||||
props.sendDone(a);
|
||||
prop.sendAllData();
|
||||
prop.sendDone(a);
|
||||
}
|
||||
else if (a == u8"reset-mcu")
|
||||
{
|
||||
props.resetMcu();
|
||||
prop.resetMcu();
|
||||
}
|
||||
else if (a == "clignoter:1")
|
||||
{
|
||||
clignoter.setValue(true);
|
||||
|
||||
props.sendAllData(); // all data change, we don't have to be selctive then
|
||||
props.sendDone(a); // acknowledge props command action
|
||||
prop.sendAllData(); // all data change, we don't have to be selctive then
|
||||
prop.sendDone(a); // acknowledge prop command action
|
||||
}
|
||||
else if (a == "clignoter:0")
|
||||
{
|
||||
clignoter.setValue(false);
|
||||
|
||||
props.sendAllData(); // all data change, we don't have to be selctive then
|
||||
props.sendDone(a); // acknowledge props command action
|
||||
prop.sendAllData(); // all data change, we don't have to be selctive then
|
||||
prop.sendDone(a); // acknowledge prop command action
|
||||
}
|
||||
else
|
||||
{
|
||||
// acknowledge omition of the props command
|
||||
props.sendOmit(a);
|
||||
// acknowledge omition of the prop command
|
||||
prop.sendOmit(a);
|
||||
}
|
||||
}
|
||||
+11
-11
@@ -1,8 +1,8 @@
|
||||
# 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%)
|
||||
- fast problem fixing
|
||||
- real-time (human scale) notification and control
|
||||
@@ -15,7 +15,7 @@ Benefits and specificities of the *ArduinoProps library*
|
||||
- constant sustaining of Arduino code (YUN)
|
||||
- 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 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
|
||||
@@ -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:
|
||||
|
||||
- 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.
|
||||
- Notifying the props 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.
|
||||
- Notifying the prop is done by publishing a message on its inbox topic.
|
||||
- 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* 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.
|
||||
|
||||
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 Rev 2**
|
||||
- **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 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
|
||||
@@ -85,9 +85,9 @@ Arduino with Ethernet or Wifi shield is suitable to build an Escape Room Props,
|
||||
- Arduino Ethernet
|
||||
- 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
|
||||
- Sparkfun WiFly Shield – [library](https://github.com/dpslwk/WiFly)
|
||||
- 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:
|
||||
* ***BridgeProps*** for Yun board and Yun shield
|
||||
* ***EthernetProps*** for Ethernet shield
|
||||
* ***WifiProps*** for WiFiNINA boards
|
||||
*Prop* is a base class for 3 connected prop, depending on their network interface:
|
||||
* ***BridgeProp*** for Yun board and Yun shield
|
||||
* ***EthernetProp*** for Ethernet shield
|
||||
* ***WifiProp*** for WiFiNINA boards
|
||||
|
||||
*Props* class reference:
|
||||
1. Define the *Props*
|
||||
* Defining a *BridgeProps*
|
||||
* Defining an *EthernetProps*
|
||||
* Defining a *WifiProps*
|
||||
2. Setup the *Props*
|
||||
*Prop* class reference:
|
||||
1. Define the *Prop*
|
||||
* Defining a *BridgeProp*
|
||||
* Defining an *EthernetProp*
|
||||
* Defining a *WifiProp*
|
||||
2. Setup the *Prop*
|
||||
* Change timings
|
||||
3. Call in sketch *loop()*
|
||||
4. Implement `InboxMessage::run()` callback
|
||||
5. Update broker address from SSH (*BridgeProps*)
|
||||
5. Update broker address from SSH (*BridgeProp*)
|
||||
6. Examples
|
||||
7. Compatible hardware
|
||||
|
||||
|
||||
## 1. Defines the *Props*
|
||||
Defining a Bridge (Yun), Ethernet or Wifi *Props* is slighlty different.
|
||||
## 1. Defines the *Prop*
|
||||
Defining a Bridge (Yun), Ethernet or Wifi *Prop* is slighlty different.
|
||||
|
||||
### Defining a *BridgeProps*
|
||||
### Defining a *BridgeProp*
|
||||
```csharp
|
||||
#include <Bridge.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
|
||||
// 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/outbox",
|
||||
"192.168.1.42", // your MQTT server IP address
|
||||
1883); // your MQTT server port;
|
||||
|
||||
PropsDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
||||
PropsDataLogical led(u8"led");
|
||||
PropDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
||||
PropDataLogical led(u8"led");
|
||||
|
||||
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>`.
|
||||
|
||||
### Defining an *EthernetProps*
|
||||
### Defining an *EthernetProp*
|
||||
```csharp
|
||||
#include <Ethernet.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
|
||||
// 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/outbox",
|
||||
"192.168.1.42", // your MQTT server IP address
|
||||
1883); // your MQTT server port;
|
||||
|
||||
PropsDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
||||
PropsDataLogical led(u8"led");
|
||||
PropDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
||||
PropDataLogical led(u8"led");
|
||||
|
||||
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 *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>`.
|
||||
|
||||
### Defining a *WifiProps*
|
||||
### Defining a *WifiProp*
|
||||
```csharp
|
||||
#include "ArduinoProps.h"
|
||||
|
||||
@@ -98,69 +98,69 @@ const char *passphrase = "";
|
||||
// prpos inbox/outbox syntax Room/[escape room name]/Props/[propsname]/inbox|outbox
|
||||
// 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/outbox",
|
||||
"192.168.1.42", // your MQTT server IP address
|
||||
1883); // your MQTT server port;
|
||||
|
||||
PropsDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
||||
PropsDataLogical led(u8"led");
|
||||
PropDataLogical clignoter(u8"clignote", u8"oui", u8"non", true);
|
||||
PropDataLogical led(u8"led");
|
||||
|
||||
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**.
|
||||
|
||||
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
|
||||
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:
|
||||
|
||||
Room 2.0 *inbox* topic:
|
||||
```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"
|
||||
```
|
||||
Room 2.0 *outbox* topic:
|
||||
```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"
|
||||
```
|
||||
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
|
||||
*PropsData* provides a facility to monitor data sent into MQTT outbox.
|
||||
#### *PropData* instances
|
||||
*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
|
||||
To maintain a non-blocking asynchronous behavior of your props, use *PropsAction* objects to trigger action periodically.
|
||||
#### *PropAction* instances
|
||||
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.
|
||||
|
||||
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.
|
||||
```csharp
|
||||
void setup()
|
||||
{
|
||||
// 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
|
||||
props.addData(&clignoter);
|
||||
props.addData(&led);
|
||||
prop.addData(&clignoter);
|
||||
prop.addData(&led);
|
||||
|
||||
props.begin(InboxMessage::run);
|
||||
prop.begin(InboxMessage::run);
|
||||
|
||||
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
|
||||
- call `props.begin(InboxMessage::run)`
|
||||
- add *PropData* references to the prop
|
||||
- call `prop.begin(InboxMessage::run)`
|
||||
|
||||
The setup code is slighlty different to start the network client (bridge, ethernet of wifi):
|
||||
```csharp
|
||||
void setup()
|
||||
{
|
||||
#if defined(BRIDGEPROPS_H)
|
||||
#if defined(BRIDGEPROP_H)
|
||||
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
|
||||
//Ethernet.setSubnetMask(IPAddress());
|
||||
//Ethernet.setGatewayIP(IPAddress());
|
||||
@@ -201,7 +201,7 @@ void setup()
|
||||
}
|
||||
delay(1500); // time for shield stuff
|
||||
|
||||
#elif defined(WIFIPROPS_H)
|
||||
#elif defined(WIFIPROP_H)
|
||||
// can do more static IP configuration
|
||||
//WiFi.config(IPAddress(), IPAddress(), IPAddress());
|
||||
//WiFi.config(IPAddress(), IPAddress());
|
||||
@@ -221,11 +221,11 @@ void setup()
|
||||
### Change timings
|
||||
Default timings are:
|
||||
* 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()`:
|
||||
```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
|
||||
void loop()
|
||||
{
|
||||
props.loop();
|
||||
prop.loop();
|
||||
|
||||
led.setValue(digitalRead(LED_BUILTIN)); // read I/O
|
||||
|
||||
@@ -243,7 +243,7 @@ void loop()
|
||||
```
|
||||
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
|
||||
@@ -255,40 +255,40 @@ void InboxMessage::run(String a) {
|
||||
|
||||
if (a == u8"app:startup")
|
||||
{
|
||||
props.sendAllData();
|
||||
props.sendDone(a);
|
||||
prop.sendAllData();
|
||||
prop.sendDone(a);
|
||||
}
|
||||
else if (a == "clignoter:1")
|
||||
{
|
||||
clignoter.setValue(true);
|
||||
|
||||
props.sendAllData(); // all data change, we don't have to be selctive then
|
||||
props.sendDone(a); // acknowledge props command action
|
||||
prop.sendAllData(); // all data change, we don't have to be selctive then
|
||||
prop.sendDone(a); // acknowledge prop command action
|
||||
}
|
||||
else if (a == "clignoter:0")
|
||||
{
|
||||
clignoter.setValue(false);
|
||||
|
||||
props.sendAllData(); // all data change, we don't have to be selctive then
|
||||
props.sendDone(a); // acknowledge props command action
|
||||
prop.sendAllData(); // all data change, we don't have to be selctive then
|
||||
prop.sendDone(a); // acknowledge prop command action
|
||||
}
|
||||
else
|
||||
{
|
||||
// acknowledge omition of the props command
|
||||
props.sendOmit(a);
|
||||
// acknowledge omition of the prop command
|
||||
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:
|
||||
```bash
|
||||
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
|
||||
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
|
||||
IPAddress ip;
|
||||
@@ -304,7 +304,7 @@ void updateBrokerAdressFromFile(const char* broker_file, BridgeProps* props)
|
||||
}
|
||||
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
|
||||
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*
|
||||
2. **BlinkOnEthernetProps**: the Blink example on an Ethernet props with *ArduinoProps library*
|
||||
3. **BlinkOnWifiProps**: the Blink example on a Wifi props with *ArduinoProps library*
|
||||
4. **BlinkOnBridgePubSub**: the Blink example on props using *PubSubClient* directly
|
||||
1. **BlinkOnBridgeProps**: the Blink example on a Yun prop with *ArduinoProps library*
|
||||
2. **BlinkOnEthernetProps**: the Blink example on an Ethernet prop with *ArduinoProps library*
|
||||
3. **BlinkOnWifiProps**: the Blink example on a Wifi prop with *ArduinoProps library*
|
||||
4. **BlinkOnBridgePubSub**: the Blink example on prop using *PubSubClient* directly
|
||||
|
||||
|
||||
## 7. Compatible hardware
|
||||
@@ -331,9 +331,9 @@ See [EXAMPLES.md](../EXAMPLES.md) for an adaptation of the Blink example (https:
|
||||
- Arduino Ethernet
|
||||
- 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
|
||||
- Sparkfun WiFly Shield – [library](https://github.com/dpslwk/WiFly)
|
||||
- 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
|
||||
* `PropsAction()`
|
||||
* `PropsAction(unsigned long interval, void (*function)())`
|
||||
* `PropAction()`
|
||||
* `PropAction(unsigned long interval, void (*function)())`
|
||||
|
||||
`function` is the callback executed at every `interval` milliseconds.
|
||||
|
||||
@@ -30,9 +30,9 @@ void clignote()
|
||||
}
|
||||
```
|
||||
|
||||
### Create a *PropsAction* instance
|
||||
### Create a *PropAction* instance
|
||||
```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()`
|
||||
@@ -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
|
||||
BridgeProps KEYWORD1
|
||||
EthernetProps KEYWORD1
|
||||
WifiProps KEYWORD1
|
||||
PropsAction KEYWORD1
|
||||
PropsData KEYWORD1
|
||||
PropsDataDecimal KEYWORD1
|
||||
PropsDataInteger KEYWORD1
|
||||
PropsDataLogical KEYWORD1
|
||||
PropsDataText KEYWORD1
|
||||
BridgeProp KEYWORD1
|
||||
EthernetProp KEYWORD1
|
||||
WifiProp KEYWORD1
|
||||
PropAction KEYWORD1
|
||||
PropData KEYWORD1
|
||||
PropDataDecimal KEYWORD1
|
||||
PropDataInteger KEYWORD1
|
||||
PropDataLogical KEYWORD1
|
||||
PropDataText KEYWORD1
|
||||
PropsCallback KEYWORD1
|
||||
PropsMessageReceived KEYWORD1
|
||||
InboxMessage KEYWORD1
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
Editor: https://github.com/fauresystems
|
||||
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"
|
||||
|
||||
+6
-6
@@ -5,7 +5,7 @@
|
||||
Editor: https://github.com/fauresystems
|
||||
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
|
||||
@@ -17,10 +17,10 @@
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#include "BridgeProps.h"
|
||||
#include "EthernetProps.h"
|
||||
#include "WifiProps.h"
|
||||
#include "PropsAction.h"
|
||||
#include "PropsData.h"
|
||||
#include "BridgeProp.h"
|
||||
#include "EthernetProp.h"
|
||||
#include "WifiProp.h"
|
||||
#include "PropAction.h"
|
||||
#include "PropData.h"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Name: BridgeProps.cpp
|
||||
Name: BridgeProp.cpp
|
||||
Created: 29/10/2019 09:20:31
|
||||
Author: Marie Faure <dev at faure dot systems>
|
||||
Editor: https://github.com/fauresystems
|
||||
@@ -8,20 +8,20 @@
|
||||
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)
|
||||
{
|
||||
_client.setClient(_bridgeClient);
|
||||
}
|
||||
|
||||
void BridgeProps::begin(void(*on_message)(String))
|
||||
void BridgeProp::begin(void(*on_message)(String))
|
||||
{
|
||||
if (on_message) onInboxMessageReceived = on_message;
|
||||
}
|
||||
|
||||
void BridgeProps::setBrokerIpAddress(IPAddress ip, uint16_t port)
|
||||
void BridgeProp::setBrokerIpAddress(IPAddress ip, uint16_t port)
|
||||
{
|
||||
_brokerIpAddress = ip;
|
||||
_client.setServer(_brokerIpAddress, port);
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Name: BridgeProps.h
|
||||
Name: BridgeProp.h
|
||||
Created: 29/10/2019 09:20:31
|
||||
Author: Marie Faure <dev at faure dot systems>
|
||||
Editor: https://github.com/fauresystems
|
||||
@@ -7,17 +7,17 @@
|
||||
|
||||
Class Props for Arduino Yun and Dragino Yun shield.
|
||||
*/
|
||||
#ifndef BRIDGEPROPS_H
|
||||
#define BRIDGEPROPS_H
|
||||
#ifndef BRIDGEPROP_H
|
||||
#define BRIDGEPROP_H
|
||||
|
||||
#include <BridgeClient.h>
|
||||
#include <IPAddress.h>
|
||||
#include "Props.h"
|
||||
#include "Prop.h"
|
||||
|
||||
class BridgeProps : public Props
|
||||
class BridgeProp : public Props
|
||||
{
|
||||
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 setBrokerIpAddress(IPAddress, uint16_t port = 1883);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Name: EthernetProps.cpp
|
||||
Name: EthernetProp.cpp
|
||||
Created: 29/10/2019 09:20:31
|
||||
Author: Marie Faure <dev at faure dot systems>
|
||||
Editor: https://github.com/fauresystems
|
||||
@@ -8,15 +8,15 @@
|
||||
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)
|
||||
{
|
||||
_client.setClient(_ethernetClient);
|
||||
}
|
||||
|
||||
void EthernetProps::begin(void(*on_message)(String))
|
||||
void EthernetProp::begin(void(*on_message)(String))
|
||||
{
|
||||
if (on_message) onInboxMessageReceived = on_message;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Name: EthernetProps.h
|
||||
Name: EthernetProp.h
|
||||
Created: 29/10/2019 09:20:31
|
||||
Author: Marie Faure <dev at faure dot systems>
|
||||
Editor: https://github.com/fauresystems
|
||||
@@ -7,19 +7,19 @@
|
||||
|
||||
Class Props for Arduino with Ethernet shield.
|
||||
*/
|
||||
#ifndef ETHERNETPROPS_H
|
||||
#define ETHERNETPROPS_H
|
||||
#ifndef ETHERNETPROP_H
|
||||
#define ETHERNETPROP_H
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <EthernetClient.h>
|
||||
#include "Props.h"
|
||||
#include "Prop.h"
|
||||
|
||||
class EthernetProps : public Props
|
||||
class EthernetProp : public Props
|
||||
{
|
||||
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);
|
||||
|
||||
private:
|
||||
@@ -5,10 +5,10 @@
|
||||
Editor: https://github.com/fauresystems
|
||||
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>
|
||||
#if defined(__AVR__)
|
||||
#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
|
||||
}
|
||||
|
||||
void Props::addData(PropsData* d)
|
||||
void Props::addData(PropData* d)
|
||||
{
|
||||
_dataTable.Add(d);
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
/*
|
||||
Name: Props.h
|
||||
Name: Prop.h
|
||||
Created: 29/10/2019 09:20:31
|
||||
Author: Marie Faure <dev at faure dot systems>
|
||||
Editor: https://github.com/fauresystems
|
||||
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
|
||||
#define PROPS_H
|
||||
#ifndef PROP_H
|
||||
#define PROP_H
|
||||
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "arduino.h"
|
||||
@@ -19,8 +19,8 @@
|
||||
#include <BridgeClient.h>
|
||||
#include <PubSubClient.h>
|
||||
#include <ListLib.h>
|
||||
#include "PropsAction.h"
|
||||
#include "PropsData.h"
|
||||
#include "PropAction.h"
|
||||
#include "PropData.h"
|
||||
|
||||
#ifndef MQTT_MAX_PACKET_SIZE
|
||||
#define MQTT_MAX_PACKET_SIZE 128 // Bridge tranfer stuff (see PubSubClient)
|
||||
@@ -53,7 +53,7 @@ class Props
|
||||
public:
|
||||
Props(const char*, const char*, const char*, const char*, const int=1883);
|
||||
virtual void begin(void(*)(String) = NULL) = 0;
|
||||
void addData(PropsData*);
|
||||
void addData(PropData*);
|
||||
void loop();
|
||||
void resetIntervals(const int changes, const int silent);
|
||||
void resetMcu();
|
||||
@@ -86,8 +86,8 @@ class Props
|
||||
uint8_t _maximumSilentPeriod;
|
||||
unsigned long _nextReconAttempt;
|
||||
uint8_t _payloadMax;
|
||||
PropsAction _sendDataAction;
|
||||
List<PropsData*> _dataTable;
|
||||
PropAction _sendDataAction;
|
||||
List<PropData*> _dataTable;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Name: PropsAction.h
|
||||
Name: PropAction.h
|
||||
Created: 29/10/2019 09:20:31
|
||||
Author: Marie Faure <dev at faure dot systems>
|
||||
Editor: https://github.com/fauresystems
|
||||
@@ -8,9 +8,9 @@
|
||||
Provide an easy way of triggering functions at a set _interval.
|
||||
*/
|
||||
|
||||
#include "PropsAction.h"
|
||||
#include "PropAction.h"
|
||||
|
||||
PropsAction::PropsAction()
|
||||
PropAction::PropAction()
|
||||
{
|
||||
_active = true;
|
||||
_previous = 0;
|
||||
@@ -18,7 +18,7 @@ PropsAction::PropsAction()
|
||||
_execute = NULL;
|
||||
}
|
||||
|
||||
PropsAction::PropsAction(unsigned long intervl, void (*function)())
|
||||
PropAction::PropAction(unsigned long intervl, void (*function)())
|
||||
{
|
||||
_active = true;
|
||||
_previous = 0;
|
||||
@@ -26,24 +26,24 @@ PropsAction::PropsAction(unsigned long intervl, void (*function)())
|
||||
_execute = function;
|
||||
}
|
||||
|
||||
void PropsAction::reset(unsigned long intervl)
|
||||
void PropAction::reset(unsigned long intervl)
|
||||
{
|
||||
_active = true;
|
||||
_previous = 0;
|
||||
_interval = intervl;
|
||||
}
|
||||
|
||||
void PropsAction::disable()
|
||||
void PropAction::disable()
|
||||
{
|
||||
_active = false;
|
||||
}
|
||||
|
||||
void PropsAction::enable()
|
||||
void PropAction::enable()
|
||||
{
|
||||
_active = true;
|
||||
}
|
||||
|
||||
void PropsAction::check() {
|
||||
void PropAction::check() {
|
||||
if (_active && (millis() - _previous >= _interval))
|
||||
{
|
||||
_previous = millis();
|
||||
@@ -51,7 +51,7 @@ void PropsAction::check() {
|
||||
}
|
||||
}
|
||||
|
||||
bool PropsAction::tick() {
|
||||
bool PropAction::tick() {
|
||||
if (_active && (millis() - _previous >= _interval))
|
||||
{
|
||||
_previous = millis();
|
||||
@@ -60,7 +60,7 @@ bool PropsAction::tick() {
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned long PropsAction::getInterval()
|
||||
unsigned long PropAction::getInterval()
|
||||
{
|
||||
return _interval;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Name: PropsAction.h
|
||||
Name: PropAction.h
|
||||
Created: 29/10/2019 09:20:31
|
||||
Author: Marie Faure <dev at faure dot systems>
|
||||
Editor: https://github.com/fauresystems
|
||||
@@ -19,11 +19,11 @@
|
||||
|
||||
class Props;
|
||||
|
||||
class PropsAction {
|
||||
class PropAction {
|
||||
|
||||
public:
|
||||
PropsAction();
|
||||
PropsAction(unsigned long interval, void (*function)());
|
||||
PropAction();
|
||||
PropAction(unsigned long interval, void (*function)());
|
||||
|
||||
void reset(unsigned long interval);
|
||||
void disable();
|
||||
@@ -1,18 +1,18 @@
|
||||
/*
|
||||
Name: PropsData.cpp
|
||||
Name: PropData.cpp
|
||||
Created: 29/10/2019 09:20:31
|
||||
Author: Marie Faure <dev at faure dot systems>
|
||||
Editor: https://github.com/fauresystems
|
||||
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>
|
||||
|
||||
// ---- 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;
|
||||
_current = initial;
|
||||
_previous = _current;
|
||||
@@ -20,12 +20,12 @@ PropsDataDecimal::PropsDataDecimal(const char * id, uint8_t digits, double preci
|
||||
_digits = digits;
|
||||
}
|
||||
|
||||
String PropsDataDecimal::fetch() {
|
||||
String PropDataDecimal::fetch() {
|
||||
_previous = _current;
|
||||
return String(_id) + "=" + String(_current, _digits) + " ";
|
||||
}
|
||||
|
||||
String PropsDataDecimal::fetchChange() {
|
||||
String PropDataDecimal::fetchChange() {
|
||||
if (_current != _previous && _current && abs(_current - _previous) / _current >= _precision) {
|
||||
return fetch();
|
||||
}
|
||||
@@ -35,28 +35,28 @@ String PropsDataDecimal::fetchChange() {
|
||||
return String();
|
||||
}
|
||||
|
||||
void PropsDataDecimal::setValue(const double v) {
|
||||
void PropDataDecimal::setValue(const double v) {
|
||||
_current = v;
|
||||
}
|
||||
|
||||
double PropsDataDecimal::value() const {
|
||||
double PropDataDecimal::value() const {
|
||||
return _current;
|
||||
}
|
||||
|
||||
// ---- Integer
|
||||
PropsDataInteger::PropsDataInteger(const char * id, double precision, long initial) {
|
||||
PropDataInteger::PropDataInteger(const char * id, double precision, long initial) {
|
||||
_id = id;
|
||||
_current = initial;
|
||||
_previous = _current;
|
||||
_precision = precision;
|
||||
}
|
||||
|
||||
String PropsDataInteger::fetch() {
|
||||
String PropDataInteger::fetch() {
|
||||
_previous = _current;
|
||||
return String(_id) + "=" + String(_current) + " ";
|
||||
}
|
||||
|
||||
String PropsDataInteger::fetchChange() {
|
||||
String PropDataInteger::fetchChange() {
|
||||
if (_current != _previous && _current && abs(_current - _previous) / _current >= _precision) {
|
||||
return fetch();
|
||||
}
|
||||
@@ -66,16 +66,16 @@ String PropsDataInteger::fetchChange() {
|
||||
return String();
|
||||
}
|
||||
|
||||
void PropsDataInteger::setValue(const long v) {
|
||||
void PropDataInteger::setValue(const long v) {
|
||||
_current = v;
|
||||
}
|
||||
|
||||
long PropsDataInteger::value() const {
|
||||
long PropDataInteger::value() const {
|
||||
return _current;
|
||||
}
|
||||
|
||||
// ---- 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;
|
||||
_current = initial;
|
||||
_previous = _current;
|
||||
@@ -83,7 +83,7 @@ PropsDataLogical::PropsDataLogical(const char * id, const char *trueval, const c
|
||||
_falseString = falseval;
|
||||
}
|
||||
|
||||
String PropsDataLogical::fetch() {
|
||||
String PropDataLogical::fetch() {
|
||||
String str(String(_id) + "=");
|
||||
if (_current) {
|
||||
str += _trueString ? _trueString : "1";
|
||||
@@ -95,42 +95,42 @@ String PropsDataLogical::fetch() {
|
||||
return str;
|
||||
}
|
||||
|
||||
String PropsDataLogical::fetchChange() {
|
||||
String PropDataLogical::fetchChange() {
|
||||
if (_current != _previous) {
|
||||
return fetch();
|
||||
}
|
||||
return String();
|
||||
}
|
||||
|
||||
void PropsDataLogical::setValue(const bool v) {
|
||||
void PropDataLogical::setValue(const bool v) {
|
||||
_current = v;
|
||||
}
|
||||
|
||||
bool PropsDataLogical::value() const {
|
||||
bool PropDataLogical::value() const {
|
||||
return _current;
|
||||
}
|
||||
|
||||
// ---- Text
|
||||
PropsDataText::PropsDataText(const char * id) {
|
||||
PropDataText::PropDataText(const char * id) {
|
||||
_id = id;
|
||||
}
|
||||
|
||||
String PropsDataText::fetch() {
|
||||
String PropDataText::fetch() {
|
||||
_previous = _current;
|
||||
return String(_id) + "=" + _current + " ";
|
||||
}
|
||||
|
||||
String PropsDataText::fetchChange() {
|
||||
String PropDataText::fetchChange() {
|
||||
if (_current != _previous) {
|
||||
return fetch();
|
||||
}
|
||||
return String();
|
||||
}
|
||||
|
||||
void PropsDataText::setValue(String v) {
|
||||
void PropDataText::setValue(String v) {
|
||||
_current = v;
|
||||
}
|
||||
|
||||
String PropsDataText::value() const {
|
||||
String PropDataText::value() const {
|
||||
return _current;
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
Name: PropsData.h
|
||||
Name: PropData.h
|
||||
Created: 29/10/2019 09:20:31
|
||||
Author: Marie Faure <dev at faure dot systems>
|
||||
Editor: https://github.com/fauresystems
|
||||
License: MIT License (c) Marie Faure <dev at faure dot systems>
|
||||
|
||||
Variable wrapper for connected props.
|
||||
Variable wrapper for connected prop.
|
||||
*/
|
||||
#ifndef PROPSDATA_H
|
||||
#define PROPSDATA_H
|
||||
@@ -19,17 +19,17 @@
|
||||
#include <inttypes.h>
|
||||
#include <WString.h>
|
||||
|
||||
class PropsData
|
||||
class PropData
|
||||
{
|
||||
public:
|
||||
virtual String fetch() = 0;
|
||||
virtual String fetchChange() = 0;
|
||||
};
|
||||
|
||||
class PropsDataDecimal : public PropsData
|
||||
class PropDataDecimal : public PropData
|
||||
{
|
||||
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 fetchChange();
|
||||
void setValue(const double);
|
||||
@@ -42,10 +42,10 @@ class PropsDataDecimal : public PropsData
|
||||
uint8_t _digits;
|
||||
};
|
||||
|
||||
class PropsDataInteger : public PropsData
|
||||
class PropDataInteger : public PropData
|
||||
{
|
||||
public:
|
||||
PropsDataInteger(const char *, double precision = 0.1, long initial = 0);
|
||||
PropDataInteger(const char *, double precision = 0.1, long initial = 0);
|
||||
String fetch();
|
||||
String fetchChange();
|
||||
void setValue(const long);
|
||||
@@ -57,10 +57,10 @@ class PropsDataInteger : public PropsData
|
||||
double _precision;
|
||||
};
|
||||
|
||||
class PropsDataLogical : public PropsData
|
||||
class PropDataLogical : public PropData
|
||||
{
|
||||
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 fetchChange();
|
||||
void setValue(const bool);
|
||||
@@ -73,10 +73,10 @@ class PropsDataLogical : public PropsData
|
||||
const char *_falseString;
|
||||
};
|
||||
|
||||
class PropsDataText : public PropsData
|
||||
class PropDataText : public PropData
|
||||
{
|
||||
public:
|
||||
PropsDataText(const char *);
|
||||
PropDataText(const char *);
|
||||
String fetch();
|
||||
String fetchChange();
|
||||
void setValue(String);
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Name: WifiProps.cpp
|
||||
Name: WifiProp.cpp
|
||||
Created: 29/10/2019 09:20:31
|
||||
Author: Marie Faure <dev at faure dot systems>
|
||||
Editor: https://github.com/fauresystems
|
||||
@@ -8,19 +8,19 @@
|
||||
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)
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
_client.setClient(_wifiClient);
|
||||
}
|
||||
|
||||
void WifiProps::begin(void(*on_message)(String))
|
||||
void WifiProp::begin(void(*on_message)(String))
|
||||
{
|
||||
if (on_message) onInboxMessageReceived = on_message;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Name: WifiProps.h
|
||||
Name: WifiProp.h
|
||||
Created: 29/10/2019 09:20:31
|
||||
Author: Marie Faure <dev at faure dot systems>
|
||||
Editor: https://github.com/fauresystems
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
Class Props for Arduino with WiFiNINA.
|
||||
*/
|
||||
#ifndef WIFIPROPS_H
|
||||
#define WIFIPROPS_H
|
||||
#ifndef WIFIPROP_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)
|
||||
@@ -18,12 +18,12 @@
|
||||
|
||||
#include <SPI.h>
|
||||
#include <WiFiClient.h>
|
||||
#include "Props.h"
|
||||
#include "Prop.h"
|
||||
|
||||
class WifiProps : public Props
|
||||
class WifiProp : public Props
|
||||
{
|
||||
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);
|
||||
|
||||
private:
|
||||
Reference in New Issue
Block a user