Skip to content

RainMaker - Improve sysProvEvent function #7932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
38 changes: 35 additions & 3 deletions libraries/RainMaker/examples/RMakerCustom/RMakerCustom.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ static Device *my_device = NULL;

void sysProvEvent(arduino_event_t *sys_event)
{
switch (sys_event->event_id) {
switch (sys_event->event_id){
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
Serial.print("\nConnected IP address : ");
Serial.println(IPAddress(sys_event->event_info.got_ip.ip_info.ip.addr));
break;
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
Serial.println("\nDisconnected. Connecting to the AP again... ");
break;
case ARDUINO_EVENT_PROV_START:
#if CONFIG_IDF_TARGET_ESP32S2
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop);
Expand All @@ -41,9 +48,34 @@ void sysProvEvent(arduino_event_t *sys_event)
break;
case ARDUINO_EVENT_PROV_CRED_SUCCESS:
wifi_prov_mgr_stop_provisioning();
break;
case ARDUINO_EVENT_PROV_CRED_RECV:
Serial.println("\nReceived Wi-Fi credentials");
Serial.print("\tSSID : ");
Serial.println((const char *) sys_event->event_info.prov_cred_recv.ssid);
Serial.print("\tPassword : ");
Serial.println((char const *) sys_event->event_info.prov_cred_recv.password);
break;
default:;
}
case ARDUINO_EVENT_PROV_CRED_FAIL:
Serial.println("\nProvisioning failed!\nPlease reset to factory and retry provisioning\n");
if(sys_event->event_info.prov_fail_reason == WIFI_PROV_STA_AUTH_ERROR)
{
Serial.println("\nWi-Fi AP password incorrect");
}
else
{
Serial.println("\nWi-Fi AP not found....Add API \" nvs_flash_erase() \" before beginProvision()");
}
break;
case ARDUINO_EVENT_PROV_CRED_SUCCESS:
Serial.println("\nProvisioning Successful");
break;
case ARDUINO_EVENT_PROV_END:
Serial.println("\nProvisioning Ends");
break;
default:
break;
}
}

void write_callback(Device *device, Param *param, const param_val_t val, void *priv_data, write_ctx_t *ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ static Device *my_device = NULL;

void sysProvEvent(arduino_event_t *sys_event)
{
switch (sys_event->event_id) {
switch (sys_event->event_id){
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
Serial.print("\nConnected IP address : ");
Serial.println(IPAddress(sys_event->event_info.got_ip.ip_info.ip.addr));
break;
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
Serial.println("\nDisconnected. Connecting to the AP again... ");
break;
case ARDUINO_EVENT_PROV_START:
#if CONFIG_IDF_TARGET_ESP32S2
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop);
Expand All @@ -58,9 +65,34 @@ void sysProvEvent(arduino_event_t *sys_event)
break;
case ARDUINO_EVENT_PROV_CRED_SUCCESS:
wifi_prov_mgr_stop_provisioning();
break;
case ARDUINO_EVENT_PROV_CRED_RECV:
Serial.println("\nReceived Wi-Fi credentials");
Serial.print("\tSSID : ");
Serial.println((const char *) sys_event->event_info.prov_cred_recv.ssid);
Serial.print("\tPassword : ");
Serial.println((char const *) sys_event->event_info.prov_cred_recv.password);
break;
default:;
}
case ARDUINO_EVENT_PROV_CRED_FAIL:
Serial.println("\nProvisioning failed!\nPlease reset to factory and retry provisioning\n");
if(sys_event->event_info.prov_fail_reason == WIFI_PROV_STA_AUTH_ERROR)
{
Serial.println("\nWi-Fi AP password incorrect");
}
else
{
Serial.println("\nWi-Fi AP not found....Add API \" nvs_flash_erase() \" before beginProvision()");
}
break;
case ARDUINO_EVENT_PROV_CRED_SUCCESS:
Serial.println("\nProvisioning Successful");
break;
case ARDUINO_EVENT_PROV_END:
Serial.println("\nProvisioning Ends");
break;
default:
break;
}
}

