Skip to content
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

Esp Rainmaker y EspNow (AEGHB-914) #132

Open
vizocu opened this issue Dec 13, 2024 · 4 comments
Open

Esp Rainmaker y EspNow (AEGHB-914) #132

vizocu opened this issue Dec 13, 2024 · 4 comments

Comments

@vizocu
Copy link

vizocu commented Dec 13, 2024

No es posible el funcionamiento simultaneo de estas dos funcionalidades, estoy equivocado?

Estoy realizando un proyecto en el que necesito comunicación bidireccional entre un esp con rainmaker y otro con una pantalla touch. el código de EspNow si que lo puedo insertar en el código de la pantalla touch pero al insertar el código EspNow junto al de Rainmaker, no compila ''exit error 1''. Alguien sabe si es posible y debo seguir intentándolo o dejo de insistir?
Gracias.

@github-actions github-actions bot changed the title Esprainmaker y EspNow Esprainmaker y EspNow (AEGHB-914) Dec 13, 2024
@vizocu vizocu changed the title Esprainmaker y EspNow (AEGHB-914) Esp Rainmaker y EspNow (AEGHB-914) Dec 13, 2024
@lhespress
Copy link
Collaborator

@vizocu

Please apply the patch as the attachment fan.zip which use direction param for check BIND(1) and UNBIND(0), power for control the responder on esp-rainmaker.

fan log:

