ESP RainMaker Sensor Update Values

maialbe2823
Posts: 27
Joined: Thu Feb 17, 2022 4:41 am

ESP RainMaker Sensor Update Values

Postby maialbe2823 » Sat Feb 19, 2022 4:35 am

Hi, I am trying to see how to update a temp sensor values in the rainmaker app. I am using arduino ide this is the callback function im using:
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, "Temperature F") == 0) {
Serial.printf("Received value = %2.2f for %s - %s\n", val.val.f, device_name, param_name);
dht_temperature = val.val.f;
param->updateAndReport(val);
}
if (strcmp(param_name, "Humidity Rh") == 0) {
Serial.printf("Received value = %2.2f for %s - %s\n", val.val.f, device_name, param_name);
dht_humidity = val.val.f;
param->updateAndReport(val);
}
}

However; the sensor value doesn't get updated it just stays the same. How can I get it to update. Thanks.

endlessparadigm
Posts: 16
Joined: Mon Oct 25, 2021 4:15 am

Re: ESP RainMaker Sensor Update Values

Postby endlessparadigm » Sun Feb 20, 2022 11:50 pm

Have you attached the callback to the device? Are you able to see serial print output?

maialbe2823
Posts: 27
Joined: Thu Feb 17, 2022 4:41 am

Re: ESP RainMaker Sensor Update Values

Postby maialbe2823 » Mon Feb 21, 2022 12:17 pm

Hi, how should the callback function look like cuz mine it not doing anything. This is my callback function:
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, "Temperature F") == 0) {
Serial.printf("Received value = %2.2f for %s - %s\n", val.val.f, device_name, param_name);
dht_temperature = val.val.f;
param->updateAndReport(val);
}
if (strcmp(param_name, "Humidity Rh") == 0) {
Serial.printf("Received value = %2.2f for %s - %s\n", val.val.f, device_name, param_name);
dht_humidity = val.val.f;
param->updateAndReport(val);
}
}
However; the updateandReport fucntion is not updating the param as it should do. Any suggestion as why that might be.

endlessparadigm
Posts: 16
Joined: Mon Oct 25, 2021 4:15 am

Re: ESP RainMaker Sensor Update Values

Postby endlessparadigm » Mon Feb 21, 2022 9:44 pm

Your callback functions looks alright. My question here is when you start the serial monitor do you see the Serial.prints going through? it maybe because you might nto have attached write_callback to your dht device.
Refer to official example -> https://github.com/espressif/arduino-es ... Switch.ino

Code: Select all

//Standard switch device
    my_switch.addCb(write_callback);
    
    //Add switch device to the node   
    my_node.addDevice(my_switch);

maialbe2823
Posts: 27
Joined: Thu Feb 17, 2022 4:41 am

Re: ESP RainMaker Sensor Update Values

Postby maialbe2823 » Mon Feb 21, 2022 11:16 pm

Yes I do have it, but it still doesn't update it just reads the first value after flashing the device and after that it just stays the same.
This is what I have:
Node my_sensor;
my_sensor = RMaker.initNode("Sensor Node");


DHT_Sensor.addCb(write_callback);
my_sensor.addDevice(DHT_Sensor);

But I cant figure out why it doesn't update the values.

endlessparadigm
Posts: 16
Joined: Mon Oct 25, 2021 4:15 am

Re: ESP RainMaker Sensor Update Values

Postby endlessparadigm » Tue Feb 22, 2022 12:08 am

Oh Hold On. write_callback gets called from the cloud if the "User" tried to write any value.
From my understanding Temperature and Humidity should be be a read only param. A User wont write the value of temperature from the App so a write callback wont be called.

Try to update the param value after you read the readings from the sensor in your loop function.

Code: Select all

 DHT_Sensor.updateAndReportParam("Temperature F", temp_val);

maialbe2823
Posts: 27
Joined: Thu Feb 17, 2022 4:41 am

Re: ESP RainMaker Sensor Update Values

Postby maialbe2823 » Sat Feb 26, 2022 8:06 am

Thanks, already figure it out.

ZANTERA
Posts: 2
Joined: Thu Nov 17, 2022 6:24 pm

Re: ESP RainMaker Sensor Update Values

Postby ZANTERA » Sun Nov 20, 2022 5:19 pm

