I'm running into so trouble that seems above my head. I'm thinking it has something to do with the flash memory but I have no way of knowing if that's true or how to go about fixing it. I have "Erase flash before sketch upload" enabled and, due to space requirements, I set it to "Upload with minimal SPIFFS".
Here's the serial monitor output:
Code: Select all
rst:0x1 (POWERON_RESET),boot:0x1b (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1184
load:0x40078000,len:13160
load:0x40080400,len:3036
entry 0x400805e4
E (25) esp_rmaker_fctry: NVS Flash init failed
E (25) esp_rmaker_core: Failed to initialise storage
E (25) esp_rmaker_node: Node or Device/Service handle cannot be NULL.
E (29) esp_rmaker_node: Node or Device/Service handle cannot be NULL.
E (35) esp_rmaker_core: ESP RainMaker not initialised
E (40) esp_rmaker_node: Node or Device/Service handle cannot be NULL.
E (46) esp_rmaker_ota: Failed to enable OTA
E (50) esp_rmaker_core: ESP RainMaker not initialised
E (55) esp_rmaker_node: Node or Device/Service handle cannot be NULL.
E (63) esp_rmaker_core: ESP RainMaker not initialised
E (65) esp_rmaker_node: Node or Device/Service handle cannot be NULL.
E (72) esp_rmaker_schedule: Failed to add service Service
Chip ID: 9999999 Service Name: PROV_11111
Starting ESP-RainMaker
E (87) esp_rmaker_core: ESP RainMaker not initialised
Code: Select all
#include "RMaker.h"
#include "WiFi.h"
#include "WiFiProv.h"
#include <AceButton.h>
using namespace ace_button;
const char *service_name = "PROV_11111";
const char *pop = "1111111";
// define the Device Names
char deviceName_1[] = "Socket 1";
char deviceName_2[] = "Socket 2";
// define the GPIO connected with Relays and switches
static uint8_t RelayPin1 = 32; //D32
static uint8_t RelayPin2 = 33; //D33
static uint8_t SwitchPin1 = 19; //D19
static uint8_t SwitchPin2 = 22; //D22
static uint8_t wifiLed = 2; //D2
static uint8_t gpio_reset = 34; //D34
/* Variable for reading pin status*/
bool toggleState_1 = LOW; //Define integer to remember the toggle state for relay 1
bool toggleState_2 = LOW; //Define integer to remember the toggle state for relay 2
ButtonConfig config1;
AceButton button1(&config1);
ButtonConfig config2;
AceButton button2(&config2);
void handleEvent1(AceButton*, uint8_t, uint8_t);
void handleEvent2(AceButton*, uint8_t, uint8_t);
//The framework provides some standard device types like switch, lightbulb, fan, temperature sensor.
static Switch my_switch1(deviceName_1, &RelayPin1);
static Switch my_switch2(deviceName_2, &RelayPin2);
void sysProvEvent(arduino_event_t *sys_event)
{
switch (sys_event->event_id) {
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
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop);
printQR(service_name, pop, "softap");
#endif
break;
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
Serial.printf("\nConnected to Wi-Fi!\n");
digitalWrite(wifiLed, true);
break;
}
}
void write_callback(Device *device, Param *param, const param_val_t val, void *priv_data, write_ctx_t *ctx)
{
const char *device_name = device->getDeviceName();
const char *param_name = param->getParamName();
if(strcmp(device_name, deviceName_1) == 0) {
Serial.printf("Lightbulb = %s\n", val.val.b? "true" : "false");
if(strcmp(param_name, "Power") == 0) {
Serial.printf("Received value = %s for %s - %s\n", val.val.b? "true" : "false", device_name, param_name);
toggleState_1 = val.val.b;
(toggleState_1 == false) ? digitalWrite(RelayPin1, HIGH) : digitalWrite(RelayPin1, LOW);
param->updateAndReport(val);
}
} else if(strcmp(device_name, deviceName_2) == 0) {
Serial.printf("Switch value = %s\n", val.val.b? "true" : "false");
if(strcmp(param_name, "Power") == 0) {
Serial.printf("Received value = %s for %s - %s\n", val.val.b? "true" : "false", device_name, param_name);
toggleState_2 = val.val.b;
(toggleState_2 == false) ? digitalWrite(RelayPin2, HIGH) : digitalWrite(RelayPin2, LOW);
param->updateAndReport(val);
}
}
}
void setup()
{
uint32_t chipId = 0;
Serial.begin(115200);
// Set the Relays GPIOs as output mode
pinMode(RelayPin1, OUTPUT);
pinMode(RelayPin2, OUTPUT);
pinMode(wifiLed, OUTPUT);
// Configure the input GPIOs
pinMode(SwitchPin1, INPUT_PULLUP);
pinMode(SwitchPin2, INPUT_PULLUP);
pinMode(gpio_reset, INPUT);
// Write to the GPIOs the default state on booting
digitalWrite(RelayPin1, !toggleState_1);
digitalWrite(RelayPin2, !toggleState_2);
digitalWrite(wifiLed, LOW);
config1.setEventHandler(button1Handler);
config2.setEventHandler(button2Handler);
button1.init(SwitchPin1);
button2.init(SwitchPin2);
Node my_node;
my_node = RMaker.initNode("ESP32_Relay_2");
//Standard switch device
my_switch1.addCb(write_callback);
my_switch2.addCb(write_callback);
//Add switch device to the node
my_node.addDevice(my_switch1);
my_node.addDevice(my_switch2);
//This is optional
RMaker.enableOTA(OTA_USING_PARAMS);
//If you want to enable scheduling, set time zone for your region using setTimeZone().
//The list of available values are provided here https://rainmaker.espressif.com/docs/time-service.html
// RMaker.setTimeZone("Europe/Helsinki");
// Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone
RMaker.enableTZService();
RMaker.enableSchedule();
//Service Name
for(int i=0; i<17; i=i+8) {
chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;
}
Serial.printf("\nChip ID: %d Service Name: %s\n", chipId, service_name);
Serial.printf("\nStarting ESP-RainMaker\n");
RMaker.start();
WiFi.onEvent(sysProvEvent);
#if CONFIG_IDF_TARGET_ESP32
WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name);
#else
WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE, WIFI_PROV_SECURITY_1, pop, service_name);
#endif
my_switch1.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, false);
my_switch2.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, false);
}
void loop()
{
// Read GPIO0 (external button to reset device
if(digitalRead(gpio_reset) == LOW) { //Push button pressed
Serial.printf("Reset Button Pressed!\n");
// Key debounce handling
delay(100);
int startTime = millis();
while(digitalRead(gpio_reset) == LOW) delay(50);
int endTime = millis();
if ((endTime - startTime) > 10000) {
// If key pressed for more than 10secs, reset all
Serial.printf("Reset to factory.\n");
RMakerFactoryReset(2);
} else if ((endTime - startTime) > 3000) {
Serial.printf("Reset Wi-Fi.\n");
// If key pressed for more than 3secs, but less than 10, reset Wi-Fi
RMakerWiFiReset(2);
}
}
delay(100);
if (WiFi.status() != WL_CONNECTED)
{
//Serial.println("WiFi Not Connected");
digitalWrite(wifiLed, false);
}
else
{
//Serial.println("WiFi Connected");
digitalWrite(wifiLed, true);
}
button1.check();
button2.check();
}
void button1Handler(AceButton* button, uint8_t eventType, uint8_t buttonState) {
Serial.println("EVENT1");
switch (eventType) {
case AceButton::kEventReleased:
digitalWrite(RelayPin1, toggleState_1);
toggleState_1 = !toggleState_1;
my_switch1.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_1);
break;
}
}
void button2Handler(AceButton* button, uint8_t eventType, uint8_t buttonState) {
Serial.println("EVENT2");
switch (eventType) {
case AceButton::kEventReleased:
digitalWrite(RelayPin2, toggleState_2);
toggleState_2 = !toggleState_2;
my_switch2.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_2);
break;
}
}
TR.