instead of control close off in cayenne.I want automatic control according to the program in arduino.When I control 1 time, the automatic program will run continuously.But only if there is a control signal arduino has signal.If not controlled Arduino does not receive any signal.I want cayenne to constantly issue control signals
i did not understand what you meant.
I am not good at English sory.when there is a magnetic control signal cayenne arduino runs the program.when not controlled from cayenne , there is no signal coming arduino.Arduino only runs 1 times, do not run until there is a signal from cayenne next.Cayenne only needs to control it once.thanhk you
what are you referring to as magnetic control signal?
sorry. “signals by cayenne”. Cayenne signal output when there is a control effect.The program only runs once.The program will not be called when there is no signal by cayenne.??
can you share the code you are using?
Because I’m not good at English.when I control with cayenne, I only send 1 time value of 1 (0).
when I do not effect the signal received from cayenne is -1-1-1.I want to control only once, cayenne always sends 1 value.
Share the code.
Vào Th 3, 19 thg 3, 2019 vào lúc 14:52 Shramik salgaonkar via myDevices Cayenne Community mydevices@discoursemail.com đã viết:
i need the code that you have uploaded on your arduino.
when there is no signal sent from cayenne , the signal is received arduino -1-1-1
Vào Th 3, 19 thg 3, 2019 vào lúc 22:09 khánh học phan phankhanhhocvraks@gmail.com đã viết:
(Attachment sendnodemcu.ino is missing)
(Attachment arduinoreceive.ino is missing)
nodesend :
#include <Wire.h>
#include "Arduino.h"
#include <CayenneMQTTESP8266.h>
#define CAYENNE_PRINT Serial
const int SLAVE_ADDRESS = 8; //Slave arduino ID
uint8_t Buffer1[3];
int table[]={0,0,0};
int table1[]={0,0,0};
// tên và mật khẩu wifi thiết bị kết nối
char ssid[] = "";
char wifiPassword[] = "";
// --- Địa chỉ esp gửi dữ liệu lên cayenne
char username[] = "";
char password[] =
char clientID[] = "-f--";
//the data will be transmited via table as to allow different data to be transfer.
void setup ()
{
Wire.begin ();
Serial.begin (9600); // start serial for output
Wire.begin(D1,D2);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
} // end of setup
void loop()
{
Wire.requestFrom(SLAVE_ADDRESS, 3);// request 3 bytes from slave device #8
//Cayenne.loop();
CAYENNE_OUT_DEFAULT()
{
for(int i=0;i<3;i++)//organizes the data from the slave in the table
{
int c = Wire.read(); // receive a byte as character
table[i]=c;
}
Cayenne.celsiusWrite(1, table[1] );// gửi dữ liệu đến channel 0 đã cài đặt trên cayenne
Cayenne.luxWrite(0, table[0]); // gửi dữ liệu đến channe 1 đã cài đặt trên cayenne
//displays the data
Serial.print('\n');
Serial.print(table[0]);
Serial.print('\t');
Serial.print(table[1]);
Serial.print('\t');
Serial.print(table[2]);
Serial.print('\n');
Serial.println("\r\n");
delay (500);
}
CAYENNE_IN(2) // tự động
{
int TD =getValue.asInt();
table1[0]= TD ;
if( table1[0]==1)
{
Wire.beginTransmission(8);
Buffer1[0]=table1[0];// nếu table1[0]= 1 thì chạy tự động
Wire.write(Buffer1,3);// cái này chỉ khi điều khiển nó mới gửi sang bên nhận
Wire.endTransmission();
}
else
{
Wire.beginTransmission(8);
Buffer1[0]=table1[0];
Wire.write(Buffer1,3);
Wire.endTransmission();
}
}
CAYENNE_IN(3) // điều khiển bơm
{
// transmit just this variable to the slave
int bom = getValue.asInt();
table1[1]=bom;
Wire.beginTransmission(8);
Buffer1[1]=table1[1];
Wire.write(Buffer1,3);
Wire.endTransmission();
}
CAYENNE_IN(5)
{
int den = getValue.asInt();
table1[2]= den ;
Wire.beginTransmission(8);
Buffer1[2]=table1[2];
Wire.write(Buffer1,3);
Wire.endTransmission();
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
arduinoreceive
#include <Wire.h>
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22
#define DK_bom 10 // xuất tín hiệu điều khiển bơm
#define DK_den 8 // xuất tín hiệu điều khiển động cơ
#define DK_Quat 9// dieu khien quat thong gio
boolean denT = 0;
boolean bomT = 0;
boolean quatT = 0;
int table[]={0,0,0};
int table1[]={0,0,0};
int Work=0;
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
pinMode(DK_bom, OUTPUT);
pinMode(DK_Quat, OUTPUT);
pinMode(DK_den , OUTPUT);
digitalWrite(DK_bom, LOW);
digitalWrite(DK_Quat, LOW);
digitalWrite(DK_den , LOW);
Wire.begin(8); // join i2c bus with address #8
Wire.onRequest(requestEvent); // register event
Wire.onReceive(receiveEvent); // register event
dht.begin();
}
void loop() {
delay(2200);
byte doam = dht.readHumidity();
// Read temperature as Celsius (the default)
byte nhietdo = dht.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(doam) || isnan(nhietdo)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Humidity: ");
Serial.print(doam);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(nhietdo);
Serial.print(" *C ");
Serial.println("\r\n");
int z=255;
table[0]=doam;
table[1]=nhietdo;
table[2]=z;
}
void dk_td(void)
{
byte doam = dht.readHumidity();
// Read temperature as Celsius (the default)
byte nhietdo = dht.readTemperature();
Serial.print("DIEU KHIEN TU DONG");
if (( doam > 85) && (doam < 95))
{
if ( nhietdo < 26)
{
digitalWrite(DK_bom, LOW);
digitalWrite(DK_Quat, LOW);
digitalWrite(DK_den , HIGH);
bomT = 0;
quatT = 0;
denT = 1;
}
else if ( nhietdo > 37)
{
digitalWrite(DK_Quat, LOW);
digitalWrite(DK_den , LOW);
digitalWrite( DK_bom , HIGH);
quatT = 0;
denT = 0;
bomT = 1;
}
else
{
digitalWrite(DK_bom, LOW);
digitalWrite(DK_Quat, LOW);
digitalWrite(DK_den , LOW);
denT = 0;
bomT = 0;
quatT = 0;
}
Serial.print("%bom: ");
Serial.print(bomT);
Serial.print("Quat: ");
Serial.println(quatT);
Serial.print("%den: ");
Serial.println(denT);
}
else if ( doam < 84)
{
if ( nhietdo < 26)
{
digitalWrite(DK_Quat, LOW);
digitalWrite( DK_bom , HIGH);
digitalWrite(DK_den , HIGH);
quatT = 0;
bomT = 1;
denT = 1;
}
else
{
digitalWrite(DK_Quat, LOW);
digitalWrite(DK_den , LOW);
digitalWrite( DK_bom , HIGH);
denT = 0;
quatT = 0;
bomT = 1;
}
Serial.print("%bom: ");
Serial.print(bomT);
Serial.print("Quat: ");
Serial.println(quatT);
Serial.print("%den: ");
Serial.println(denT);
}
else
{
if ( nhietdo < 26 )
{
digitalWrite( DK_bom , LOW);
digitalWrite(DK_Quat, LOW);
digitalWrite(DK_den , HIGH);
bomT = 0;
quatT = 0;
denT = 1;
}
else
{
digitalWrite(DK_den , LOW);
digitalWrite( DK_bom , LOW);
digitalWrite(DK_Quat, HIGH);
denT = 0;
bomT = 0;
quatT = 1;
}
Serial.print("%bom: ");
Serial.print(bomT);
Serial.print("Quat: ");
Serial.println(quatT);
Serial.print("%DK_Den: ");
Serial.println(denT);
}
}
void requestEvent()
{
uint8_t Buffer[3];
Buffer[0]=table[0];
Buffer[1]=table[1];
Buffer[2]=table[2];
Wire.write(Buffer,3);
}
// chỉ chạy tới đây khi có tín hiệu gửi
void receiveEvent(int howMany)
{
for(int i=0;i<3;i++)
{
int b = Wire.read();// nhận tín hiệu nhưng chỉ có tín hiệu gửi thì mới tiến hành đọc anh
table1[i]=b;
}
while(table1[0] == 1)
{
dk_td();// e muốn chỉ gửi 1 lần nó sẽ chạy từ đầu tới đây anh rồi vòng lại từ đầu anh
table1[0] = 1;
for(int i=0;i<3;i++)
{
int b = Wire.read();
table1[i]=b;
}
//Serial.print("DIEU KHIEN TU DONG");
//table1[0]=1;
}
if(table1[1] == 1)
{
digitalWrite(DK_bom, HIGH);
table1[1] = 1;
Serial.print("bat bom" );
}
else
{
digitalWrite(DK_bom, LOW);
Serial.print("tat bom" );
}
if( table1[2]==1)
{
digitalWrite(DK_den, HIGH);
table1[2] =1;
Serial.print("bat DK_Den" );
}
else
{
digitalWrite(DK_den, LOW);
Serial.print("tắt den" );
}
Serial.println("\r\n");
}
so what i understand is you are using two arduino to communicate via I2C and the issue is the receiver arduino receives value (-1-1-1)?
so why are sending data as an array? any specific reason for that?
When there is a cayenne signal, get value is 1 or 0.Only receive 1 first control.Then when there is no control signal cayenne, The signal received is -1-1-1.I want when not controlled ,Still get the previous value is 1 or 0.
try this code:
i have used arduino uno and mega.
Sender code:
/*
This example shows how to connect to Cayenne using an Ethernet W5100 shield and send/receive sample data.
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. Set the Cayenne authentication info to match the authentication info from the Dashboard.
2. Compile and upload the sketch.
3. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.
*/
#include <Wire.h>
//#define CAYENNE_DEBUG // Uncomment to show debug messages
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>
char username[] = "";
char password[] = "";
char clientID[] = "";
void setup() {
Wire.begin();
Serial.begin(9600);
Cayenne.begin(username, password, clientID);
}
void loop() {
Cayenne.loop();
}
// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
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());
}
// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN(16)
{
int x = getValue.asInt();
Wire.beginTransmission(8);
Wire.write("channel 16 value is ");
Wire.write(x);
Wire.endTransmission();
}
CAYENNE_IN(5)
{
int y = getValue.asInt();
Wire.beginTransmission(8);
Wire.write("channel 5 value is ");
Wire.write(y);
Wire.endTransmission();
}
Receiver code:
#include <Wire.h>
void setup() {
Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
Serial.println("reciever");
}
void loop() {
delay(100);
}
int x;
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {
while (1 < Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
}
thank you very much
hoc
I use a nodemcu (esp 8266). can you use it you use shield W5100 Ethernet, i can’t use it. do you have code nodemcu?