maialbe2823 wrote:
Sat Feb 26, 2022 8:06 am
Thanks, already figure it out.
Do you still have the code?
im struggleing really bad whit mine

I cant make rainmaker read the sensor, but the esp can

when i open the serial monitor and i try to print the parameters, it pull out this message



this is the code
  1. #include "RMaker.h"
  2. #include "WiFi.h"
  3. #include "WiFiProv.h"
  4. #include <Adafruit_AHTX0.h>
  5. #include <SimpleTimer.h>
  6.  
  7. const char *service_name = "Indoor Control Unit";
  8. const char *pop = "1234567";
  9.  
  10. void Send_Sensor();
  11.  
  12. // define the Device Names
  13. char deviceName_1[] = "Iluminación 1";
  14. char deviceName_2[] = "Iluminación 2";
  15. char deviceName_3[] = "Riego 1";
  16. char deviceName_4[] = "Riego 2";
  17. char deviceName_5[] = "Frio";
  18. char deviceName_6[] = "Calor";
  19. char deviceName_7[] = "Ventilación 1";
  20. char deviceName_8[] = "Ventilación 2";
  21. char deviceName_9[] = "Temperatura";
  22. char deviceName_10[] = "Humedad";
  23.  
  24. // define the GPIO connected with Relays and switches
  25. static uint8_t RelayPin1 = 13;  //D23
  26. static uint8_t RelayPin2 = 12;  //D22
  27. static uint8_t RelayPin3 = 14;  //D21
  28. static uint8_t RelayPin4 = 27;  //D19
  29. static uint8_t RelayPin5 = 26;  //D18
  30. static uint8_t RelayPin6 = 25;   //D5
  31. static uint8_t RelayPin7 = 33;  //D25
  32. static uint8_t RelayPin8 = 32;  //D26
  33.  
  34. static uint8_t SwitchPin1  ;  //D13
  35. static uint8_t SwitchPin2  ;  //D12
  36. static uint8_t SwitchPin3  ;  //D14
  37. static uint8_t SwitchPin4  ;  //D27
  38. static uint8_t SwitchPin5  ;  //D33
  39. static uint8_t SwitchPin6  ;  //D32
  40. static uint8_t SwitchPin7  ;  //D15
  41. static uint8_t SwitchPin8  ;   //D4
  42.  
  43. static uint8_t wifiLed    = 2;   //D2
  44. static uint8_t gpio_reset = 0;
  45.  
  46. /* Variable for reading pin status*/
  47. // Relay State
  48. bool toggleState_1 = true; //Define integer to remember the toggle state for relay 1
  49. bool toggleState_2 = true; //Define integer to remember the toggle state for relay 2
  50. bool toggleState_3 = true; //Define integer to remember the toggle state for relay 3
  51. bool toggleState_4 = true; //Define integer to remember the toggle state for relay 4
  52. bool toggleState_5 = true; //Define integer to remember the toggle state for relay 5
  53. bool toggleState_6 = true; //Define integer to remember the toggle state for relay 6
  54. bool toggleState_7 = true; //Define integer to remember the toggle state for relay 7
  55. bool toggleState_8 = true; //Define integer to remember the toggle state for relay 8
  56. float temperatura = 0;
  57. float humedad = 0;
  58.  
  59. // Switch State
  60. bool SwitchState_1 = true;
  61. bool SwitchState_2 = true;
  62. bool SwitchState_3 = true;
  63. bool SwitchState_4 = true;
  64. bool SwitchState_5 = true;
  65. bool SwitchState_6 = true;
  66. bool SwitchState_7 = true;
  67. bool SwitchState_8 = true;
  68.  
  69. Adafruit_AHTX0 aht;
  70. SimpleTimer Timer;
  71.  
  72. //The framework provides some standard device types like switch, lightbulb, fan, temperature sensor.
  73. static LightBulb my_switch1(deviceName_1, &RelayPin1);
  74. static LightBulb my_switch2(deviceName_2, &RelayPin2);
  75. static Switch my_switch3(deviceName_3, &RelayPin3);
  76. static Switch my_switch4(deviceName_4, &RelayPin4);
  77. static Switch my_switch5(deviceName_5, &RelayPin5);
  78. static Switch my_switch6(deviceName_6, &RelayPin6);
  79. static Fan my_switch7(deviceName_7, &RelayPin7);
  80. static Fan my_switch8(deviceName_8, &RelayPin8);
  81. static TemperatureSensor my_switch9(deviceName_9);
  82. static TemperatureSensor my_switch10(deviceName_10);
  83.  
  84. void sysProvEvent(arduino_event_t *sys_event)
  85. {
  86.     switch (sys_event->event_id) {      
  87.         case ARDUINO_EVENT_PROV_START:
  88. #if CONFIG_IDF_TARGET_ESP32
  89.         Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop);
  90.         printQR(service_name, pop, "ble");
  91. #else
  92.         Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop);
  93.         printQR(service_name, pop, "softap");
  94. #endif        
  95.         break;
  96.         case ARDUINO_EVENT_WIFI_STA_CONNECTED:
  97.         Serial.printf("\nConnected to Wi-Fi!\n");
  98.         digitalWrite(wifiLed, true);
  99.         break;
  100.     }
  101. }
  102.  
  103. void write_callback(Device *device, Param *param, const param_val_t val, void *priv_data, write_ctx_t *ctx)
  104. {
  105.     const char *device_name = device->getDeviceName();
  106.     const char *param_name = param->getParamName();
  107.  
  108.     if(strcmp(device_name, deviceName_1) == 0) {
  109.      
  110.       Serial.printf("Lightbulb = %s\n", val.val.b? "true" : "false");
  111.      
  112.       if(strcmp(param_name, "Power") == 0) {
  113.           Serial.printf("Received value = %s for %s - %s\n", val.val.b? "true" : "false", device_name, param_name);
  114.         toggleState_1 = val.val.b;
  115.         (toggleState_1 == false) ? digitalWrite(RelayPin1, LOW) : digitalWrite(RelayPin1, HIGH);
  116.         param->updateAndReport(val);
  117.       }
  118.      
  119.     } else if(strcmp(device_name, deviceName_2) == 0) {
  120.      
  121.       Serial.printf("Switch value = %s\n", val.val.b? "true" : "false");
  122.  
  123.       if(strcmp(param_name, "Power") == 0) {
  124.         Serial.printf("Received value = %s for %s - %s\n", val.val.b? "true" : "false", device_name, param_name);
  125.         toggleState_2 = val.val.b;
  126.         (toggleState_2 == false) ? digitalWrite(RelayPin2, LOW) : digitalWrite(RelayPin2, HIGH);
  127.         param->updateAndReport(val);
  128.       }
  129.  
  130.     } else if(strcmp(device_name, deviceName_3) == 0) {
  131.      
  132.       Serial.printf("Switch value = %s\n", val.val.b? "true" : "false");
  133.  
  134.       if(strcmp(param_name, "Power") == 0) {
  135.         Serial.printf("Received value = %s for %s - %s\n", val.val.b? "true" : "false", device_name, param_name);
  136.         toggleState_3 = val.val.b;
  137.         (toggleState_3 == false) ? digitalWrite(RelayPin3, LOW) : digitalWrite(RelayPin3, HIGH);
  138.         param->updateAndReport(val);
  139.       }
  140.  
  141.     } else if(strcmp(device_name, deviceName_4) == 0) {
  142.      
  143.       Serial.printf("Switch value = %s\n", val.val.b? "true" : "false");
  144.  
  145.       if(strcmp(param_name, "Power") == 0) {
  146.         Serial.printf("Received value = %s for %s - %s\n", val.val.b? "true" : "false", device_name, param_name);
  147.         toggleState_4 = val.val.b;
  148.         (toggleState_4 == false) ? digitalWrite(RelayPin4, LOW) : digitalWrite(RelayPin4, HIGH);
  149.         param->updateAndReport(val);
  150.       }
  151.        
  152.     } else if(strcmp(device_name, deviceName_5) == 0) {
  153.      
  154.       Serial.printf("Lightbulb = %s\n", val.val.b? "true" : "false");
  155.      
  156.       if(strcmp(param_name, "Power") == 0) {
  157.           Serial.printf("Received value = %s for %s - %s\n", val.val.b? "true" : "false", device_name, param_name);
  158.         toggleState_5 = val.val.b;
  159.         (toggleState_5 == false) ? digitalWrite(RelayPin5, LOW) : digitalWrite(RelayPin5, HIGH);
  160.         param->updateAndReport(val);
  161.       }
  162.      
  163.     } else if(strcmp(device_name, deviceName_6) == 0) {
  164.      
  165.       Serial.printf("Switch value = %s\n", val.val.b? "true" : "false");
  166.  
  167.       if(strcmp(param_name, "Power") == 0) {
  168.         Serial.printf("Received value = %s for %s - %s\n", val.val.b? "true" : "false", device_name, param_name);
  169.         toggleState_6 = val.val.b;
  170.         (toggleState_6 == false) ? digitalWrite(RelayPin6, LOW) : digitalWrite(RelayPin6, HIGH);
  171.         param->updateAndReport(val);
  172.       }
  173.  
  174.     } else if(strcmp(device_name, deviceName_7) == 0) {
  175.      
  176.       Serial.printf("Switch value = %s\n", val.val.b? "true" : "false");
  177.  
  178.       if(strcmp(param_name, "Power") == 0) {
  179.         Serial.printf("Received value = %s for %s - %s\n", val.val.b? "true" : "false", device_name, param_name);
  180.         toggleState_7 = val.val.b;
  181.         (toggleState_7 == false) ? digitalWrite(RelayPin7, LOW) : digitalWrite(RelayPin7, HIGH);
  182.         param->updateAndReport(val);
  183.       }
  184.  
  185.     } else if(strcmp(device_name, deviceName_8) == 0) {
  186.      
  187.       Serial.printf("Switch value = %s\n", val.val.b? "true" : "false");
  188.  
  189.       if(strcmp(param_name, "Power") == 0) {
  190.         Serial.printf("Received value = %s for %s - %s\n", val.val.b? "true" : "false", device_name, param_name);
  191.         toggleState_8 = val.val.b;
  192.         (toggleState_8 == false) ? digitalWrite(RelayPin8, LOW) : digitalWrite(RelayPin8, HIGH);
  193.         param->updateAndReport(val);
  194.       }  
  195.     }
  196. }
  197.  
  198. void manual_control()
  199. {
  200.   if (digitalRead(SwitchPin1) == LOW && SwitchState_1 == LOW) {
  201.     digitalWrite(RelayPin1, LOW);
  202.     toggleState_1 = 1;
  203.     SwitchState_1 = HIGH;
  204.     my_switch1.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_1);
  205.     Serial.println("Switch-1 on");
  206.   }
  207.   if (digitalRead(SwitchPin1) == HIGH && SwitchState_1 == HIGH) {
  208.     digitalWrite(RelayPin1, HIGH);
  209.     toggleState_1 = 0;
  210.     SwitchState_1 = LOW;
  211.     my_switch1.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_1);
  212.     Serial.println("Switch-1 off");
  213.   }
  214.   if (digitalRead(SwitchPin2) == LOW && SwitchState_2 == LOW) {
  215.     digitalWrite(RelayPin2, LOW);
  216.     toggleState_2 = 1;
  217.     SwitchState_2 = HIGH;
  218.     my_switch2.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_2);
  219.     Serial.println("Switch-2 on");
  220.   }
  221.   if (digitalRead(SwitchPin2) == HIGH && SwitchState_2 == HIGH) {
  222.     digitalWrite(RelayPin2, HIGH);
  223.     toggleState_2 = 0;
  224.     SwitchState_2 = LOW;
  225.     my_switch2.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_2);
  226.     Serial.println("Switch-2 off");
  227.   }
  228.   if (digitalRead(SwitchPin3) == LOW && SwitchState_3 == LOW) {
  229.     digitalWrite(RelayPin3, LOW);
  230.     toggleState_3 = 1;
  231.     SwitchState_3 = HIGH;
  232.     my_switch3.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_3);
  233.     Serial.println("Switch-3 on");
  234.   }
  235.   if (digitalRead(SwitchPin3) == HIGH && SwitchState_3 == HIGH) {
  236.     digitalWrite(RelayPin3, HIGH);
  237.     toggleState_3 = 0;
  238.     SwitchState_3 = LOW;
  239.     my_switch3.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_3);
  240.     Serial.println("Switch-3 off");
  241.   }
  242.   if (digitalRead(SwitchPin4) == LOW && SwitchState_4 == LOW) {
  243.     digitalWrite(RelayPin4, LOW);
  244.     toggleState_4 = 1;
  245.     SwitchState_4 = HIGH;
  246.     my_switch4.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_4);
  247.     Serial.println("Switch-4 on");
  248.   }
  249.   if (digitalRead(SwitchPin4) == HIGH && SwitchState_4 == HIGH) {
  250.     digitalWrite(RelayPin4, HIGH);
  251.     toggleState_4 = 0;
  252.     SwitchState_4 = LOW;
  253.     my_switch4.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_4);
  254.     Serial.println("Switch-4 off");
  255.   }
  256.   if (digitalRead(SwitchPin5) == LOW && SwitchState_5 == LOW) {
  257.     digitalWrite(RelayPin5, LOW);
  258.     toggleState_5 = 1;
  259.     SwitchState_5 = HIGH;
  260.     my_switch5.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_5);
  261.     Serial.println("Switch-5 on");
  262.   }
  263.   if (digitalRead(SwitchPin5) == HIGH && SwitchState_5 == HIGH) {
  264.     digitalWrite(RelayPin5, HIGH);
  265.     toggleState_5 = 0;
  266.     SwitchState_5 = LOW;
  267.     my_switch5.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_5);
  268.     Serial.println("Switch-5 off");
  269.   }
  270.   if (digitalRead(SwitchPin6) == LOW && SwitchState_6 == LOW) {
  271.     digitalWrite(RelayPin6, LOW);
  272.     toggleState_6 = 1;
  273.     SwitchState_6 = HIGH;
  274.     my_switch6.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_6);
  275.     Serial.println("Switch-6 on");
  276.   }
  277.   if (digitalRead(SwitchPin6) == HIGH && SwitchState_6 == HIGH) {
  278.     digitalWrite(RelayPin6, HIGH);
  279.     toggleState_6 = 0;
  280.     SwitchState_6 = LOW;
  281.     my_switch6.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_6);
  282.     Serial.println("Switch-6 off");
  283.   }
  284.   if (digitalRead(SwitchPin7) == LOW && SwitchState_7 == LOW) {
  285.     digitalWrite(RelayPin7, LOW);
  286.     toggleState_7 = 1;
  287.     SwitchState_7 = HIGH;
  288.     my_switch7.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_7);
  289.     Serial.println("Switch-7 on");
  290.   }
  291.   if (digitalRead(SwitchPin7) == HIGH && SwitchState_7 == HIGH) {
  292.     digitalWrite(RelayPin7, HIGH);
  293.     toggleState_7 = 0;
  294.     SwitchState_7 = LOW;
  295.     my_switch7.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_7);
  296.     Serial.println("Switch-7 off");
  297.   }
  298.   if (digitalRead(SwitchPin8) == LOW && SwitchState_8 == LOW) {
  299.     digitalWrite(RelayPin8, LOW);
  300.     toggleState_8 = 1;
  301.     SwitchState_8 = HIGH;
  302.     my_switch8.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_8);
  303.     Serial.println("Switch-8 on");
  304.   }
  305.   if (digitalRead(SwitchPin8) == HIGH && SwitchState_8 == HIGH) {
  306.     digitalWrite(RelayPin8, HIGH);
  307.     toggleState_8 = 0;
  308.     SwitchState_8 = LOW;
  309.     my_switch8.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_8);
  310.     Serial.println("Switch-8 off");
  311.   }
  312. }  
  313.  
  314. void setup()
  315. {
  316.     uint32_t chipId = 0;
  317.    
  318.     Serial.begin(115200);
  319.  
  320.     Timer.setInterval(500);
  321.    
  322.     // Set the Relays GPIOs as output mode
  323.     pinMode(RelayPin1, OUTPUT);
  324.     pinMode(RelayPin2, OUTPUT);
  325.     pinMode(RelayPin3, OUTPUT);
  326.     pinMode(RelayPin4, OUTPUT);
  327.     pinMode(RelayPin5, OUTPUT);
  328.     pinMode(RelayPin6, OUTPUT);
  329.     pinMode(RelayPin7, OUTPUT);
  330.     pinMode(RelayPin8, OUTPUT);  
  331.     pinMode(wifiLed, OUTPUT);
  332.    
  333.     // Configure the input GPIOs
  334.     pinMode(SwitchPin1, INPUT_PULLUP);
  335.     pinMode(SwitchPin2, INPUT_PULLUP);
  336.     pinMode(SwitchPin3, INPUT_PULLUP);
  337.     pinMode(SwitchPin4, INPUT_PULLUP);
  338.     pinMode(SwitchPin5, INPUT_PULLUP);
  339.     pinMode(SwitchPin6, INPUT_PULLUP);
  340.     pinMode(SwitchPin7, INPUT_PULLUP);
  341.     pinMode(SwitchPin8, INPUT_PULLUP);
  342.     pinMode(gpio_reset, INPUT);
  343.    
  344.     // Write to the GPIOs the default state on booting
  345.     digitalWrite(RelayPin1, !toggleState_1);
  346.     digitalWrite(RelayPin2, !toggleState_2);
  347.     digitalWrite(RelayPin3, !toggleState_3);
  348.     digitalWrite(RelayPin4, !toggleState_4);
  349.     digitalWrite(RelayPin5, !toggleState_5);
  350.     digitalWrite(RelayPin6, !toggleState_6);
  351.     digitalWrite(RelayPin7, !toggleState_7);
  352.     digitalWrite(RelayPin8, !toggleState_8);
  353.     digitalWrite(wifiLed, LOW);
  354.  
  355.     if (aht.begin()) {
  356.     Serial.println("Found AHT10");
  357.     } else {
  358.     Serial.println("Didn't find AHT10");
  359.     }
  360.  
  361.     Node my_node;    
  362.     my_node = RMaker.initNode("InDoor Control Unit");
  363.  
  364.     //Standard switch device
  365.     my_switch1.addCb(write_callback);
  366.     my_switch2.addCb(write_callback);
  367.     my_switch3.addCb(write_callback);
  368.     my_switch4.addCb(write_callback);
  369.     my_switch5.addCb(write_callback);
  370.     my_switch6.addCb(write_callback);
  371.     my_switch7.addCb(write_callback);
  372.     my_switch8.addCb(write_callback);
  373.  
  374.     //Add switch device to the node  
  375.     my_node.addDevice(my_switch1);
  376.     my_node.addDevice(my_switch2);
  377.     my_node.addDevice(my_switch3);
  378.     my_node.addDevice(my_switch4);
  379.     my_node.addDevice(my_switch5);
  380.     my_node.addDevice(my_switch6);
  381.     my_node.addDevice(my_switch7);
  382.     my_node.addDevice(my_switch8);
  383.     my_node.addDevice(my_switch9);
  384.     my_node.addDevice(my_switch10);
  385.  
  386.     //This is optional
  387.     RMaker.enableOTA(OTA_USING_PARAMS);
  388.     //If you want to enable scheduling, set time zone for your region using setTimeZone().
  389.     //The list of available values are provided here https://rainmaker.espressif.com/docs/time-service.html
  390.     // RMaker.setTimeZone("Asia/Shanghai");
  391.     // Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone
  392.     RMaker.enableTZService();
  393.     RMaker.enableSchedule();
  394.  
  395.     //Service Name
  396.     for(int i=0; i<17; i=i+8) {
  397.       chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;
  398.     }
  399.  
  400.     Serial.printf("\nChip ID:  %d Service Name: %s\n", chipId, service_name);
  401.  
  402.     Serial.printf("\nStarting ESP-RainMaker\n");
  403.     RMaker.start();
  404.  
  405.     WiFi.onEvent(sysProvEvent);
  406. #if CONFIG_IDF_TARGET_ESP32
  407.     WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name);
  408. #else
  409.     WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE, WIFI_PROV_SECURITY_1, pop, service_name);
  410. #endif
  411.  
  412.     my_switch1.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, false);
  413.     my_switch2.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, false);
  414.     my_switch3.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, false);
  415.     my_switch4.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, false);
  416.     my_switch5.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, false);
  417.     my_switch6.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, false);
  418.     my_switch7.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, false);
  419.     my_switch8.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, false);
  420.     my_switch9.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, false);
  421.     my_switch10.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, false);
  422. }
  423.  
  424. void loop()
  425. {
  426.  
  427.     if(Timer.isReady()){
  428.       Serial.println("Sending Sensor´s Data");
  429.       Send_Sensor();
  430.       Timer.reset();
  431.     }
  432.    
  433.     // Read GPIO0 (external button to reset device
  434.     if(digitalRead(gpio_reset) == LOW) { //Push button pressed
  435.         Serial.printf("Reset Button Pressed!\n");
  436.         // Key debounce handling
  437.         delay(100);
  438.         int startTime = millis();
  439.         while(digitalRead(gpio_reset) == LOW) delay(50);
  440.         int endTime = millis();
  441.  
  442.         if ((endTime - startTime) > 10000) {
  443.           // If key pressed for more than 10secs, reset all
  444.           Serial.printf("Reset to factory.\n");
  445.           RMakerFactoryReset(2);
  446.         } else if ((endTime - startTime) > 3000) {
  447.           Serial.printf("Reset Wi-Fi.\n");
  448.           // If key pressed for more than 3secs, but less than 10, reset Wi-Fi
  449.           RMakerWiFiReset(2);
  450.         }
  451.     }
  452.     //delay(100);
  453.  
  454.     if (WiFi.status() != WL_CONNECTED)
  455.     {
  456.       //Serial.println("WiFi Not Connected");
  457.       digitalWrite(wifiLed, false);
  458.     }
  459.     else
  460.     {
  461.       //Serial.println("WiFi Connected");
  462.       digitalWrite(wifiLed, true);
  463.     }
  464.  
  465.     //manual_control();
  466. }
  467.  
  468. void Send_Sensor()
  469. {
  470.     sensors_event_t humidity, temp;
  471.   aht.getEvent(&humidity, &temp);
  472.  
  473.   temperatura     = temp.temperature;
  474.   humedad = humidity.relative_humidity;
  475.  
  476.   Serial.print("Temperatura: ");
  477.   Serial.println(temperatura);
  478.   Serial.print("Humedad: ");
  479.   Serial.println(humedad);
  480.  
  481.   my_switch9.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, temperatura);
  482.   my_switch10.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, humedad);
  483. }

