sorry if my english is bad
please help me to solve my project
i use 2 sensor ultrasonic with newping.h
if i use:
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#include <NewPing.h>
NewPing ultrasonic (5,4);
char ssid = “vivo1612”;
char wifiPassword = “99999999”;
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “0f3d2bb0-fe1b-11e9-84bb-8f71124cfdfb”;
char password = “4f7d89bc3da5581de2a04b1f9750da8430591389”;
char clientID = “0aefc090-0153-11eb-a67f-15e30d90bbf4”;
unsigned long lastMillis = 0;
#define TRIGGER 5
#define ECHO 4
#define VIRTUAL_CHANNEL 1
void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}
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(0)
{
// 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);
}
// 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_DEFAULT()
{
CAYENNE_LOG(“Channel %u, value %s”, request.channel, getValue.asString());
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);
}
CAYENNE_OUT(1)
{
int US1 = ultrasonic.ping_cm();
Serial.print(“Hasil Sensor 1 :”);
Serial.print(US1);
Serial.println(“cm”);
delay(100);
Cayenne.virtualWrite(1, US1, “prox”, “cm”);
}
its totally work…
but if i use:
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#include <NewPing.h>
NewPing ultrasonic (5,4);
NewPing ultrasonic2 (6,7);
// WiFi network info.
char ssid = “vivo1612”;
char wifiPassword = “99999999”;
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “0f3d2bb0-fe1b-11e9-84bb-8f71124cfdfb”;
char password = “4f7d89bc3da5581de2a04b1f9750da8430591389”;
char clientID = “0aefc090-0153-11eb-a67f-15e30d90bbf4”;
unsigned long lastMillis = 0;
#define TRIGGER 5
#define ECHO 4
#define VIRTUAL_CHANNEL 1
#define TRIGGER2 6
#define ECHO2 7
#define VIRTUAL_CHANNEL 2
void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}
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(0)
{
// 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);
}
// 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_DEFAULT()
{
CAYENNE_LOG(“Channel %u, value %s”, request.channel, getValue.asString());
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);
}
CAYENNE_OUT(1)
{
int US1 = ultrasonic.ping_cm();
Serial.print(“Hasil Sensor 1 :”);
Serial.print(US1);
Serial.println(“cm”);
delay(100);
Cayenne.virtualWrite(1, US1, “prox”, “cm”);
}
CAYENNE_OUT(2)
{
int US2 = ultrasonic2.ping_cm();
Serial.print(“Hasil Sensor 2 :”);
Serial.print(US2);
Serial.println(“cm”);
delay(100);
Cayenne.virtualWrite(2, US2, “prox”, “cm”);
}
itsn’t work
please help me to solve