void write_callback(Device *device, Param *param, const param_val_t val, void *priv_data, write_ctx_t *ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,56 @@ static Switch *my_switch2 = NULL;

void sysProvEvent(arduino_event_t *sys_event)
{
switch (sys_event->event_id) {
switch (sys_event->event_id){
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
Serial.print("\nConnected IP address : ");
Serial.println(IPAddress(sys_event->event_info.got_ip.ip_info.ip.addr));
break;
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
Serial.println("\nDisconnected. Connecting to the AP again... ");
break;
case ARDUINO_EVENT_PROV_START:
#if CONFIG_IDF_TARGET_ESP32
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop);
printQR(service_name, pop, "ble");
#else
#if CONFIG_IDF_TARGET_ESP32S2
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop);
printQR(service_name, pop, "softap");
#else
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop);
printQR(service_name, pop, "ble");
#endif
break;
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
Serial.printf("\nConnected to Wi-Fi!\n");
digitalWrite(gpio_led, true);
break;
case ARDUINO_EVENT_PROV_INIT:
wifi_prov_mgr_disable_auto_stop(10000);
break;
case ARDUINO_EVENT_PROV_CRED_SUCCESS:
wifi_prov_mgr_stop_provisioning();
break;
case ARDUINO_EVENT_PROV_CRED_RECV:
Serial.println("\nReceived Wi-Fi credentials");
Serial.print("\tSSID : ");
Serial.println((const char *) sys_event->event_info.prov_cred_recv.ssid);
Serial.print("\tPassword : ");
Serial.println((char const *) sys_event->event_info.prov_cred_recv.password);
break;
default:;
}
case ARDUINO_EVENT_PROV_CRED_FAIL:
Serial.println("\nProvisioning failed!\nPlease reset to factory and retry provisioning\n");
if(sys_event->event_info.prov_fail_reason == WIFI_PROV_STA_AUTH_ERROR)
{
Serial.println("\nWi-Fi AP password incorrect");
}
else
{
Serial.println("\nWi-Fi AP not found....Add API \" nvs_flash_erase() \" before beginProvision()");
}
break;
case ARDUINO_EVENT_PROV_CRED_SUCCESS:
Serial.println("\nProvisioning Successful");
break;
case ARDUINO_EVENT_PROV_END:
Serial.println("\nProvisioning Ends");
break;
default:
break;
}
}


Expand Down
44 changes: 37 additions & 7 deletions libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,20 @@ static Switch *my_switch = NULL;

void sysProvEvent(arduino_event_t *sys_event)
{
switch (sys_event->event_id) {
switch (sys_event->event_id){
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
Serial.print("\nConnected IP address : ");
Serial.println(IPAddress(sys_event->event_info.got_ip.ip_info.ip.addr));
break;
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
Serial.println("\nDisconnected. Connecting to the AP again... ");
break;
case ARDUINO_EVENT_PROV_START:
#if CONFIG_IDF_TARGET_ESP32S2
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n",
service_name, pop);
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop);
printQR(service_name, pop, "softap");
#else
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n",
service_name, pop);
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop);
printQR(service_name, pop, "ble");
#endif
break;
Expand All @@ -44,9 +49,34 @@ void sysProvEvent(arduino_event_t *sys_event)
break;
case ARDUINO_EVENT_PROV_CRED_SUCCESS:
wifi_prov_mgr_stop_provisioning();
break;
case ARDUINO_EVENT_PROV_CRED_RECV:
Serial.println("\nReceived Wi-Fi credentials");
Serial.print("\tSSID : ");
Serial.println((const char *) sys_event->event_info.prov_cred_recv.ssid);
Serial.print("\tPassword : ");
Serial.println((char const *) sys_event->event_info.prov_cred_recv.password);
break;
default:;
}
case ARDUINO_EVENT_PROV_CRED_FAIL:
Serial.println("\nProvisioning failed!\nPlease reset to factory and retry provisioning\n");
if(sys_event->event_info.prov_fail_reason == WIFI_PROV_STA_AUTH_ERROR)
{
Serial.println("\nWi-Fi AP password incorrect");
}
else
{
Serial.println("\nWi-Fi AP not found....Add API \" nvs_flash_erase() \" before beginProvision()");
}
break;
case ARDUINO_EVENT_PROV_CRED_SUCCESS:
Serial.println("\nProvisioning Successful");
break;
case ARDUINO_EVENT_PROV_END:
Serial.println("\nProvisioning Ends");
break;
default:
break;
}
}

void write_callback(Device *device, Param *param, const param_val_t val,
Expand Down