I’m a newbie and i’m start a new project.
I have one actuator (lampe) and one sensor (temperature)
How to assemble the two programs to have only one ?
Thx for your help ^^
I’m a newbie and i’m start a new project.
I have one actuator (lampe) and one sensor (temperature)
How to assemble the two programs to have only one ?
Thx for your help ^^
copy paste code from lamp into tempo.
Just like this ?
//Thermometre
#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[] = "";
char password[] = "";
char clientID[] = "";
#define SENSOR_PIN 0
#define VIRTUAL_CHANNEL 3
void setup()
{
Serial.begin(9600);
Cayenne.begin(username, password, clientID);
}
void loop()
{
Cayenne.loop();
}
// This function is called at intervals to send sensor data to Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL)
{
Cayenne.virtualWrite(VIRTUAL_CHANNEL, analogRead(SENSOR_PIN));
}
//Lampe
#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[] = "";
char password[] = "";
char clientID[] = "";
#define VIRTUAL_CHANNEL 2
#define ACTUATOR_PIN 2 // 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);
}
There are rehearsals … I can’t upload.
Remember to fill in your MQTT credentials
//Thermometre
#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[] = "";
char password[] = "";
char clientID[] = "";
#define SENSOR_PIN 0
#define VIRTUAL_CHANNEL 3
#define VIRTUAL_CHANNEL 2
#define ACTUATOR_PIN 2 // 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 at intervals to send sensor data to Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL)
{
Cayenne.virtualWrite(VIRTUAL_CHANNEL, analogRead(SENSOR_PIN));
}
// 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);
}
Thanks ! ^^