Bonjour a tous,
J’ai pour projet de domotiser un peu ma maison. Jusque la je me servais d’un serveur web sur Arduino et de plusieurs cartes relais connectées, J’avais des problemes de lenteur et on m’avait conseillé de passer sur raspberry et domoticz et de regarder la librairie Mysensor.
Chose faite, cepandant j’ai quand meme besoin d’avoir des relais directement sur la carte arduino et non en sans fil.
J’en suis à faire des essais : Domoticz tourne, il reconnait ma passerelle et mes capteurs et actionneurs (une sonde temp, la led 13 de l’Arduino et 4 relais sur 4 sorties de l’arduino).
Lorsque je clique sur l’interrupteur:
- le relais change bien d’état
- La lampe est bien allumée sur Domoticz (icone)
mais Domoticz me dit :
"Erreur d’envoi de la commande à l’interrupteur, vérifiez le dispositif/matériel "
et dans le log :
2019-08-21 19:58:30.043 (Arduino uno) Light/Switch (Relai 1)
2019-08-21 19:58:30.061 Error: MySensors: Repeating previous command (2/2)
2019-08-21 19:58:30.161 Error: MySensors: Command not received by Node !! (node_id: 12, child_id: 5)
Le pb vient du code Arduino j’ai adapter un code ou il n’y avait que la sonde et la Led 13 et ca fonctionnait nickel.
Il y a un truc que je dois pas faire comme il faut avec les serial print ou peut etre les delay mais je ne sais pas quoi!!(ca fait 2 jours que je tente des trucs mais toujours au meme point!)
Voici le code arduino:
#define LED_LIGHT 13
#define RELAY_PIN 4 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define NUMBER_OF_RELAYS 4 // Total number of attached relays
// named constant for the pin the sensor is connected to
const int sensorPin = A0;
const long interval = 30000; // interval of sensors
const long intervalPublish = 3000000; // interval of publish
unsigned long previousMillis = 0; // will store last time LED was updated
unsigned long previousPublish = 0;
const int numReadings = 150;
unsigned readings[numReadings]; // the readings from the analog input
int index = 0; // the index of the current reading
unsigned long total = 0; // the running total
unsigned int average = 0; // the average
void setup() {
for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
// Then set relay pins in output mode
pinMode(pin, OUTPUT);
// Set relay to last known state (using eeprom storage)
// digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
}
pinMode(LED_LIGHT, OUTPUT);
// open a serial connection to display values
Serial.begin(115200);
delay(100);
Serial.println();
delay(100);
// MySensors serial protocol:
// node-id;child-sensor-id;message-type;ack;sub-type;payload\n
Serial.println("12;1;0;0;17;Arduino UNO\n");
Serial.println("12;3;0;0;6;Termometro TMP36\n");
Serial.println("12;4;0;0;3;LED Light\n");
Serial.println("12;5;0;0;3;Relai 1\n");
Serial.println("12;6;0;0;3;Relai 2\n");
Serial.println("12;7;0;0;3;Relai 3\n");
Serial.println("12;8;0;0;3;Relai 4\n");
}
void loop() {
unsigned long currentMillis = millis();
String ch;
total= total - readings[index]; // subtract the last reading:
delay(1); // delay in between reads for stability
readings[index] = analogRead(sensorPin);
total= total + readings[index]; // add the reading to the total:
index = index + 1; // advance to the next position in the array:
if (index >= numReadings) index = 0; // if we're at the end of the array...wrap around to the beginning:
average = total / numReadings; // calculate the average:
if (currentMillis - previousMillis >= interval)
{
// save the last time you blinked the LED
previousMillis = currentMillis;
// convert the ADC reading to voltage
float voltage = (average / 1024.0) * 5.0;
float temperature = (voltage - .5) * 100;
// node-id;child-sensor-id;message-type;ack;sub-type;payload\n
Serial.print("12;3;1;0;0;");
Serial.println(temperature);
if (digitalRead(LED_LIGHT) == HIGH)
{
Serial.println("12;4;1;0;2;1");
}
else
{
Serial.println("12;4;1;0;2;0");
}
if (digitalRead(4) == HIGH)
{
Serial.println("12;5;1;0;2;1");
}
else
{
Serial.println("12;5;1;0;2;0");
}
if (digitalRead(5) == HIGH)
{
Serial.println("12;6;1;0;2;1");
}
else
{
Serial.println("12;6;1;0;2;0");
}
if (digitalRead(6) == HIGH)
{
Serial.println("12;7;1;0;2;1");
}
else
{
Serial.println("12;7;1;0;2;0");
}
if (digitalRead(7) == HIGH)
{
Serial.println("12;8;1;0;2;1");
}
else
{
Serial.println("12;8;1;0;2;0");
}
}
if (currentMillis - previousPublish >= intervalPublish)
{
previousPublish = currentMillis;
Serial.println("12;1;0;0;17;Arduino UNO\n");
Serial.println("12;3;0;0;6;TMP36\n");
Serial.println("12;4;0;0;3;LED Light\n");
Serial.println("12;5;0;0;3;Relai 1\n");
Serial.println("12;6;0;0;3;Relai 2\n");
Serial.println("12;7;0;0;3;Relai 3\n");
Serial.println("12;8;0;0;3;Relai 4\n");
}
if (Serial.available()) // is there anything to be read from USB?
{
ch = Serial.readStringUntil('\n'); // read a single command string
// node-id;child-sensor-id;message-type;ack;sub-type;payload\n
// Check message: "12;4;1;0;2;1"
if(ch.startsWith("12;4;1;0;2;1") || ch.startsWith("12;4;1;1;2;1"))
{
digitalWrite(LED_LIGHT,HIGH);
Serial.println("12;4;1;0;2;1");
}
else if(ch.startsWith("12;4;1;0;2;0") || ch.startsWith("12;4;1;1;2;0"))
{
digitalWrite(LED_LIGHT,LOW);
Serial.println("12;4;1;0;2;0");
}
// node-id;child-sensor-id;message-type;ack;sub-type;payload\n
// Check message: "12;5;1;0;2;1"
else if(ch.startsWith("12;5;1;0;2;1") || ch.startsWith("12;5;1;1;2;1"))
{
digitalWrite(4,HIGH);
Serial.println("12;5;1;0;2;1");
}
else if(ch.startsWith("12;5;1;0;2;0") || ch.startsWith("12;5;1;1;2;0"))
{
digitalWrite(4,LOW);
Serial.println("12;5;1;0;2;0");
}
// node-id;child-sensor-id;message-type;ack;sub-type;payload\n
// Check message: "12;6;1;0;2;1"
else if(ch.startsWith("12;6;1;0;2;1") || ch.startsWith("12;6;1;1;2;1"))
{
digitalWrite(5,HIGH);
Serial.println("12;6;1;0;2;1");
}
else if(ch.startsWith("12;6;1;0;2;0") || ch.startsWith("12;6;1;1;2;0"))
{
digitalWrite(5,LOW);
Serial.println("12;6;1;0;2;0");
}
// node-id;child-sensor-id;message-type;ack;sub-type;payload\n
// Check message: "12;7;1;0;2;1"
else if(ch.startsWith("12;7;1;0;2;1") || ch.startsWith("12;7;1;1;2;1"))
{
digitalWrite(6,HIGH);
Serial.println("12;7;1;0;2;1");
}
else if(ch.startsWith("12;7;1;0;2;0") || ch.startsWith("12;7;1;1;2;0"))
{
digitalWrite(6,LOW);
Serial.println("12;7;1;0;2;0");
}
// node-id;child-sensor-id;message-type;ack;sub-type;payload\n
// Check message: "12;8;1;0;2;1"
else if(ch.startsWith("12;8;1;0;2;1") || ch.startsWith("12;8;1;1;2;1"))
{
digitalWrite(7,HIGH);
Serial.println("12;8;1;0;2;1");
}
else if(ch.startsWith("12;8;1;0;2;0") || ch.startsWith("12;8;1;1;2;0"))
{
digitalWrite(7,LOW);
Serial.println("12;8;1;0;2;0");
}
}
delay(100);
}
Si une âme charitable pouvait m’aiguiller!
Merci