first commit

This commit is contained in:
Jérôme Delacotte
2025-03-06 11:15:32 +01:00
commit 7b30d6e298
5276 changed files with 2108927 additions and 0 deletions

View File

@@ -0,0 +1,195 @@
#include <RCSwitch.h>
#include <Narcoleptic.h>
#include <Adafruit_BMP085.h>
#include <Wire.h>
#include "DHT.h"
#define DHTPIN A2 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 11
// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);
#define SEND_MESSAGE_DELAY 30000 // Ne pas dépasser 32000 !! Delay in ms between each value's extraction
#define SEND_433_PAUSE 160 // 16 multiple
#define DEBUG true
const unsigned long activation = 111269;
const unsigned long idTemp=1969;
const unsigned long idPressure=2069;
const unsigned long idPression=2169;
const unsigned long idLum=2269;
const unsigned long desactivation = 962111;
const unsigned int delai = 11;
const unsigned long TIME = 512;
const unsigned long TWOTIME = TIME*2;
// ################# Barometre ####
Adafruit_BMP085 bmp;
// #####################
float temperature = 0.0;
float pressure = 0.0;
float pression = 0.0;
float presiune = 0.0;
RCSwitch mySwitch = RCSwitch();
void setup() {
#ifdef DEBUG
Serial.begin(9600);
Serial.println("\n[Oregon V2.1 encoder]");
#endif
mySwitch.enableTransmit(9);
//mySwitch.setRepeatTransmit(2);
// DHT
dht.begin();
}
// Commande pour barometre humidité température
// Virtual Device
// http://192.168.0.10:8080/json.htm?type=command&param=udevice&idx=160&nvalue=0&svalue=23.3;50;2;1024.20;1024&battery=89
void doDHT() {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();
// Read temperature as Fahrenheit
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
// Serial.println("Failed to read from DHT sensor!");
return;
} else {
// Compute heat index
// Must send in temp in Fahrenheit!
float hi = dht.computeHeatIndex(f, h);
#ifdef DEBUG
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hi);
Serial.println(" *F");
#endif
}
}
// Prise Eléctrique
//ON 1 1381719 1398103
//ON 2 1394007
//ON 3 1397079 1398103
//
//OFF 1 1381716
//OFF 2 1398103
//OFF 3 1397076
void loop() {
long vcc = readVcc();
barometre();
doDHT();
#ifdef DEBUG
Serial.print("Send");
Serial.println(vcc);
#endif
myMessageSend(idTemp,temperature * 100);
myMessageSend(idPressure,pressure * 10);
myMessageSend(idPression,pression * 10);
// LUX
// R=K*L^-gamma
// R étant la résistance pour un niveau d'éclairement L.
int lum = analogRead(1);
myMessageSend(idLum,(1000.0 * lum / 1024.0));
#ifdef DEBUG
Serial.print("Luminosite=");
Serial.println(lum);
#endif
Narcoleptic.delay(SEND_MESSAGE_DELAY);
Narcoleptic.delay(SEND_MESSAGE_DELAY);
}
void barometre() {
/* See Example: TypeA_WithDIPSwitches */
// mySwitch.switchOn("00001", "10000");
// delay(1000);
// BMP
if (bmp.begin()) {
temperature = bmp.readTemperature();
pressure= bmp.readPressure() / 100.0;
pression = pressure / 101.325;
pression = pression * 0.760 * 100;
// http://en.wikipedia.org/wiki/Atmospheric_pressure#Mean_sea_level_pressure
// Serial.print("Presiure la nivelul marii (calculata) = ");
presiune = bmp.readSealevelPressure(19) / 101.325;
presiune = presiune * 0.760;
#ifdef DEBUG
Serial.print("Temperature="); Serial.println(temperature);
Serial.print("pressure="); Serial.println(pressure);
Serial.print("pression="); Serial.println(pression);
#endif
}
}
void myMessageSend(long id, long value) {
#ifdef DEBUG
Serial.print("Send id="); Serial.print(id);
Serial.print(" value="); Serial.println(value);
#endif
mySwitch.send(activation, 24);
(delai); //delayMicroseconds
mySwitch.send(id, 24); //"000000000001010100010001");
delay(delai);
mySwitch.send(value, 24); //"000000000001010100010001");
delay(delai);
mySwitch.send(desactivation, 24);
delay(delai);
//delay(5000);
delayMicroseconds(TWOTIME*8);
}
//--------------------------------------------------------------------------------------------------
// Read current supply voltage
//--------------------------------------------------------------------------------------------------
long readVcc() {
bitClear(PRR, PRADC); ADCSRA |= bit(ADEN); // Enable the ADC
long result;
// Read 1.1V reference against Vcc
#if defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
ADMUX = _BV(MUX5) | _BV(MUX0); // For ATtiny84
#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
ADMUX = _BV(MUX3) | _BV(MUX2);
#else
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); // For ATmega328
#endif
// ADCSRB = 0;
delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Convert
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = 1126400L / result; // Back-calculate Vcc in mV
// ADCSRA &= ~ bit(ADEN); bitSet(PRR, PRADC); // Disable the ADC to save power
// analogReference(DEFAULT);
return result; // Vcc in millivolts
}