I (25956) app_main: Received write request via : Cloud
I (25966) app_main: this device is not been bound
I (25966) esp_rmaker_param: Reporting params: {"Fan":{"Direction":0}}
I (31596) esp_rmaker_param: Received params: {"Fan":{"Direction":1}}
I (31596) esp_rmaker_param: Found 1 params in write request for Fan
I (31596) app_main: Received write request via : Cloud
I (31606) app_main: initiator bind press
I (31616) esp_rmaker_param: Reporting params: {"Fan":{"Direction":1}}
I (33056) esp_rmaker_time: SNTP Synchronised.
I (33056) esp_rmaker_time: The current time is: Mon Dec 16 17:15:05 2024 +0800[CST], DST: No.
I (33686) esp_rmaker_param: Received params: {"Fan":{"Power":true}}
I (33686) esp_rmaker_param: Found 1 params in write request for Fan
I (33686) app_main: Received write request via : Cloud
I (33686) app_main: Received value = true for Fan - Power
I (33696) app_main: initiator send press
I (33706) esp_rmaker_param: Reporting params: {"Fan":{"Power":true}}
I (44896) esp_rmaker_param: Received params: {"Fan":{"Power":false}}
I (44896) esp_rmaker_param: Found 1 params in write request for Fan
I (44906) app_main: Received write request via : Cloud
I (44906) app_main: Received value = false for Fan - Power
I (44916) app_main: initiator send press
I (44916) esp_rmaker_param: Reporting params: {"Fan":{"Power":false}}
I (46336) esp_rmaker_param: Received params: {"Fan":{"Power":true}}
I (46336) esp_rmaker_param: Found 1 params in write request for Fan
I (46336) app_main: Received write request via : Cloud
I (46346) app_main: Received value = true for Fan - Power
I (46346) app_main: initiator send press
I (46356) esp_rmaker_param: Reporting params: {"Fan":{"Power":true}}
I (62006) esp_rmaker_param: Received params: {"Fan":{"Power":false}}
I (62006) esp_rmaker_param: Found 1 params in write request for Fan
I (62006) app_main: Received write request via : Cloud
I (62006) app_main: Received value = false for Fan - Power
I (62016) app_main: initiator send press
I (62026) esp_rmaker_param: Reporting params: {"Fan":{"Power":false}}
I (65176) esp_rmaker_param: Received params: {"Fan":{"Power":true}}
I (65176) esp_rmaker_param: Found 1 params in write request for Fan
I (65176) app_main: Received write request via : Cloud
I (65186) app_main: Received value = true for Fan - Power
I (65186) app_main: initiator send press
I (65196) esp_rmaker_param: Reporting params: {"Fan":{"Power":true}}
I (67016) esp_rmaker_param: Received params: {"Fan":{"Power":false}}
I (67016) esp_rmaker_param: Found 1 params in write request for Fan
I (67026) app_main: Received write request via : Cloud
I (67026) app_main: Received value = false for Fan - Power
I (67036) app_main: initiator send press
I (67036) esp_rmaker_param: Reporting params: {"Fan":{"Power":false}}
I (68346) esp_rmaker_param: Received params: {"Fan":{"Power":true}}
I (68356) esp_rmaker_param: Found 1 params in write request for Fan
I (68356) app_main: Received write request via : Cloud
I (68356) app_main: Received value = true for Fan - Power
I (68366) app_main: initiator send press
I (68376) esp_rmaker_param: Reporting params: {"Fan":{"Power":true}}
I (72756) esp_rmaker_param: Received params: {"Fan":{"Direction":0}}
I (72756) esp_rmaker_param: Found 1 params in write request for Fan
I (72756) app_main: Received write request via : Cloud
I (72766) app_main: initiator unbind press
I (72766) esp_rmaker_param: Reporting params: {"Fan":{"Direction":0}}
I (75516) esp_rmaker_param: Received params: {"Fan":{"Direction":1}}
I (75516) esp_rmaker_param: Found 1 params in write request for Fan
I (75526) app_main: Received write request via : Cloud
I (75526) app_main: initiator bind press
I (75536) esp_rmaker_param: Reporting params: {"Fan":{"Direction":1}}
I (77576) esp_rmaker_param: Received params: {"Fan":{"Power":false}}
I (77576) esp_rmaker_param: Found 1 params in write request for Fan
I (77586) app_main: Received write request via : Cloud
I (77586) app_main: Received value = false for Fan - Power
I (77596) app_main: initiator send press
I (77596) esp_rmaker_param: Reporting params: {"Fan":{"Power":false}}
I (79206) esp_rmaker_param: Received params: {"Fan":{"Power":true}}
I (79206) esp_rmaker_param: Found 1 params in write request for Fan
I (79206) app_main: Received write request via : Cloud
I (79216) app_main: Received value = true for Fan - Power
I (79226) app_main: initiator send press
I (79226) esp_rmaker_param: Reporting params: {"Fan":{"Power":true}}
I (80236) esp_rmaker_param: Received params: {"Fan":{"Power":false}}
I (80236) esp_rmaker_param: Found 1 params in write request for Fan
I (80246) app_main: Received write request via : Cloud
I (80246) app_main: Received value = false for Fan - Power
I (80256) app_main: initiator send press
I (80256) esp_rmaker_param: Reporting params: {"Fan":{"Power":false}}
I (81046) esp_rmaker_param: Received params: {"Fan":{"Power":true}}
I (81046) esp_rmaker_param: Found 1 params in write request for Fan
I (81056) app_main: Received write request via : Cloud
I (81056) app_main: Received value = true for Fan - Power
I (81066) app_main: initiator send press
I (81066) esp_rmaker_param: Reporting params: {"Fan":{"Power":true}}

responder control