ZANTERA
Posts: 2
Joined: Thu Nov 17, 2022 6:24 pm

Re: ESP RainMaker Sensor Update Values

Postby ZANTERA » Wed Nov 30, 2022 3:42 am

endlessparadigm wrote:
Sun Feb 20, 2022 11:50 pm
Have you attached the callback to the device? Are you able to see serial print output?
In the serial monitor i can see the variables

this two:
Serial.println(temperatura);
and
Serial.println(humedad);

but i get null when y try to update to the app

my_switch9.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, temperatura);
my_switch10.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, humedad);

im using Rainmaker 2.0.3 because with 2.0.4 i had problems conecting with the app
  1. void Send_Sensor()
  2. {
  3.   sensors_event_t humidity, temp;
  4.   aht.getEvent(&humidity, &temp);
  5.  
  6.   temperatura     = temp.temperature;
  7.   humedad = humidity.relative_humidity;
  8.  
  9.   Serial.print("Temperatura: ");
  10.   Serial.println(temperatura);
  11.   Serial.print("Humedad: ");
  12.   Serial.println(humedad);
  13.  
  14.   my_switch9.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, temperatura);
  15.   my_switch10.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, humedad);
  16. }

sanketwadekar
Posts: 32
Joined: Tue Jul 26, 2022 10:08 am

Re: ESP RainMaker Sensor Update Values

Postby sanketwadekar » Wed Nov 30, 2022 10:45 am

ZANTERA wrote:
Wed Nov 30, 2022 3:42 am
endlessparadigm wrote:
Sun Feb 20, 2022 11:50 pm
Have you attached the callback to the device? Are you able to see serial print output?
In the serial monitor i can see the variables

this two:
Serial.println(temperatura);
and
Serial.println(humedad);

but i get null when y try to update to the app
  1.   my_switch9.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, temperatura);
  2.   my_switch10.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, humedad);
Hello,
In the above code, you have passed ESP_RMAKER_DEF_POWER_NAME as a parameter name, but the device you've created is Temperature Sensor which does not have a parameter named "Power". If you want to update the temperature value of the sensor, pass ESP_RMAKER_DEF_TEMPERATURE_NAME instead.

Code: Select all

  my_switch9.updateAndReportParam(ESP_RMAKER_DEF_TEMPERATURE_NAME, temperatura);
  my_switch10.updateAndReportParam(ESP_RMAKER_DEF_TEMPERATURE_NAME, humedad);

Who is online

Users browsing this forum: No registered users and 16 guests