@@ -31,20 +31,20 @@ LightSwitch switch_ch1 = {gpio_switch1, false};
31
31
LightSwitch switch_ch2 = {gpio_switch2, false };
32
32
33
33
// The framework provides some standard device types like switch, lightbulb, fan, temperature sensor.
34
- static Switch my_switch1 ( " Switch_ch1 " , &gpio_relay1) ;
35
- static Switch my_switch2 ( " Switch_ch2 " , &gpio_relay2) ;
34
+ static Switch my_switch1;
35
+ static Switch my_switch2;
36
36
37
37
void sysProvEvent (arduino_event_t *sys_event)
38
38
{
39
- switch (sys_event->event_id ) {
39
+ switch (sys_event->event_id ) {
40
40
case ARDUINO_EVENT_PROV_START:
41
41
#if CONFIG_IDF_TARGET_ESP32
42
42
Serial.printf (" \n Provisioning Started with name \" %s\" and PoP \" %s\" on BLE\n " , service_name, pop);
43
43
printQR (service_name, pop, " ble" );
44
44
#else
45
45
Serial.printf (" \n Provisioning Started with name \" %s\" and PoP \" %s\" on SoftAP\n " , service_name, pop);
46
46
printQR (service_name, pop, " softap" );
47
- #endif
47
+ #endif
48
48
break ;
49
49
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
50
50
Serial.printf (" \n Connected to Wi-Fi!\n " );
@@ -60,18 +60,18 @@ void write_callback(Device *device, Param *param, const param_val_t val, void *p
60
60
const char *param_name = param->getParamName ();
61
61
62
62
if (strcmp (device_name, " Switch_ch1" ) == 0 ) {
63
-
63
+
64
64
Serial.printf (" Lightbulb = %s\n " , val.val .b ? " true" : " false" );
65
-
65
+
66
66
if (strcmp (param_name, " Power" ) == 0 ) {
67
67
Serial.printf (" Received value = %s for %s - %s\n " , val.val .b ? " true" : " false" , device_name, param_name);
68
68
switch_state_ch1 = val.val .b ;
69
69
(switch_state_ch1 == false ) ? digitalWrite (gpio_relay1, LOW) : digitalWrite (gpio_relay1, HIGH);
70
70
param->updateAndReport (val);
71
71
}
72
-
72
+
73
73
} else if (strcmp (device_name, " Switch_ch2" ) == 0 ) {
74
-
74
+
75
75
Serial.printf (" Switch value = %s\n " , val.val .b ? " true" : " false" );
76
76
77
77
if (strcmp (param_name, " Power" ) == 0 ) {
@@ -80,9 +80,9 @@ void write_callback(Device *device, Param *param, const param_val_t val, void *p
80
80
(switch_state_ch2 == false ) ? digitalWrite (gpio_relay2, LOW) : digitalWrite (gpio_relay2, HIGH);
81
81
param->updateAndReport (val);
82
82
}
83
-
83
+
84
84
}
85
-
85
+
86
86
}
87
87
88
88
void ARDUINO_ISR_ATTR isr (void * arg) {
@@ -92,8 +92,9 @@ void ARDUINO_ISR_ATTR isr(void* arg) {
92
92
93
93
void setup ()
94
94
{
95
+
95
96
uint32_t chipId = 0 ;
96
-
97
+
97
98
Serial.begin (115200 );
98
99
99
100
// Configure the input GPIOs
@@ -102,7 +103,7 @@ void setup()
102
103
attachInterruptArg (switch_ch1.pin , isr, &switch_ch1, CHANGE);
103
104
pinMode (switch_ch2.pin , INPUT_PULLUP);
104
105
attachInterruptArg (switch_ch2.pin , isr, &switch_ch2, CHANGE);
105
-
106
+
106
107
// Set the Relays GPIOs as output mode
107
108
pinMode (gpio_relay1, OUTPUT);
108
109
pinMode (gpio_relay2, OUTPUT);
@@ -112,20 +113,24 @@ void setup()
112
113
digitalWrite (gpio_relay2, DEFAULT_POWER_MODE);
113
114
digitalWrite (gpio_led, false );
114
115
115
- Node my_node;
116
+ Node my_node;
116
117
my_node = RMaker.initNode (" Sonoff Dual R3" );
117
118
119
+ // Initialize switch device
120
+ my_switch1 = Switch (" Switch_ch1" , &gpio_relay1);
121
+ my_switch2 = Switch (" Switch_ch2" , &gpio_relay2);
122
+
118
123
// Standard switch device
119
124
my_switch1.addCb (write_callback);
120
125
my_switch2.addCb (write_callback);
121
126
122
- // Add switch device to the node
127
+ // Add switch device to the node
123
128
my_node.addDevice (my_switch1);
124
129
my_node.addDevice (my_switch2);
125
130
126
- // This is optional
131
+ // This is optional
127
132
RMaker.enableOTA (OTA_USING_PARAMS);
128
- // If you want to enable scheduling, set time zone for your region using setTimeZone().
133
+ // If you want to enable scheduling, set time zone for your region using setTimeZone().
129
134
// The list of available values are provided here https://rainmaker.espressif.com/docs/time-service.html
130
135
// RMaker.setTimeZone("Asia/Shanghai");
131
136
// Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone
0 commit comments