I (732) ESPNOW: espnow [version: 1.0] init
I (732) espnow: mac: c8:f0:9e:35:97:ac, version: 2
I (742) espnow: Enable main task
I (742) espnow: main task entry
I (742) app_main: primary 1 second 0
I (752) app_main: second 0 primary 8 
I (752) main_task: Returned from app_main()
I (3972) app_main: app_responder_ctrl_data_cb, initiator_attribute: 513, responder_attribute: 1, value: 0
I (7132) app_main: app_responder_ctrl_data_cb, initiator_attribute: 513, responder_attribute: 1, value: 1
I (8972) app_main: app_responder_ctrl_data_cb, initiator_attribute: 513, responder_attribute: 1, value: 0
I (10302) app_main: app_responder_ctrl_data_cb, initiator_attribute: 513, responder_attribute: 1, value: 1
I (14702) app_main: unbind, uuid: 30:30:f9:fb:8b:7c, initiator_type: 513
I (17472) espnow_ctrl: bind, timestamp: 17472, max timestamp: 30742, rssi: -19, min rssi: -55, bindlist size: 0
I (17472) app_main: bind, uuid: 30:30:f9:fb:8b:7c, initiator_type: 513
I (19542) app_main: app_responder_ctrl_data_cb, initiator_attribute: 513, responder_attribute: 1, value: 0
I (21162) app_main: app_responder_ctrl_data_cb, initiator_attribute: 513, responder_attribute: 1, value: 1
I (22202) app_main: app_responder_ctrl_data_cb, initiator_attribute: 513, responder_attribute: 1, value: 0
I (23002) app_main: app_responder_ctrl_data_cb, initiator_attribute: 513, responder_attribute: 1, value: 1

@vizocu
Copy link
Author

vizocu commented Dec 17, 2024

Gracias por contestar, no logro comprender la solución que me aportas. Podrías explicarmelo de otra forma para que pueda comprenderlo

@lhespress
Copy link
Collaborator

@vizocu Could you provide you project links or your project as the attachment?

@vizocu
Copy link
Author

vizocu commented Dec 18, 2024

Claro, por un lado uso en un esp32 el código normal de un pulsador donde al pulsar envia un mensaje haciendo uso de la librería tinyespnow.h (esta parte funciona)
el ejemplo 1st

`#include "tinyESPNow.h"
static tinyESPNow tEN;

#define BUFSIZE (64)            // The size of the buffer you want to send and receive (MAX 249 Byte)

void dataUpdate() {
  uint8_t *buf = tEN.get();     // Get a pointer to the buffer
  buf[0] = 0xFF;
  Serial.printf("%02X=>", buf[1]);
  buf[1] = (buf[1] + 1) % 256;  // Add One to the received data
  Serial.printf("%02X\n", buf[1]);
  tEN.put(buf, 2);              // Update the buffer
  tEN.send();                   // Send the buffer
}

void setup() {
  uint8_t myId = 0xFF;          // Register your number
  Serial.begin( 115200 ); while (!Serial);
  tEN.begin(myId, BUFSIZE);
  dataUpdate();
}

void loop() {
  if (tEN.isRecv()) {           // Did the data arrive?
    dataUpdate();
  }
  tEN.update();                 // Update class
  delay(10);
`

Por otro lado uso otro esp32 donde quiero insertar en el ejemplo Rmakerswitch el ejemplo 2th de tinyespnow.

