CAYENNE_IN does not work CAYENNE_OUT does


#1

Arduino Uno with W5100 ethernet shield

WEB Dashboard

When creating sensors, using CAYENNE_OUT, for the most part works. When creating actuators and using CAYENNE_IN nothing happens and Arduino UNO goes off line. I just change IN to OUT and it works. All I am doing is printing a line to the console.

Also, have used 2 raspberry pi’s no problems. 2 different arduino’s produce the same condition.

Sample: (from dashboard)

#define VIRTUAL_CHANNEL 2
#define ACTUATOR_PIN 11 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.

void setup()
{
Serial.begin(9600);
pinMode(ACTUATOR_PIN, OUTPUT);
Cayenne.begin(username, password, clientID);
}

void loop()
{
Serial.println(“In loop()”);
Cayenne.loop();
}

// This function is called when data is sent from Cayenne.
CAYENNE_IN(VIRTUAL_CHANNEL)
{
Serial.println(" In Cayenne");
//int value = getValue.asInt();
//CAYENNE_LOG(“Channel %d, pin %d, value %d”, VIRTUAL_CHANNEL, ACTUATOR_PIN, value);
// Write the value received to the digital pin.
//digitalWrite(ACTUATOR_PIN, value);
}

CAYENNE_IN never happens. Arduino is Offline on Dashboard.
Console:

12:55:39.905 -> [0] MAC: FE-62-B8-BE-1-EA
12:55:40.635 -> [726] IP: 192.168.120.83
12:55:40.669 -> [727] Connecting to mqtt.mydevices.com:1883
12:55:40.801 -> [893] Connected
12:55:40.868 -> In loop()
12:55:41.863 -> In loop()
12:55:42.859 -> In loop()
12:55:43.888 -> In loop()
12:55:44.884 -> In loop()
12:55:45.913 -> In loop()
12:55:46.909 -> In loop()
12:55:47.905 -> In loop()
12:55:48.933 -> In loop()
12:55:49.930 -> In loop()
12:55:50.927 -> In loop()

I change CAYANNE_IN to CAYENNE_OUT and it works. And now is is online in dashboard.
I have tried an Arduino Clone and a real Arduino., 2 different Ethernet shields.

Sample:

#define VIRTUAL_CHANNEL 2
#define ACTUATOR_PIN 11 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.

void setup()
{
Serial.begin(9600);
pinMode(ACTUATOR_PIN, OUTPUT);
Cayenne.begin(username, password, clientID);
}

void loop()
{
Serial.println(“In loop()”);
Cayenne.loop();
}

// This function is called when data is sent from Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL)
{
Serial.println(" In Cayenne");
//int value = getValue.asInt();
//CAYENNE_LOG(“Channel %d, pin %d, value %d”, VIRTUAL_CHANNEL, ACTUATOR_PIN, value);
// Write the value received to the digital pin.
//digitalWrite(ACTUATOR_PIN, value);
}

Console:

13:03:21.522 -> [0] MAC: FE-62-B8-BE-1-EA
13:03:22.187 -> [675] IP: 192.168.120.83
13:03:22.220 -> [676] Connecting to mqtt.mydevices.com:1883
13:03:22.585 -> [1046] Connected
13:03:22.618 -> In loop()
13:03:23.647 -> In loop()
13:03:24.643 -> In Cayenne
13:03:24.676 -> In loop()


#2

Is for reading data from cayenne and is called whenever you activate an actuator on the cayenne dashboard.


#3

I understand that. I was trying to just light an led. What I tried to display in my example is that the CAYENNE_IN(VIRTUAL_CHANNEL) function simply never executes.

If I even just put CAYENNE_IN(VIRTUAL_CHANNEL) in my sketch and load it on my arduino uno then I show offline on the web page. I change IN to OUT and it works like a champ. Shows online, print statement appears in the console, works as expected.

Using 2 different UNO’s, one is actual arduino. With 2 different ether shields. Using 1.8.8 Arduino IDE. CayenneMQTT 1.3.0

Is there any logging going on that I can view, debug out put or something?


#4

you can add #define CAYENNE_DEBUG to view the log.


#5

Here is the outcome. Loaded code below, compiled and operates ok.
in the CAYENNE_IN function is

CAYENNE_LOG(“Channel %d, pin %d, value %d”, VIRTUAL_CHANNEL, ACTUATOR_PIN, value);

Here is the console output with debug enabled

11:46:59.797 -> [0] MAC: FE-31-47-7-B3-AD
11:47:00.500 -> [726] IP: 192.168.120.88
11:47:00.547 -> [727] Connecting to mqtt.mydevices.com:1883
11:47:00.922 -> [1144] Connected
11:47:00.968 -> [1198] Publish: topic 4, channel 65534, value Arduino Uno, subkey , key
11:47:01.062 -> [1209] Publish: topic 6, channel 65534, value ATmega328P, subkey , key
11:47:01.156 -> [1285] Publish: topic 7, channel 65534, value 16000000, subkey , key
11:47:01.203 -> [1358] Publish: topic 5, channel 65534, value 1.3.0, subkey , key
11:47:01.293 -> [1429] Publish: topic 8, channel 65534, value W5100, subkey , key
11:47:12.370 -> [12588] Connection ok
11:47:22.465 -> [22669] Connection ok
11:47:32.560 -> [32750] Connection ok
11:47:42.668 -> [42830] Connection ok

Says Connection ok, but in mydevices.com web dashboard intermittently it says Offline. I restarted 3 tiimes. Now shows online. It never executes the IN function. No message to the console. Press button on page, just spins, nothng happens. logging does not change, just says ‘connection ok’.

Here is the code.

/*
Cayenne Light Switch Example

This sketch shows how to set up a Light Switch with Cayenne.

The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

Steps:

  1. In the Cayenne Dashboard add a new Light Switch Widget.
  2. Select a virtual channel number for the widget.
  3. Set the VIRTUAL_CHANNEL value below to virtual channel you selected.
  4. Attach the negative leg of an LED to ground and the other leg to the selected digital pin.
    Schematic:
    [Ground] – [LED] – [Resistor] – [Digital Pin]
  5. Set the ACTUATOR_PIN value below to the pin number you used when connecting your LED.
  6. Set the Cayenne authentication info to match the authentication info from the Dashboard.
  7. Compile and upload this sketch.
  8. Once the Arduino connects to the Dashboard you can use the widget button to turn the LED on and off.
    */
    #define CAYENNE_DEBUG
    #define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
    #include <CayenneMQTTEthernet.h>

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “xxx…”;
char password = “xxx…”;
char clientID = “xxx…”;

#define VIRTUAL_CHANNEL 2
#define ACTUATOR_PIN 6 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.

void setup()
{
Serial.begin(9600);
pinMode(ACTUATOR_PIN, OUTPUT);
Cayenne.begin(username, password, clientID);
}

void loop()
{
Cayenne.loop();
}

// This function is called when data is sent from Cayenne.
CAYENNE_IN(VIRTUAL_CHANNEL)
{
int value = getValue.asInt();
CAYENNE_LOG(“Channel %d, pin %d, value %d”, VIRTUAL_CHANNEL, ACTUATOR_PIN, value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN, value);
}


#6

you need send some data initially to keep the device online. it would a simple publish of millis() data using:

CAYENNE_OUT_DEFAULT()
{
	// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
	Cayenne.virtualWrite(0, millis());
	// Some examples of other functions you can use to send data.
	//Cayenne.celsiusWrite(1, 22.0);
	//Cayenne.luxWrite(2, 700);
	//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}