Cayenne ESp8266 mqtt

how to manage Sync.All function with cayenne esp8266 in mqtt mode as no virtual pins in mqtt.

I don’t understand what your looking for, are you asking how to send multiple values to the MQTT dashboard? If so you just change your channel in the topic. The documentation for the MQTT API is here Cayenne Docs If you’re looking for something else let me know

I want to synchronize the ardino pins voltages when ardino come online just as using sync all function. …I read this function is only for virtual pins but ESP MQTT has no virtual pin option

Yes, you are correct, right now there is no sync while using MQTT. As a workaround you could write a function that runs once on the first loop that downloads all the values and sets the pins to the correct values (manual sync).

Well thnksKindly you may help me in logic building for data capture from dashboard…

Dear Adam, Is there a possibility to send an analogue value from the dashboard to a WeMos D1 mini using MQTT … TODAY ? … as we are 8 months later … :wink:
Sending from the WeMos D1 mini to the Dashboard works very well AND is VERY stable !!!
Thanks
(PS: with a Arduino YUN and without MQTT the YUN was VERY UNSTABLE … only worked a couple of hours … tried it with Dragino YUN Shield on a MEGA … same instability problem … :frowning: … can’t get it solved)

Yes, it is certainly possible. You can see the documentation here Cayenne Docs

@adam , Hi Adam, thanks for the VERY Quick answer, … the link is jumping me to “Cayenne Low Power Payload” … is that what I need ?
Is there somewhere a small example sketch available that let the WeMos D1 mini receive an analogue value from the dashboard and writes it to Serial output ? (I have spend many many hours over the last 7 days to find/solve this … without success … tried digital signal too to simpligy problem …)
Another question: I saw that my router stopped incoming messages to port 23 when I tried to send a digital value from the dashboard. I forwarded the port 23 to the IP of the WeMos D1 mini and also on the same port 23.
Is that OK ? When I scan the WeMos D1 mini I can not find ANY OPEN PORT ??? … My YUNs show many open ports to communicate with … DO I NEED PORT FORWARDING ? From what port and to what port ? Thanks

Hmm yes that might be an out of date link. Here is the correct one, sorry myDevices | Simplify Sensor Deployments

Port 23 is telnet, not sure what’s going on there as Cayenne doesn’t use it.

The ESP8266 probably doesn’t respond to port scanning, that is fine as the device doesn’t need any ports open. Port 1883 will need to be forwarded on the router. Sorry, you don’t need to forward, just not have the port specifically blocked by the router.

@adam
Thanks Adam. Looked again in the info you poited to (looked at it in the past too).
I’m sorry I think I’m missing something … but I can not find any example sketch or other info how to do it that will work.
I have put example code in my sketch but nothing happens. See my code below.
The Write statements to the Serial in the subroutine “CAYENNE_IN(V2)” are never executed.
Can’t find what I’m doing wrong … sorry … :wink: … do you see it ?
Image of my actuator dashboard setting after the code.
Thanks,

_**/* t7.ino **_
_**     * WeMos D1 mini connecting to Cayenne  Reading SI7021 sensor for Temperature and Humidity **_
_**     * TRY  <==>  sending data from WWW to WeMos D1 Mini ... like Temp. setpoint ... or an Digital Out status**_
_**     * **_
_**     This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.**_
_**     Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling. **_
_**    */**_

_**    //#define CAYENNE_DEBUG**_
_**    #define CAYENNE_PRINT Serial**_
_**    #include <CayenneMQTTESP8266.h>**_
_**    #include <Wire.h>**_
_**    #include <SI7021.h>**_
_**    SI7021 sensor;**_

_**    // WiFi network info.**_
_**    char ssid[] = "xxxx";**_
_**    char wifiPassword[] = "yyyy";**_

_**    // Cayenne authentication info. This should be obtained from the Cayenne Dashboard.**_
_**    char username[] = "aaaa";**_
_**    char password[] = "bbbb";**_
_**    char clientID[] = "cccc";**_

