bonjour,
1 croquis avec dsb18b20 relié onewire sur esp8266 wemos D1, envoi vers thingspeak ok
#include <ESP8266WiFi.h>
#include "ThingSpeak.h"
#include <OneWire.h>
#include <DallasTemperature.h>
// compilation ok 10/2021
// Data wire is plugged into port D2 on the ESP8266
#define ONE_WIRE_BUS D2
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
float tempSensor1, tempSensor2, tempSensor3;
uint8_t sensor1[8] = { 0x28, 0xAA, 0xF8, 0x63, 0x40, 0x14, 0x01, 0xB5 };
uint8_t sensor2[8] = { 0x28, 0xAA, 0x51, 0x56, 0x40, 0x14, 0x01, 0xBC };
uint8_t sensor3[8] = { 0x28, 0xAA, 0xCD, 0x79, 0x40, 0x14, 0x01, 0xC0 };
/*Put your SSID & Password*/
const char* ssid = "VOO-myssid"; // Enter SSID here
const char* password = "mypw"; //Enter Password here
WiFiClient client;
unsigned long myChannelNumber = myIDchannel;
const char * myWriteAPIKey = "mykey";
// Timer variables
unsigned long lastTime = 0;
unsigned long timerDelay = 300000; // envoi toutes les 5 minutes
String myStatus = "";
void setup() {
Serial.begin(115200); //Initialize serial
delay(100);
sensors.begin();
// resolution a 9 bits pour limiter la valeur a une décimale
sensors.setResolution(sensor1, 9);
sensors.setResolution(sensor2, 9);
sensors.setResolution(sensor3, 9);
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client); // Initialize ThingSpeak
}
void loop() {
if ((millis() - lastTime) > timerDelay) { // tout est dans ce if ?
// Connect or reconnect to WiFi
if(WiFi.status() != WL_CONNECTED){
Serial.print("Attempting to connect");
while(WiFi.status() != WL_CONNECTED){
WiFi.begin(ssid, password);
delay(5000);
}
Serial.println("\nConnected.");
}
sensors.requestTemperatures();
// je retire 1 degre a la temp du 1820 que je trouve trop optimiste
// meme si ma sonde auriol indique la meme chose
tempSensor1 = (sensors.getTempC(sensor1)-1); // Gets the values of the temperature
tempSensor2 = (sensors.getTempC(sensor2)-1); // Gets the values of the temperature
tempSensor3 = (sensors.getTempC(sensor3)-1); // Gets the values of the temperature
// set the fields with the values
ThingSpeak.setField(1, tempSensor1);
ThingSpeak.setField(2, tempSensor2);
ThingSpeak.setField(3, tempSensor3);
Serial.println(tempSensor1);
Serial.println(tempSensor2);
// Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different
// pieces of information in a channel. Here, we write to field 1.
int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
if(x == 200){
Serial.println("Channel update successful.");
}
else{
Serial.println("Problem updating channel. HTTP error code " + String(x));
}
lastTime = millis();
} // fin du if "millis"
} // end loop
le 2eme croquis : recup trame oregon thn132 vers moniteur serie ok
// biblio https://github.com/invandy/Oregon_NR
#include <Oregon_NR.h> // attachInterrupt(digitalPinToInterrupt(GPIO), ISR, mode);
#if defined ( ESP8266 ) || ( ESP32 ) // Wemos accepte interrupt sur toutes les broches sauf d0 (gpio16)
Oregon_NR oregon(13, 13, 2, true, 50, true); // recepteur data sur D7 (GPIO13)
// LED sur d4=gpio2 ledbuiltin tirée vers le +(true). si pas de led, numero de pin - 255
// buffer de 50 bits, creation de package pour la v2
#else // pour uno
Oregon_NR oregon(2, 0, // RX sur D2, interruption 0,
13, false); // led integrée sur d13
// buffer reception standard - pour 24 bits inclus protocole v2
//Oregon_NR oregon(2, 0); // constructeur par defaut, buffer standard sans led
#endif
void setup() {
Serial.begin(115200);
Serial.println();
if (oregon.no_memory)
{
Serial.println("NO MEMORY"); //memoire insuffisante
do yield();
while(true);
}
//attend reception
oregon.start();
oregon.receiver_dump = 0; //true - - affiche, data recepteur
}
void loop() {
//capture paquet data
oregon.capture(false); // 1 - envoi sur serial monitor
//traitement paquet
if (oregon.captured && oregon.sens_type) {
Serial.print (" ");
//version protocole recu
if (oregon.ver == 2) Serial.print(" v2 ");
if (oregon.ver == 3) Serial.print("3 ");
if (oregon.ver == 11) Serial.print("E ");
if (oregon.ver == 12) Serial.print("E2");
if ((oregon.sens_type == THGN132 || oregon.sens_type == THN132) && oregon.crc_c){
Serial.print("\t");
if (oregon.sens_type == THGN132) Serial.print("THGN132N");
if (oregon.sens_type == THN132 ) Serial.print("THN132N ");
Serial.print(oregon.sens_tmp, 1);
Serial.print("C ");
}
Serial.println();
}
yield();
}
la fonction yield() sert à quoi ?
dans le premier croquis l'esp8266 interroge le bus et retourne la temperature qui est envoyée sur thingspeak
dans le 2eme l'esp8266 ATTEND de recevoir une trame valide et l'envoye apres decodage sur le port série, variable oregon.sens_tmp,
quand je combine les 2 , je n'ai plus l'affichage du thn132 sur le moniteur et j'ai toujours la temp des dsb18b20, c'est une question de timing ?
Merci d'avance pour toute info