Działa, dzięki bardzo

Code: Select all
#define DHT_in_PIN 3 // 3-RX
#define DHT_out_PIN 13
//#define DHTTYPE DHT22
// Setup a DHT instance
DHT dht_in(DHT_in_PIN, DHTTYPE);
DHT dht_out(DHT_out_PIN, DHTTYPE);
// DHT22 Sensor read implementation
void get_temperature_and_humidity(int channelNumber, double *temp, double *humidity) {
switch(channelNumber) {
case 0: {
*temp = dht_in.readTemperature();
*humidity = dht_in.readHumidity();
Serial.print("DHT Temp wew : ");
Serial.print(*temp);
Serial.print(" Wilgotność wew : ");
Serial.println(*humidity);
if ( isnan(*temp) || isnan(*humidity) ) {
*temp = -275;
*humidity = -1;
}
break;
} //end case 1
case 1: {
*temp = dht_out.readTemperature();
*humidity = dht_out.readHumidity();
// *temp = bme.readTemperature();
// *humidity = bme.readHumidity();
Serial.print("DHT Temp zew : ");
Serial.print(*temp);
Serial.print(" Wilgotność zew : ");
Serial.println(*humidity);
Serial.println("*******************");
if ( isnan(*temp) || isnan(*humidity) ) {
*temp = -275;
*humidity = -1;
}
break;
} //end case 2
} //switch
} //void
void setup()
// CHANNEL0 -> case 0
SuplaDevice.addDHT22();
// CHANNEL1 -> case 1
SuplaDevice.addDHT22();
Code: Select all
// Init DHT library
dht_in.begin();
dht_out.begin();
// Set temperature/humidity callback
SuplaDevice.setTemperatureHumidityCallback(&get_temperature_and_humidity);
Mniej więcej coś takiego. Robiłem na szybko - nie sprawdzałem czy działasoren wrote: Sun Jul 15, 2018 7:17 pm Mam podpięte pod arduino dts18b20 do tego kilka przekaźników i kontaktrony wszystko ze skeczu z przykładów suplaenernetshielddallass...
działa elegancko zwiększyłem tylko liczbę przekaźników i krańcówek. Teraz do kodu chciałbym dodać obsługę kilku na poczatek nawet jednego dht22 .... jakby ktoś miał chwilkę byłbym wdzięczny.
Może ma ktoś cały skecz do arduino obsługujący kilka ds18b20 kilka dth22 kilka kontaktronów i przekaznikow?
Code: Select all
#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <DHT.h>
#include <SuplaDevice.h>
/*
* This example requires DHT sensor library installed.
* https://github.com/adafruit/DHT-sensor-library
*/
#define DHTPIN 24
#define DHTTYPE DHT22
// Setup a DHT instance
DHT dht(DHTPIN, DHTTYPE);
OneWire oneWire(24);
DallasTemperature sensors(&oneWire);
DeviceAddress DS18B20_1 = { 0x28, 0xFF, 0x2E, 0xFB, 0xC1, 0x17, 0x1, 0xD3 }; // odczytany adres 28FF2EFBC11701D3
DeviceAddress DS18B20_2 = { 0x28, 0xFF, 0xEC, 0xFE, 0xC1, 0x17, 0x1, 0xF3 }; //Odczytany adres 28FFECFEC11701F3
// DS18B20 Sensor read implementation
double get_temperature(int channelNumber, double last_val) {
double t = -275;
if ( sensors.getDeviceCount() > 0 )
{
sensors.requestTemperatures();
switch(channelNumber)
{
case 0:
t = sensors.getTempC(DS18B20_1);
break;
case 1:
t = sensors.getTempC(DS18B20_2);
break;
};
};
return t;
}
void get_temperature_and_humidity(int channelNumber, double *temp, double *humidity) {
*temp = dht.readTemperature();
*humidity = dht.readHumidity();
if ( isnan(*temp) || isnan(*humidity) ) {
*temp = -275;
*humidity = -1;
}
}
void setup() {
Serial.begin(9600);
// Init DS18B20 library
sensors.begin();
// Init DHT library
dht.begin();
// Set temperature/humidity callback
SuplaDevice.setTemperatureHumidityCallback(&get_temperature_and_humidity);
// Set temperature callback
SuplaDevice.setTemperatureCallback(&get_temperature);
// Replace the falowing GUID
char GUID[SUPLA_GUID_SIZE] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
// with GUID that you can retrieve from https://www.supla.org/arduino/get-guid
// Ethernet MAC address
uint8_t mac[6] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
/*
* Having your device already registered at cloud.supla.org,
* you want to change CHANNEL sequence or remove any of them,
* then you must also remove the device itself from cloud.supla.org.
* Otherwise you will get "Channel conflict!" error.
*/
// CHANNEL0 - Thermometer DS18B20
SuplaDevice.addDS18B20Thermometer();
// CHANNEL1 - Thermometer DS18B20
SuplaDevice.addDS18B20Thermometer();
// CHANNEL2 - RELAY
SuplaDevice.addRelay(44, true);
// CHANNEL3 - RELAY
SuplaDevice.addRelay(45, true);
// CHANNEL4 - RELAY
SuplaDevice.addRelay(46, true);
// CHANNEL5 - RELAY
SuplaDevice.addRelay(47, true);
// CHANNEL6 - Opening sensor (Normal Open)
SuplaDevice.addSensorNO(A0);
// CHANNEL7 - Opening sensor (Normal Open)
SuplaDevice.addSensorNO(A1);
// CHANNEL8 - DHT22 Sensor
SuplaDevice.addDHT22();
// SuplaDevice.addDHT11();
// SuplaDevice.addAM2302();
/*
* SuplaDevice Initialization.
* Server address, LocationID and LocationPassword are available at https://cloud.supla.org
* If you do not have an account, you can create it at https://cloud.supla.org/account/create
* SUPLA and SUPLA CLOUD are free of charge
*
*/
SuplaDevice.begin(GUID, // Global Unique Identifier
mac, // Ethernet MAC address
"svr1.supla.org", // SUPLA server address
0, // Location ID
""); // Location Password
}
void loop() {
SuplaDevice.iterate();
}