_**    unsigned long lastMillis = 0;**_

_**    void setup() {**_
_**        pinMode(2, OUTPUT);  // set onboard LED as output (arduino pin #2  =  D4 ... can be also default name  BUILTIN_LED )**_
_**        pinMode(BUILTIN_LED, OUTPUT);  // set onboard LED as output (arduino pin #2  =  D4 ... can be also default name  BUILTIN_LED )**_
_**        digitalWrite(BUILTIN_LED, 1);  // sets the LED to OFF  ... works REVERSE ??? !!!**_
_**        sensor.begin(4,5);  /// used Arduino pin 4 & 5 (D2 & D1) as SDA & SCL**_
_**      	Serial.begin(9600);**_
_**      	Cayenne.begin(username, password, clientID, ssid, wifiPassword);**_
_**    }**_

_**    void loop() {**_
_**        float temperature = 0.01* sensor.getCelsiusHundredths();**_
_**        Cayenne.virtualWrite(0, temperature, "temp", "c"); // (chan# , value , "type value" , "unit value")**_
_**        Serial.print("Temp.: "+String(temperature,1));**_
_**      **_
_**        int humidity = sensor.getHumidityPercent();**_
_**        Cayenne.virtualWrite(1, humidity, "rel_hum", "p"); // (chan# , value , "type value" , "unit value")**_
_**        Serial.println("     Hum.: "+String(humidity));**_
_**      **_
_**        delay(10000);**_
_**      **_
_**        Cayenne.syncVirtual(V2) ; // get V2 if posted by Cayenne => auto-call subroutine ?**_
_**    }**_
_**    //==============================================================================================**_

_**    //  This function will be called every time a Dashboard widget writes a value to Virtual Pin V2.**_
_**    CAYENNE_IN(V2)**_
_**    {**_
_**        Serial.println("CAYENNE_IN(V2) running");**_
_**          **_
_**        CAYENNE_LOG("Got a value: %s", getValue.asStr());**_
_**        int currentValue = getValue.asInt();**_
_**        **_
_**        if (currentValue == 0)**_
_**        {**_
_**          Serial.println("CAYENNE_IN 2 == 0 ");**_
_**          digitalWrite(2, LOW);**_
_**        }**_
_**        else**_
_**        {**_
_**          Serial.println("CAYENNE_IN 2 > 0 ");**_
_**          digitalWrite(2, HIGH);**_
_**        }  **_
_**    }**_

Formatting of code did not work … this is a clean PASTE …

/* t7.ino 
 * WeMos D1 mini connecting to Cayenne  Reading SI7021 sensor for Temperature and Humidity 
 * TRY  <==>  sending data from WWW to WeMos D1 Mini ... like Temp. setpoint ... or an Digital Out status
 * 
 This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
 Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling. 
*/

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#include <Wire.h>
#include <SI7021.h>
SI7021 sensor;

// WiFi network info.
char ssid[] = "xxxx";
char wifiPassword[] = "yyyy";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "aaaa";
char password[] = "bbbb";
char clientID[] = "cccc";

unsigned long lastMillis = 0;

void setup() {
    pinMode(2, OUTPUT);  // set onboard LED as output (arduino pin #2  =  D4 ... can be also default name  BUILTIN_LED )
    pinMode(BUILTIN_LED, OUTPUT);  // set onboard LED as output (arduino pin #2  =  D4 ... can be also default name  BUILTIN_LED )
    digitalWrite(BUILTIN_LED, 1);  // sets the LED to OFF  ... works REVERSE ??? !!!
    sensor.begin(4,5);  /// used Arduino pin 4 & 5 (D2 & D1) as SDA & SCL
  	Serial.begin(9600);
  	Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
    float temperature = 0.01* sensor.getCelsiusHundredths();
    Cayenne.virtualWrite(0, temperature, "temp", "c"); // (chan# , value , "type value" , "unit value")
    Serial.print("Temp.: "+String(temperature,1));
  
    int humidity = sensor.getHumidityPercent();
    Cayenne.virtualWrite(1, humidity, "rel_hum", "p"); // (chan# , value , "type value" , "unit value")
    Serial.println("     Hum.: "+String(humidity));
  
    delay(10000);
  
    Cayenne.syncVirtual(V2) ; // get V2 if posted by Cayenne => auto-call subroutine ?
}
//==============================================================================================

