3
3
4
4
Set SECRET_SSID and SECRET_PASS in arduino_secrets.h
5
5
6
- Requirements:
6
+ Requirements:
7
7
- install ArduinoProps.zip library and dependencies (https://github.com/fauresystems/ArduinoProps)
8
8
- help: https://github.com/xcape-io/ArduinoProps/blob/master/help/ArduinoProps_sketch.md
9
9
*/
@@ -15,10 +15,10 @@ char ssid[] = SECRET_SSID; // your network SSID (name)
15
15
char pass[] = SECRET_PASS; // your network password (use for WPA)
16
16
17
17
WifiProp prop (u8" Arduino Lights" , // as MQTT client id, should be unique per client for given broker
18
- u8" Room/My room/Props/Arduino Lights/inbox" ,
19
- u8" Room/My room/Props/Arduino Lights/outbox" ,
20
- " 192.168.1.53" , // your MQTT server IP address
21
- 1883 ); // your MQTT server port;
18
+ u8" Room/My room/Props/Arduino Lights/inbox" ,
19
+ u8" Room/My room/Props/Arduino Lights/outbox" ,
20
+ " 192.168.1.53" , // your MQTT server IP address
21
+ 1883 ); // your MQTT server port;
22
22
23
23
// Relays pinout
24
24
#define LIGHT1 0
@@ -28,26 +28,38 @@ WifiProp prop(u8"Arduino Lights", // as MQTT client id, should be unique per cli
28
28
#define LIGHT5 4
29
29
#define LIGHT6 5
30
30
31
- PropDataLogical blinking (u8" blink" , u8" yes" , u8" no" , true );
32
- PropDataLogical led (u8" led" );
31
+ PropDataLogical lighting (u8" lighting" , u8" yes" , u8" no" , false );
32
+ PropDataLogical light1 (u8" light1" );
33
+ PropDataLogical light2 (u8" light2" );
34
+ PropDataLogical light3 (u8" light3" );
35
+ PropDataLogical light4 (u8" light4" );
36
+ PropDataLogical light5 (u8" light5" );
37
+ PropDataLogical light6 (u8" light6" );
33
38
PropDataText rssi (u8" rssi" );
34
39
35
- void blink (); // forward
36
- PropAction blinkAction = PropAction(1000 , blink);
37
-
38
40
bool wifiBegun (false );
39
41
40
42
void setup ()
41
43
{
42
44
Serial.begin (9600 );
43
45
44
- prop.addData (&blinking);
45
- prop.addData (&led);
46
+ prop.addData (&lighting);
47
+ prop.addData (&light1);
48
+ prop.addData (&light2);
49
+ prop.addData (&light3);
50
+ prop.addData (&light4);
51
+ prop.addData (&light5);
52
+ prop.addData (&light6);
46
53
prop.addData (&rssi);
47
-
54
+
48
55
prop.begin (InboxMessage::run);
49
56
50
- pinMode (LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output
57
+ pinMode (LIGHT1, OUTPUT);
58
+ pinMode (LIGHT2, OUTPUT);
59
+ pinMode (LIGHT3, OUTPUT);
60
+ pinMode (LIGHT4, OUTPUT);
61
+ pinMode (LIGHT5, OUTPUT);
62
+ pinMode (LIGHT6, OUTPUT);
51
63
52
64
// At this point, the broker is not connected yet
53
65
}
@@ -87,17 +99,12 @@ void loop()
87
99
88
100
rssi.setValue (WiFi.RSSI () + String (" dBm" )); // https://www.metageek.com/training/resources/understanding-rssi.html
89
101
90
- led.setValue (digitalRead (LED_BUILTIN)); // read I/O
91
-
92
- blinkAction.check (); // do your stuff, don't freeze the loop with delay() calls
93
- }
94
-
95
- void blink ()
96
- {
97
- if (blinking.value ()) {
98
- led.setValue (!led.value ());
99
- digitalWrite (LED_BUILTIN, led.value () ? HIGH : LOW);
100
- }
102
+ light1.setValue (digitalRead (LIGHT1)); // read I/O
103
+ light2.setValue (digitalRead (LIGHT2));
104
+ light3.setValue (digitalRead (LIGHT3));
105
+ light4.setValue (digitalRead (LIGHT4));
106
+ light5.setValue (digitalRead (LIGHT5));
107
+ light6.setValue (digitalRead (LIGHT6));
101
108
}
102
109
103
110
void InboxMessage::run (String a) {
@@ -111,16 +118,16 @@ void InboxMessage::run(String a) {
111
118
{
112
119
prop.resetMcu ();
113
120
}
114
- else if (a == " blink :1" )
121
+ else if (a == " lighting :1" )
115
122
{
116
- blinking. setValue ( true );
123
+
117
124
118
125
prop.sendAllData (); // all data change, we don't have to be selctive then
119
126
prop.sendDone (a); // acknowledge prop command action
120
127
}
121
- else if (a == " blink :0" )
128
+ else if (a == " lighting :0" )
122
129
{
123
- blinking. setValue ( false );
130
+
124
131
125
132
prop.sendAllData (); // all data change, we don't have to be selctive then
126
133
prop.sendDone (a); // acknowledge prop command action
0 commit comments