`// This example demonstrates the ESP RainMaker with a standard Switch device.
#include "RMaker.h"
#include "WiFi.h"
#include "WiFiProv.h"
#include "AppInsights.h"

#define DEFAULT_POWER_MODE true
const char *service_name = "PROV_1234";
const char *pop = "abcd1234";

// GPIO for push button
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6
static int gpio_0 = 9;
static int gpio_switch = 7;
#else
// GPIO for virtual device
static int gpio_0 = 0;
static int gpio_switch = 16;
#endif

/* Variable for reading pin status*/
bool switch_state = true;

// The framework provides some standard device types like switch, lightbulb,
// fan, temperaturesensor.
static Switch *my_switch = NULL;

// WARNING: sysProvEvent is called from a separate FreeRTOS task (thread)!
void sysProvEvent(arduino_event_t *sys_event) {
  switch (sys_event->event_id) {
    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);
      WiFiProv.printQR(service_name, pop, "softap");
#else
      Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop);
      WiFiProv.printQR(service_name, pop, "ble");
#endif
      break;
    case ARDUINO_EVENT_PROV_INIT:         WiFiProv.disableAutoStop(10000); break;
    case ARDUINO_EVENT_PROV_CRED_SUCCESS: WiFiProv.endProvision(); break;
    default:                              ;
  }
}

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(param_name, "Power") == 0) {
    Serial.printf("Received value = %s for %s - %s\n", val.val.b ? "true" : "false", device_name, param_name);
    switch_state = val.val.b;
    (switch_state == false) ? digitalWrite(gpio_switch, LOW) : digitalWrite(gpio_switch, HIGH);
    param->updateAndReport(val);
  }
}

void setup() {
  Serial.begin(115200);
  pinMode(gpio_0, INPUT);
  pinMode(gpio_switch, OUTPUT);
  digitalWrite(gpio_switch, DEFAULT_POWER_MODE);

  Node my_node;
  my_node = RMaker.initNode("ESP RainMaker Node");

  // Initialize switch device
  my_switch = new Switch("Switch", &gpio_switch);
  if (!my_switch) {
    return;
  }
  // Standard switch device
  my_switch->addCb(write_callback);

  // Add switch device to the node
  my_node.addDevice(*my_switch);

  // This is optional
  RMaker.enableOTA(OTA_USING_TOPICS);
  // 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("Asia/Shanghai");
  //  Alternatively, enable the Timezone service and let the phone apps set the
  //  appropriate timezone
  RMaker.enableTZService();

  RMaker.enableSchedule();

  RMaker.enableScenes();
  // Enable ESP Insights. Insteads of using the default http transport, this function will
  // reuse the existing MQTT connection of Rainmaker, thereby saving memory space.
  initAppInsights();

  RMaker.enableSystemService(SYSTEM_SERV_FLAGS_ALL, 2, 2, 2);

  RMaker.start();

  WiFi.onEvent(sysProvEvent);  // Will call sysProvEvent() from another thread.
#if CONFIG_IDF_TARGET_ESP32S2
  WiFiProv.beginProvision(NETWORK_PROV_SCHEME_SOFTAP, NETWORK_PROV_SCHEME_HANDLER_NONE, NETWORK_PROV_SECURITY_1, pop, service_name);
#else
  WiFiProv.beginProvision(NETWORK_PROV_SCHEME_BLE, NETWORK_PROV_SCHEME_HANDLER_FREE_BTDM, NETWORK_PROV_SECURITY_1, pop, service_name);
#endif
}

void loop() {
  if (digitalRead(gpio_0) == LOW) {  // Push button pressed

    // Key debounce handling
    delay(100);
    int startTime = millis();
    while (digitalRead(gpio_0) == 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);
    } else {
      // Toggle device state
      switch_state = !switch_state;
      Serial.printf("Toggle State to %s.\n", switch_state ? "true" : "false");
      if (my_switch) {
        my_switch->updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, switch_state);
      }
      (switch_state == false) ? digitalWrite(gpio_switch, LOW) : digitalWrite(gpio_switch, HIGH);
    }
  }
  delay(100);
}`

codigo tiniespnow.h

`#include "tinyESPNow.h"
static tinyESPNow tEN;

#define BUFSIZE (64)            // The size of the buffer you want to send and receive (MAX 249 Byte)

void dataUpdate() {
  uint8_t *buf = tEN.get();     // Get a pointer to the buffer
  buf[0] = 0xFF;
  Serial.printf("%02X=>", buf[1]);
  buf[1] = (buf[1] + 1) % 256;  // Add One to the received data
  Serial.printf("%02X\n", buf[1]);
  tEN.put(buf, 2);              // Update the buffer
  tEN.send();                   // Send the buffer
}

void setup() {
  uint8_t myId = 0xFF;          // Register your number
  Serial.begin( 115200 ); while (!Serial);
  tEN.begin(myId, BUFSIZE);
  dataUpdate();
}

void loop() {
  if (tEN.isRecv()) {           // Did the data arrive?
    dataUpdate();
  }
  tEN.update();                 // Update class
  delay(10);
}`

Estoy trabajando con arduino IDE.
Simplificando, necesito que funcione el protocolo ESPnow y ESPRainmaker juntos para que al cambiar el estado del switch en rainmaker, este esp32 sea capaz de enviar un cambio de estado al otro esp32.

Gracias por tu paciencia.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants