Voici le code complet, base sur la version 10e de votre code. Les quelques lignes ajoutee sont commentees.
Ca n'est pas un code voue a etre complet, mais principalement pour tenter de resoudre le conflit entre la reception Linky et l'Emission RF
/***********************************************************************
Récepteur TIC Linky
Mode historique
V03 : External SoftwareSerial. Tested OK on 07/03/18.
V04 : Replaced available() by new(). Tested Ok on 08/03/18.
V05 : Internal SoftwareSerial. Cf special construction syntax.
V06 : Separate compilation version.
V10a : Parametric version, initial. Tested OK on 23/10/19.
V10b : fixed bug in ptecIsNew(). Tested OK on 24/10/19.
V10c : added LKYSIMINPUT mode. Tested OK (partial) on 31/10/19.
V10d : adapted to Arduino Uno and Mega. Tested Ok on 27/04/20.
V10e : added optional ISOUSC. OK 26/11/22
***********************************************************************
Configuration parameters are defined in LinkyHistTIC.h
***********************************************************************/
/***************************** Includes *******************************/
#include <string.h>
#include <Streaming.h>
#include "LinkyHistTIC.h"
// include librarie for virtualwire //ajoute le 17/07/2023 pour emission 433MHz
#include <VirtualWire.h>
/****************************** Defines *******************************/
#define VERSION "V10e"
// structure definition //ajoute le 17/07/2023 pour emission 433MHz
typedef struct {
char commande;
int valeur;
} MaStructure;
MaStructure tempds18b20;
/****************************** Constants *****************************/
/************************* Global variables ***************************/
/************************* Object instanciation ***********************/
LinkyHistTIC Linky(LKYRX_INPUT, LKYTXPIN);
/**************************** Routines ******************************/
/****************************** Setup *******************************/
void setup()
{
/* Initialise serial link */
#ifndef LKYSIMINPUT
Serial.begin(9600);
#endif
/* Initialise the Linky receiver */
Linky.Init();
Serial << F("Bonjour - ") << VERSION << endl;
// ajoute le 17/07/2023 pour emission 433MHz
vw_set_tx_pin(3); //init=12, changed to 3 to give a try // pins 13,12,8,7 are working
vw_set_rx_pin(5); //init=11, changed to 5 to give a try // pins 13,12,8,7 are working
vw_set_ptt_pin(6); //init=10, changed to 6 to give a try // pins 13,12,8,7 are working
vw_setup(2000);
}
/******************************* Loop *********************************/
void loop()
{
uint8_t i;
// vw_send((byte*) &tempds18b20, sizeof(tempds18b20)); // On envoie le message
// vw_wait_tx(); // On attend la fin de l'envoi
Linky.Update();
if (Linky.pappIsNew())
{
Serial << F("Puis. app. = ") << Linky.papp() << F(" VA") << endl;
}
#ifdef LKY_Base
if (Linky.baseIsNew())
{
Serial << F("Index base = ") << Linky.base() << F(" Wh") << endl;
}
#endif
#ifdef LKY_HPHC
if (Linky.hchpIsNew())
{
Serial << F("Index HP = ") << Linky.hchp() << F(" Wh") << endl;
}
if (Linky.hchcIsNew())
{
Serial << F("Index HC = ") << Linky.hchc() << F(" Wh") << endl;
}
if (Linky.ptecIsNew())
{
Serial << F("Tarif en cours : ");
if (Linky.ptec() == Linky.C_HPleines)
{
Serial << F("heures pleines") << endl;
}
else
{
Serial << F("heures creuses") << endl;
}
}
#endif
#ifdef LKY_IMono
if (Linky.iinstIsNew())
{
Serial << F("I instant. = ") << Linky.iinst() << F(" A") << endl;
}
#endif
#ifdef LKY_ITri
for (i = Linky.C_Phase_1; i <= Linky.C_Phase_3; i++)
{
if (Linky.iinstIsNew(i))
{
Serial << F("I Phase ") << i+1 << F(" = ") \
<< Linky.iinst(i) << F(" A") << endl;
}
}
#endif
#ifdef LKY_ISOUSC
if (Linky.isouscIsNew())
{
Serial << F("Intensité souscrite = ") << Linky.isousc() << F(" A (par phase)") << endl;
}
#endif
};
Etant limite en nombre de reponse, je complete celle-ci:
Merci @MicroQuettas pour le retour rapide!
Je ne m'attendais pas a un tel support!
Sur l'aspect linky: je suis en:
- tarification HSC(Heures Super Creuses) HC HP (Anciennement Direct Energie)
- mono-phase
Effectivement, je n'utilise generalement le moniteur serie que pour debugger, ca n'est pas pour moi une fin en soi d'avoir un ordi connecte en permanence sur une des arduino
La bibliotheque VirtualWire que j'utilise est effectivement peut etre un peu datee. Je la mets en PJ.
J'utilise l'emission et la reception avec VitualWire notemment sur un capteur exterieur (temperature, humidite, pression atmospherique) qui envoit vers une seconde arduino disposant d'un ecran. Sur cette installation, aucun soucis avec la bibliotheque. Voici les codes correspondants. Desole si je respecte pas l'etat d'art, sur la facon de commenter:
Voici le code emetteur (un capteur DHT22, un capteur BMP180 + un bete capteur de lumiere)
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
//////////////////////////////
////// //////
////// DEFINITION //////
////// //////
//////////////////////////////
// include libraries
#include <VirtualWire.h>
#include "DHT.h"
#include <Wire.h>
#include <SFE_BMP180.h>
// DHT definition
#define DHTPIN 2 // defines the pin on which DHT22 is connected
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor for normal 16mhz Arduino
// light sensor definition
int val = 0;
int CDSpin = 1; // this pin is used for light measurement
int tempfinal = 0;
int humfinal = 0;
int tressfinal = 0;
int pressurefinal = 0;
int delaybet = 300; // delay between sending each data
int delayend = 10000; // delay when all data was sent
// structure definition
typedef struct {
char commande;
int valeur;
} MaStructure;
MaStructure temp;
MaStructure humi;
MaStructure lumi;
MaStructure tress;
MaStructure pressure;
// BMP180 definition (pressure sensor)
SFE_BMP180 bmp180;
int Altitude = 30; //current altitude in meters
/////////////////////////
////// //////
////// SETUP //////
////// //////
/////////////////////////
void setup() {
Serial.begin(9600);
// Initialisation de la bibliothèque VirtualWire
vw_setup(2000);
vw_set_tx_pin(13); // pins 13,12,8,7 are working
Serial.println("Go !");
dht.begin();
delay(300); // small delay is required, otherwise data is not available (ini=300)
// Initialization for BMP180
bool success = bmp180.begin();
if (success) {
Serial.println("BMP180 init success");
delay(2000); // just to ensure everything has started properly..., before measuring and sending first data
}
}
////////////////////////
////// //////
////// LOOP //////
////// //////
////////////////////////
void loop() {
// delay(2000); // just to ensure everything has started properly..., before measuring and sending first data
/////////////////////////////////
////// //////
////// MEASUREMENTS //////
////// //////
////////////////////////////////
// First, each of the parameters is measured and/or calculated
float h = dht.readHumidity();
float inttemp = dht.readTemperature(); // Read temperature as Celsius
float f = dht.readTemperature(true); // Read temperature as Fahrenheit
float hi = dht.computeHeatIndex(f, h); // Calcul la température ressentie
hi = dht.convertFtoC(hi); //Convertion de la temperature ressentie en degre Celsius
/*
Serial.println(inttemp);
Serial.println(h);
Serial.println(f);
Serial.println(hi); // Affiche la température ressentie
*/
tempfinal = (int) inttemp;
humfinal = (int) h;
tressfinal = (int) hi;
val = analogRead(CDSpin); // reads voltage on analog pin 1
val = map(val, 15, 1007, 0, 99); //Scale down the value from 1023-max to 101-max
// below is aquisition from BMP180 sensor:
char status;
double T, P;
bool success = false;
status = bmp180.startTemperature();
if (status != 0) {
delay(20);
status = bmp180.getTemperature(T);
if (status != 0) {
status = bmp180.startPressure(3);
if (status != 0) {
delay(status);
status = bmp180.getPressure(P, T);
if (status != 0) {
float comp = bmp180.sealevel(P, Altitude);
pressurefinal = comp +0.5;
}
}
}
}
/////////////////////////////////
////// //////
////// TRANSMISSION //////
////// //////
////////////////////////////////
// Second, each of the parameters is transmitted via virtualwire
delay(300); // just to ensure everything from previous section has ended properly...
temp.commande = 'T';
temp.valeur = tempfinal;
Serial.print(temp.commande);
Serial.print("=");
Serial.print(temp.valeur);
Serial.println("*C");
vw_send((byte*) &temp, sizeof(temp)); // On envoie le message
vw_wait_tx(); // On attend la fin de l'envoi
delay(delaybet);
humi.commande = 'H';
humi.valeur = humfinal;
Serial.print(humi.commande);
Serial.print("=");
Serial.print(humi.valeur);
Serial.println("%");
vw_send((byte*) &humi, sizeof(humi)); // On envoie le message
vw_wait_tx(); // On attend la fin de l'envoi
delay(delaybet);
tress.commande = 'R';
tress.valeur = tressfinal;
Serial.print(tress.commande);
Serial.print("=");
Serial.print(tress.valeur);
Serial.println("*C");
vw_send((byte*) &tress, sizeof(tress)); // On envoie le message
vw_wait_tx(); // On attend la fin de l'envoi
delay(delaybet);
lumi.commande = 'L';
lumi.valeur = val;
Serial.print(lumi.commande);
Serial.print("=");
Serial.print(lumi.valeur);
Serial.println("%");
vw_send((byte*) &lumi, sizeof(lumi)); // On envoie le message
vw_wait_tx(); // On attend la fin de l'envoi
delay(delaybet);
pressure.commande = 'P';
pressure.valeur = pressurefinal;
Serial.print(pressure.commande);
Serial.print("=");
Serial.print(pressure.valeur);
Serial.println("hPa");
vw_send((byte*) &pressure, sizeof(pressure)); // On envoie le message
vw_wait_tx(); // On attend la fin de l'envoi
delay(delayend);
}
et le code reception:
// receiver using using virtual wire to receive data from the emitter + sending part of the information to the LCD display
//////////////////////////////
////// //////
////// DEFINITION //////
////// //////
//////////////////////////////
// libraries include
#include <VirtualWire.h> // include the virtualwire library
#include <LiquidCrystal.h> // include the LCD library
// LCD definition
LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins
const int inputPin = A0; // buttons array analog input
uint16_t inputValue = 0; // value read from buttons array
// variables definition
int temperature = 0;
int humidity = 0;
int light = 0;
int tress = 0;
int pressure = 0;
// structure definition
typedef struct {
char commande;
int valeur;
} MaStructure;
// led definition
int led = 13;
/////////////////////////
////// //////
////// SETUP //////
////// //////
/////////////////////////
void setup() {
Serial.begin(9600);
// Initialisation de la bibliothèque VirtualWire
// Vous pouvez changez les broches RX/TX/PTT avant vw_setup() si nécessaire
vw_setup(2000);
vw_set_rx_pin(11);
vw_rx_start(); // On peut maintenant recevoir des messages
Serial.println("Go !");
//LCD
lcd.begin(16, 2); // set up the LCD's number of columns and rows
lcd.print("initialisation"); // Print a message on the LCD
lcd.setCursor(0, 1); // set the cursor to column 0, line 1
lcd.print("en cours");
delay(2000);
lcd.begin(16, 2); // set up the LCD's number of columns and rows
// noTone(8);
tone(8, 100, 100);
delay(150);
tone(8, 100, 100);
// Led initialization
pinMode(led, OUTPUT); // it can also be defined using "BUILTIN": pinMode(LED_BUILTIN, OUTPUT)
// in that case, the correct pin is chosen automatically so that the integrated led is used
// draw-back is that you pin number is not fully clear...
}
////////////////////////
////// //////
////// LOOP //////
////// //////
////////////////////////
void loop() {
MaStructure message;
byte taille_message = sizeof(MaStructure);
vw_wait_rx();
if (vw_get_message((byte *) &message, &taille_message)) {
// On copie le message, qu'il soit corrompu ou non
Serial.print("commande="); // Affiche le message
Serial.print(message.commande);
Serial.print(" valeur=");
Serial.println(message.valeur);
}
if (message.commande == 'T') {
temperature = message.valeur;
// temperature = -12; //for test only
}
if (message.commande == 'H') {
humidity = message.valeur;
}
if (message.commande == 'L') {
light = message.valeur;
}
if (message.commande == 'R') {
tress = message.valeur;
}
if (message.commande == 'P') {
pressure = message.valeur;
}
tone(8, 35, 100); //audible feedback on pin8 [ tone(8, 35, 100); ]
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(10); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
// delay(10); // wait for a second
//print int temperature on LCD
if (temperature > 9) {
lcd.setCursor(0, 0);
lcd.print("deg=");
lcd.setCursor(4, 0);
lcd.print(temperature);
lcd.setCursor(6, 0);
lcd.print(" ");
}
else if (temperature <0) {
lcd.setCursor(0, 0);
lcd.print("deg=");
lcd.setCursor(4, 0);
lcd.print(temperature);
}
else {
lcd.setCursor(0, 0);
lcd.print("deg=");
lcd.setCursor(4, 0);
lcd.print("0");
lcd.setCursor(5, 0);
lcd.print(temperature);
lcd.setCursor(6, 0);
lcd.print(" ");
}
//print int humidity on LCD
if (humidity > 9) {
lcd.setCursor(8, 0);
lcd.print("hum=");
lcd.setCursor(12, 0);
lcd.print(humidity);
}
else {
lcd.setCursor(8, 0);
lcd.print("hum=");
lcd.setCursor(12, 0);
lcd.print("0");
lcd.setCursor(13, 0);
lcd.print(humidity);
}
//print int light on LCD
if (light > 9){
lcd.setCursor(0, 1);
lcd.print("lum=");
lcd.setCursor(4, 1);
lcd.print(light);
}
else {
lcd.setCursor(0, 1);
lcd.print("lum=");
lcd.setCursor(4, 1);
lcd.print("0");
lcd.setCursor(5, 1);
lcd.print(light);
}
/*
//print heat index on LCD
if (tress > 9) {
lcd.setCursor(8, 1);
lcd.print("tre=");
lcd.setCursor(12, 1);
lcd.print(tress);
lcd.setCursor(14, 1);
lcd.print(" ");
}
else if (tress <0) {
lcd.setCursor(8, 1);
lcd.print("tre=");
lcd.setCursor(11, 1);
lcd.print(tress);
}
else {
lcd.setCursor(8, 1);
lcd.print("tre=");
lcd.setCursor(12, 1);
lcd.print("0");
lcd.setCursor(13, 1);
lcd.print(tress);
lcd.setCursor(14, 1);
lcd.print(" ");
}
*/
//print pressure on LCD
if (pressure > 999) {
lcd.setCursor(8, 1);
lcd.print("pre=");
lcd.setCursor(12, 1);
lcd.print(pressure);
}
else {
lcd.setCursor(8, 1);
lcd.print("pre=");
lcd.setCursor(12, 1);
lcd.print(pressure);
lcd.setCursor(15, 1);
lcd.print(" ");
}
//cleaning of zero digits
// first row
lcd.setCursor(6, 0);
lcd.print(" ");
lcd.setCursor(7, 0);
lcd.print(" ");
lcd.setCursor(14, 0);
lcd.print(" ");
lcd.setCursor(15, 0);
lcd.print(" ");
// second row
lcd.setCursor(6, 1);
lcd.print(" ");
lcd.setCursor(7, 1);
lcd.print(" ");
}