@@ -31,20 +31,20 @@ LightSwitch switch_ch1 = {gpio_switch1, false};
3131LightSwitch 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
3737void 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 (" \n Provisioning Started with name \" %s\" and PoP \" %s\" on BLE\n " , service_name, pop);
4343 printQR (service_name, pop, " ble" );
4444#else
4545 Serial.printf (" \n Provisioning 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 (" \n Connected 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
8888void ARDUINO_ISR_ATTR isr (void * arg) {
@@ -92,8 +92,11 @@ void ARDUINO_ISR_ATTR isr(void* arg) {
9292
9393void 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
0 commit comments