//  This function will be called every time a Dashboard widget writes a value to Virtual Pin V2.
CAYENNE_IN(V2)
{
    Serial.println("CAYENNE_IN(V2) running");
      
    CAYENNE_LOG("Got a value: %s", getValue.asStr());
    int currentValue = getValue.asInt();
    
    if (currentValue == 0)
    {
      Serial.println("CAYENNE_IN 2 == 0 ");
      digitalWrite(2, LOW);
    }
    else
    {
      Serial.println("CAYENNE_IN 2 > 0 ");
      digitalWrite(2, HIGH);
    }  
}

Try changing your CAYENNE_IN(V2) to just CAYENNE_IN(2); take out all the "V"s. Let us know if that did anything.

In regards to syncVirtual function, do you want it to always be off or on when the program initially loads? Or does it need to poll it when it boots?

@Jodi remove delay from main loop. use this instead.

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#include <Wire.h>
#include <SI7021.h>
SI7021 sensor;

// WiFi network info.
char ssid[] = "xxxx";
char wifiPassword[] = "yyyy";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "aaaa";
char password[] = "bbbb";
char clientID[] = "cccc";

unsigned long lastMillis = 0;

void setup() {
    pinMode(2, OUTPUT);  // set onboard LED as output (arduino pin #2  =  D4 ... can be also default name  BUILTIN_LED )
    pinMode(BUILTIN_LED, OUTPUT);  // set onboard LED as output (arduino pin #2  =  D4 ... can be also default name  BUILTIN_LED )
    digitalWrite(BUILTIN_LED, 1);  // sets the LED to OFF  ... works REVERSE ??? !!!
    sensor.begin(4,5);  /// used Arduino pin 4 & 5 (D2 & D1) as SDA & SCL
    Serial.begin(9600);
    Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}
void loop() {
  Cayenne.loop();
  float temperature = 0.01 * sensor.getCelsiusHundredths();
  int humidity = sensor.getHumidityPercent();

  //Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
  if (millis() - lastMillis > 10000) {
    lastMillis = millis();
    //Write data to Cayenne here. This example just sends the current uptime in milliseconds.
    Cayenne.virtualWrite(0, temperature, "temp", "c"); // (chan# , value , "type value" , "unit value")
    Cayenne.virtualWrite(1, humidity, "rel_hum", "p"); // (chan# , value , "type value" , "unit value")

  }
}
CAYENNE_IN(2)
{
  Serial.println("CAYENNE_IN(V2) running");
  CAYENNE_LOG("Got a value: %s", getValue.asStr()); _
  int currentValue = getValue.asInt();
  if (currentValue == 0)
  {
    Serial.println("CAYENNE_IN 2 == 0 ");
    digitalWrite(2, LOW);
  }
  else
  {
    Serial.println("CAYENNE_IN 2 > 0 ");
    digitalWrite(2, HIGH);
  }
}

@shramik_salgaonkar
@vapor83
@adam
Thank you all very much for your help.
I have located the basic error … in void loop() I did NOT put Cayenne.loop() … got lost … this was the BASIC problem.
For writing to dashboard it is not needed but for receiving data IT IS !
I can confirm that Virtual Pins do not work to receive values … I tested 2 in stead if V2 in the past but without “Cayenne.loop()” both do not work … :wink:
I also confirm that port forwarding is NOT needed as Adam stated !
Thanks again to all, my problem is solved !!!

2 Likes