Merge branch 'master' of ssh://www.lexach.dns-cloud.net:56656/home/git/AHome into master
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#define MY_DEBUG
|
||||
#define MY_RADIO_RF24
|
||||
#define MY_RF24_CHANNEL (105)
|
||||
#define MY_RF24_PA_LEVEL RF24_PA_HIGH
|
||||
#include <MySensors.h>
|
||||
#include <AHT10.h>
|
||||
@@ -17,6 +18,10 @@ MyMessage msgTemp(0, V_TEMP);
|
||||
MyMessage msgHum(1, V_HUM);
|
||||
MyMessage msgMillis(2, V_VAR1);
|
||||
MyMessage msgVolts(2, V_VAR2);
|
||||
void sendData(MyMessage msg, int status);
|
||||
void sendData(MyMessage msg, float status, uint8_t decm);
|
||||
void sendData(MyMessage msg, bool status);
|
||||
void sendData(MyMessage msg, uint32_t status);
|
||||
|
||||
AHT10 myAHT10(AHT10_ADDRESS_0X38);
|
||||
|
||||
@@ -24,40 +29,44 @@ void setup() {
|
||||
analogReference(INTERNAL);
|
||||
sensorValue = analogRead(BATTERY_SENSE_PIN);
|
||||
v = sensorValue * 0.004659498;
|
||||
batteryPcnt = (v * 100) / 4.2;
|
||||
batteryPcnt = (v-3.0 * 100) / 1.2;
|
||||
while (myAHT10.begin() != true)
|
||||
{
|
||||
Serial.println(F("AHT10 not connected or fail to load calibration coefficient")); //(F()) save string to flash & keeps dynamic memory free
|
||||
delay(5000);
|
||||
}
|
||||
Serial.println(F("AHT10 OK"));
|
||||
Serial.print(F("Temperature: ")); Serial.print(myAHT10.readTemperature(AHT10_FORCE_READ_DATA)); Serial.println(F(" +-0.3C"));
|
||||
Serial.print(F("Humidity...: ")); Serial.print(myAHT10.readHumidity(AHT10_USE_READ_DATA)); Serial.println(F(" +-2%"));
|
||||
Serial.print(F("T: ")); Serial.print(myAHT10.readTemperature(AHT10_FORCE_READ_DATA));// Serial.println(F(" +-0.3C"));
|
||||
Serial.print(F("H: ")); Serial.print(myAHT10.readHumidity(AHT10_USE_READ_DATA));// Serial.println(F(" +-2%"));
|
||||
|
||||
cRun = millis();
|
||||
send(msgMillis.set(cRun));
|
||||
cRun = 0;
|
||||
sendData(msgMillis, cRun);
|
||||
//send(msgMillis.set(cRun));
|
||||
}
|
||||
|
||||
void loop() {
|
||||
float temp, hum;
|
||||
//if((cRun + 29999) < millis()){
|
||||
cRun = millis();
|
||||
temp = myAHT10.readTemperature(AHT10_FORCE_READ_DATA);
|
||||
hum = myAHT10.readHumidity(AHT10_USE_READ_DATA);
|
||||
Serial.print(F("Temperature: ")); Serial.print(temp); Serial.println(F(" +-0.3C"));
|
||||
Serial.print(F("Humidity...: ")); Serial.print(hum); Serial.println(F(" +-2%"));
|
||||
if (temp < 200){
|
||||
send(msgTemp.set(temp, 1));
|
||||
send(msgHum.set(hum, 1));
|
||||
}
|
||||
send(msgMillis.set(cRun));
|
||||
sensorValue = analogRead(BATTERY_SENSE_PIN);
|
||||
v = sensorValue * 0.004659498;
|
||||
batteryPcnt = (v * 100) / 4.2;
|
||||
sendBatteryLevel(batteryPcnt);
|
||||
send(msgVolts.set(v, 2));
|
||||
//}
|
||||
sleep(60000 - (millis() - cRun));
|
||||
unsigned long t = millis();
|
||||
temp = myAHT10.readTemperature(AHT10_FORCE_READ_DATA);
|
||||
hum = myAHT10.readHumidity(AHT10_USE_READ_DATA);
|
||||
Serial.print(F("T: ")); Serial.println(temp);// Serial.println(F(" +-0.3C"));
|
||||
Serial.print(F("H: ")); Serial.println(hum);// Serial.println(F(" +-2%"));
|
||||
if (temp < 200){
|
||||
sendData(msgTemp, temp, 1);
|
||||
sendData(msgHum, hum, 1);
|
||||
// send(msgTemp.set(temp, 1));
|
||||
// send(msgHum.set(hum, 1));
|
||||
}
|
||||
sensorValue = analogRead(BATTERY_SENSE_PIN);
|
||||
v = sensorValue * 0.004659498;
|
||||
//batteryPcnt = ((v-3.0) * 100) / 1.2;
|
||||
//sendBatteryLevel(batteryPcnt);
|
||||
sendData(msgVolts, v, 2);
|
||||
//send(msgVolts.set(v, 2));
|
||||
Serial.println(F("Tm run")); Serial.println(millis() - t);
|
||||
sendData(msgMillis, cRun++);
|
||||
//send(msgMillis.set(cRun++));
|
||||
sleep(60000 - (millis() - t));
|
||||
}
|
||||
|
||||
void presentation()
|
||||
@@ -67,3 +76,61 @@ void presentation()
|
||||
present(1, S_HUM, "Humid");
|
||||
present(2, S_CUSTOM, "ESMillis");
|
||||
}
|
||||
|
||||
void sendData(MyMessage msg, bool status)
|
||||
{
|
||||
bool send_data = false;
|
||||
uint8_t count = 0;
|
||||
while(send_data == false){
|
||||
count++;
|
||||
send_data = send(msg.set(status));
|
||||
wait(100, C_SET, V_STATUS);
|
||||
if ((count == 3 )&&(send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки
|
||||
count = 0; // Обнуляем счётчик
|
||||
send_data = 1; // Выходим из цикла
|
||||
}
|
||||
}
|
||||
}
|
||||
void sendData(MyMessage msg, float status, uint8_t decm)
|
||||
{
|
||||
bool send_data = false;
|
||||
uint8_t count = 0;
|
||||
while(send_data == false){
|
||||
count++;
|
||||
send_data = send(msg.set(status, decm));
|
||||
wait(100, C_SET, V_STATUS);
|
||||
if ((count == 3 )&&(send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки
|
||||
count = 0; // Обнуляем счётчик
|
||||
send_data = 1; // Выходим из цикла
|
||||
}
|
||||
}
|
||||
}
|
||||
void sendData(MyMessage msg, int status)
|
||||
{
|
||||
bool send_data = false;
|
||||
uint8_t count = 0;
|
||||
while(send_data == false){
|
||||
count++;
|
||||
send_data = send(msg.set(status));
|
||||
wait(100, C_SET, V_STATUS);
|
||||
if ((count == 3 )&&(send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки
|
||||
count = 0; // Обнуляем счётчик
|
||||
send_data = 1; // Выходим из цикла
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sendData(MyMessage msg, uint32_t status)
|
||||
{
|
||||
bool send_data = false;
|
||||
uint8_t count = 0;
|
||||
while(send_data == false){
|
||||
count++;
|
||||
send_data = send(msg.set(status));
|
||||
wait(100, C_SET, V_STATUS);
|
||||
if ((count == 3 )&&(send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки
|
||||
count = 0; // Обнуляем счётчик
|
||||
send_data = 1; // Выходим из цикла
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user