Skip to content

Commit 7af3a10

Browse files
committed
1 parent 3f69bcf commit 7af3a10

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

Diff for: libraries/RainMaker/examples/RMakerSonoffDualR3/RMakerSonoffDualR3.ino

+19-16
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@ LightSwitch switch_ch1 = {gpio_switch1, false};
3131
LightSwitch switch_ch2 = {gpio_switch2, false};
3232

3333
//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;
3636

3737
void sysProvEvent(arduino_event_t *sys_event)
3838
{
39-
switch (sys_event->event_id) {
39+
switch (sys_event->event_id) {
4040
case ARDUINO_EVENT_PROV_START:
4141
#if CONFIG_IDF_TARGET_ESP32
4242
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop);
4343
printQR(service_name, pop, "ble");
4444
#else
4545
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop);
4646
printQR(service_name, pop, "softap");
47-
#endif
47+
#endif
4848
break;
4949
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
5050
Serial.printf("\nConnected to Wi-Fi!\n");
@@ -60,18 +60,18 @@ void write_callback(Device *device, Param *param, const param_val_t val, void *p
6060
const char *param_name = param->getParamName();
6161

6262
if(strcmp(device_name, "Switch_ch1") == 0) {
63-
63+
6464
Serial.printf("Lightbulb = %s\n", val.val.b? "true" : "false");
65-
65+
6666
if(strcmp(param_name, "Power") == 0) {
6767
Serial.printf("Received value = %s for %s - %s\n", val.val.b? "true" : "false", device_name, param_name);
6868
switch_state_ch1 = val.val.b;
6969
(switch_state_ch1 == false) ? digitalWrite(gpio_relay1, LOW) : digitalWrite(gpio_relay1, HIGH);
7070
param->updateAndReport(val);
7171
}
72-
72+
7373
} else if(strcmp(device_name, "Switch_ch2") == 0) {
74-
74+
7575
Serial.printf("Switch value = %s\n", val.val.b? "true" : "false");
7676

7777
if(strcmp(param_name, "Power") == 0) {
@@ -80,9 +80,9 @@ void write_callback(Device *device, Param *param, const param_val_t val, void *p
8080
(switch_state_ch2 == false) ? digitalWrite(gpio_relay2, LOW) : digitalWrite(gpio_relay2, HIGH);
8181
param->updateAndReport(val);
8282
}
83-
83+
8484
}
85-
85+
8686
}
8787

8888
void ARDUINO_ISR_ATTR isr(void* arg) {
@@ -92,8 +92,11 @@ void ARDUINO_ISR_ATTR isr(void* arg) {
9292

9393
void setup()
9494
{
95+
my_switch1 = Switch("Switch_ch1", &gpio_relay1);
96+
my_switch2 = Switch("Switch_ch2", &gpio_relay2);
97+
9598
uint32_t chipId = 0;
96-
99+
97100
Serial.begin(115200);
98101

99102
// Configure the input GPIOs
@@ -102,7 +105,7 @@ void setup()
102105
attachInterruptArg(switch_ch1.pin, isr, &switch_ch1, CHANGE);
103106
pinMode(switch_ch2.pin, INPUT_PULLUP);
104107
attachInterruptArg(switch_ch2.pin, isr, &switch_ch2, CHANGE);
105-
108+
106109
// Set the Relays GPIOs as output mode
107110
pinMode(gpio_relay1, OUTPUT);
108111
pinMode(gpio_relay2, OUTPUT);
@@ -112,20 +115,20 @@ void setup()
112115
digitalWrite(gpio_relay2, DEFAULT_POWER_MODE);
113116
digitalWrite(gpio_led, false);
114117

115-
Node my_node;
118+
Node my_node;
116119
my_node = RMaker.initNode("Sonoff Dual R3");
117120

118121
//Standard switch device
119122
my_switch1.addCb(write_callback);
120123
my_switch2.addCb(write_callback);
121124

122-
//Add switch device to the node
125+
//Add switch device to the node
123126
my_node.addDevice(my_switch1);
124127
my_node.addDevice(my_switch2);
125128

126-
//This is optional
129+
//This is optional
127130
RMaker.enableOTA(OTA_USING_PARAMS);
128-
//If you want to enable scheduling, set time zone for your region using setTimeZone().
131+
//If you want to enable scheduling, set time zone for your region using setTimeZone().
129132
//The list of available values are provided here https://rainmaker.espressif.com/docs/time-service.html
130133
// RMaker.setTimeZone("Asia/Shanghai");
131134
// Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone

Diff for: libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino

+9-8
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ static int gpio_switch = 16;
2121
bool switch_state = true;
2222

2323
//The framework provides some standard device types like switch, lightbulb, fan, temperaturesensor.
24-
static Switch my_switch("Switch", &gpio_switch);
24+
static Switch my_switch;
2525

2626
void sysProvEvent(arduino_event_t *sys_event)
2727
{
28-
switch (sys_event->event_id) {
28+
switch (sys_event->event_id) {
2929
case ARDUINO_EVENT_PROV_START:
3030
#if CONFIG_IDF_TARGET_ESP32S2
3131
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop);
3232
printQR(service_name, pop, "softap");
3333
#else
3434
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop);
3535
printQR(service_name, pop, "ble");
36-
#endif
36+
#endif
3737
break;
3838
default:;
3939
}
@@ -54,23 +54,24 @@ void write_callback(Device *device, Param *param, const param_val_t val, void *p
5454

5555
void setup()
5656
{
57+
my_switch = Switch("Switch", &gpio_switch);
5758
Serial.begin(115200);
5859
pinMode(gpio_0, INPUT);
5960
pinMode(gpio_switch, OUTPUT);
6061
digitalWrite(gpio_switch, DEFAULT_POWER_MODE);
6162

62-
Node my_node;
63+
Node my_node;
6364
my_node = RMaker.initNode("ESP RainMaker Node");
6465

6566
//Standard switch device
6667
my_switch.addCb(write_callback);
67-
68-
//Add switch device to the node
68+
69+
//Add switch device to the node
6970
my_node.addDevice(my_switch);
7071

71-
//This is optional
72+
//This is optional
7273
RMaker.enableOTA(OTA_USING_PARAMS);
73-
//If you want to enable scheduling, set time zone for your region using setTimeZone().
74+
//If you want to enable scheduling, set time zone for your region using setTimeZone().
7475
//The list of available values are provided here https://rainmaker.espressif.com/docs/time-service.html
7576
// RMaker.setTimeZone("Asia/Shanghai");
7677
// Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone

0 commit comments

Comments
 (0)