Skip to content

Commit 77065bf

Browse files
1 parent 01e2229 commit 77065bf

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

libraries/RainMaker/examples/RMakerSonoffDualR3/RMakerSonoffDualR3.ino

+21-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,9 @@ void ARDUINO_ISR_ATTR isr(void* arg) {
9292

9393
void setup()
9494
{
95+
9596
uint32_t chipId = 0;
96-
97+
9798
Serial.begin(115200);
9899

99100
// Configure the input GPIOs
@@ -102,7 +103,7 @@ void setup()
102103
attachInterruptArg(switch_ch1.pin, isr, &switch_ch1, CHANGE);
103104
pinMode(switch_ch2.pin, INPUT_PULLUP);
104105
attachInterruptArg(switch_ch2.pin, isr, &switch_ch2, CHANGE);
105-
106+
106107
// Set the Relays GPIOs as output mode
107108
pinMode(gpio_relay1, OUTPUT);
108109
pinMode(gpio_relay2, OUTPUT);
@@ -112,20 +113,24 @@ void setup()
112113
digitalWrite(gpio_relay2, DEFAULT_POWER_MODE);
113114
digitalWrite(gpio_led, false);
114115

115-
Node my_node;
116+
Node my_node;
116117
my_node = RMaker.initNode("Sonoff Dual R3");
117118

119+
//Initialize switch device
120+
my_switch1 = Switch("Switch_ch1", &gpio_relay1);
121+
my_switch2 = Switch("Switch_ch2", &gpio_relay2);
122+
118123
//Standard switch device
119124
my_switch1.addCb(write_callback);
120125
my_switch2.addCb(write_callback);
121126

122-
//Add switch device to the node
127+
//Add switch device to the node
123128
my_node.addDevice(my_switch1);
124129
my_node.addDevice(my_switch2);
125130

126-
//This is optional
131+
//This is optional
127132
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().
129134
//The list of available values are provided here https://rainmaker.espressif.com/docs/time-service.html
130135
// RMaker.setTimeZone("Asia/Shanghai");
131136
// Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone

libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino

+11-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
}
@@ -59,18 +59,21 @@ void setup()
5959
pinMode(gpio_switch, OUTPUT);
6060
digitalWrite(gpio_switch, DEFAULT_POWER_MODE);
6161

62-
Node my_node;
62+
Node my_node;
6363
my_node = RMaker.initNode("ESP RainMaker Node");
6464

65+
//Initialize switch device
66+
my_switch = Switch("Switch", &gpio_switch);
67+
6568
//Standard switch device
6669
my_switch.addCb(write_callback);
67-
68-
//Add switch device to the node
70+
71+
//Add switch device to the node
6972
my_node.addDevice(my_switch);
7073

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

0 commit comments

Comments
 (0)