[PORADNIK] Arduino IDE

cino111
Posty: 714
Rejestracja: pn maja 07, 2018 8:00 pm

Wstaw swój program. Na jakiej płytce chcesz uruchomić termometry?
Awatar użytkownika
Piotr61
Posty: 61
Rejestracja: pt wrz 15, 2017 12:59 pm

jarsek pisze: pn wrz 24, 2018 8:30 am Wgrałem program do nodemcu na pięć termometrów ds...niestety nie chodzi...na 4 też nie chodzi ....ledwo ciągnie na 3.Nie wiem co jest powodem.
Ja ten temat już przerabiałem ( viewtopic.php?f=6&t=2350 ) i NIE ZADZIAŁA.
Trzeba zmienić koncepcję i sposób przekazywania danych o temperaturach do chmury. :mrgreen:
"Dopóki nie skorzystałem z Internetu, nie wiedziałem, że na świecie jest tylu idiotów" - Stanisław Lem
jarsek
Posty: 13
Rejestracja: śr lut 21, 2018 6:39 am

Kolega Piotr61 chyba ma racje.Chyba trzeba dać sobie spokój z kilkoma DS-ami bo są z tym ciągłe problemy.
Awatar użytkownika
Duch__
Posty: 1779
Rejestracja: śr sie 24, 2016 7:26 pm
Lokalizacja: Opole

32 kanały DS18b20 na jednym ESP8266 to żaden problem.
Obrazek
jarsek
Posty: 13
Rejestracja: śr lut 21, 2018 6:39 am

No to wstaw działający kod na ESP8266 programowany przez Arduino na 6-8 Ds-ów....bo ja do tej pory nie spotkałem.
Awatar użytkownika
dawidd
Posty: 615
Rejestracja: wt gru 19, 2017 12:45 pm

Witam
Zwracam sie z prośba do osób które ogarniają pisanie kodów w arduino. Do kodu pod ESP8266 ktory jest poniżej, potrzebuje dołożyć 2 termometry DS1820
Kod jest zaczerpnięty z lekkimi zmianami z wątku dot czujnika pyłu:
viewtopic.php?f=11&t=2989
W założeniu ma być:
4 przekaźniki, 2 czujniki, 1 wejście analogowe A0 do pomiaru napięcia akumulatora 12V (emulowany pomiar temperatury DS'em) - i to już działa.
Do tego potrzebuje pomiar temperatury w 2 punktach przez DS1820 (niekoniecznie na jednym GPIO)
Czy ktoś mógłby zmodyfikować kod żeby jeszcze te 2 ds'y się pojawiły?

Kod: Zaznacz cały

#include <ESP8266WiFi.h>
#define SUPLADEVICE_CPP
#include <SuplaDevice.h>

WiFiClient client;

const char* ssid     = "xxx";
const char* password = "xxx";


int measurePin = A0;

float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;



// DS18B20 Sensor read implementation
double get_temperature(int channelNumber, double last_val) {


    voMeasured = analogRead(measurePin); // read the dust value
 
   calcVoltage = (5000.0 / 1024.0) * voMeasured; // Przeliczamy na mV.
  
  
if (voMeasured>3.0)
dustDensity = 0.010165 * calcVoltage - 0.1; // V
    Serial.print("Raw Signal Value (0-1023): ");
    Serial.print(voMeasured);
  
    Serial.print(" - Voltage: ");
    Serial.print(calcVoltage);
  
    Serial.print(" - Dust Density [V]: ");
    Serial.println(dustDensity);    
    
    
    
    
    
    
    
    double t = dustDensity;
    last_val = t;
    

    
    return t;  
}

void setup() {
pinMode(5, OUTPUT);
  Serial.begin(115200);
  WiFi.softAPdisconnect(true); // wyłączenie rozgłaszania sieci ESP
  //sensors.begin();
   
  // Set temperature callback
  
 
 char GUID[SUPLA_GUID_SIZE] = {0x69,0x74,0x43,0x20,0xAC,0xF0,0x0D,0x9D,0x42,0x35,0xDD,0xA2,0x74,0x1C,0x3E,0x04};  // with GUID that you can retrieve from https://www.supla.org/arduino/get-guid
  uint8_t mac[6] = {0x00, 0x02, 0x01, 0x03, 0x04, 0x05};

  SuplaDevice.addRelay(12, true);                 
  SuplaDevice.addRelay(13, true);              
  SuplaDevice.addRelay(14, true);
  SuplaDevice.addRelay(15, true);
  SuplaDevice.addDS18B20Thermometer();

  
  // CHANNEL7,8 - Opening sensor (Normal Open)
  SuplaDevice.addSensorNO(4);   // A0 - Pin number where the sensor is connected
  SuplaDevice.addSensorNO(16);  // Call SuplaDevice.addSensorNO(A0, true) with an extra "true" parameter
                                // to enable the internal pull-up resistor


  SuplaDevice.begin(GUID,              // Global Unique Identifier 
                    mac,               // Ethernet MAC address
                    "svr8.supla.org",  // SUPLA server address
                    xxxx,                 // Location ID 
                    "xxxx");               // Location Password
    
}

void loop() {
  
  if (WiFi.status() != WL_CONNECTED) // Jeżeli sieć WiFi nie jest podłączona, wywołaj procedurę łączenia
  {
    WiFi_up();
  }
  
  SuplaDevice.iterate();
  SuplaDevice.setTemperatureCallback(&get_temperature);
}


// Supla.org ethernet layer
    int supla_arduino_tcp_read(void *buf, int count) {
        _supla_int_t size = client.available();
       
        if ( size > 0 ) {
            if ( size > count ) size = count;
            return client.read((uint8_t *)buf, size);
        };
    
        return -1;
    };
    
    int supla_arduino_tcp_write(void *buf, int count) {
        return client.write((const uint8_t *)buf, count);
    };
    
    bool supla_arduino_svr_connect(const char *server, int port) {
          return client.connect(server, 2015);
    }
    
    bool supla_arduino_svr_connected(void) {
          return client.connected();
    }
    
    void supla_arduino_svr_disconnect(void) {
         client.stop();
    }
    
    void supla_arduino_eth_setup(uint8_t mac[6], IPAddress *ip) {

       WiFi_up();
    }

SuplaDeviceCallbacks supla_arduino_get_callbacks(void) {
          SuplaDeviceCallbacks cb;
          
          cb.tcp_read = &supla_arduino_tcp_read;
          cb.tcp_write = &supla_arduino_tcp_write;
          cb.eth_setup = &supla_arduino_eth_setup;
          cb.svr_connected = &supla_arduino_svr_connected;
          cb.svr_connect = &supla_arduino_svr_connect;
          cb.svr_disconnect = &supla_arduino_svr_disconnect;
          cb.get_temperature = &get_temperature;
           cb.get_temperature_and_humidity = NULL;
          cb.get_rgbw_value = NULL;
          cb.set_rgbw_value = NULL;
          
          return cb;
}

void WiFi_up() // Procedura podłączenia do sieci WiFi
{
  Serial.print("Proba podlaczenia do sieci ");
  Serial.println(ssid);

  WiFi.begin(ssid, password); // Próba podłączenia do sieci


  for (int x = 60; x > 0; x--) // Powtarzaj pętlę maksymanie maksymalnie 30 sekund (ponieważ przy każdym elsie jest 0,5 sekundy zwłoki)
  {
    if (WiFi.status() == WL_CONNECTED) // Jezeli WiFi jest podłączone
    {
      break;                           // to zatrzymaj pętlę
    }
    else                                 // w przeciwnym wypadku
    {
      Serial.print(".");               // wystaw na serial .
      delay(500);                      // i czekaj 0,5 sekundy
    }

  }

  if (WiFi.status() == WL_CONNECTED) // Jeżeli połączenie z siecią zostało nawiązane, wyślij na serial jego parametry
  {
    Serial.println("");
    Serial.println("Polaczenie nawiazane");
    Serial.println("Adres IP: ");
    Serial.print(WiFi.localIP());
    Serial.print(" / ");
    Serial.println(WiFi.subnetMask());
    Serial.print("Brama: ");
    Serial.println(WiFi.gatewayIP());
    long rssi = WiFi.RSSI();
    Serial.print("Sila sygnalu (RSSI): ");
    Serial.print(rssi);
    Serial.println(" dBm");
  }
  else    // w przeciwnym wypadku poinformuj przez serial o nieudanej próbie
  {
    Serial.println("");
    Serial.println("Polaczenia nie udalo sie nawiazac");
  }
}
Awatar użytkownika
slawek
Posty: 2465
Rejestracja: pn mar 14, 2016 11:48 pm
Lokalizacja: Biała Podlaska

Duch__ pisze: śr wrz 26, 2018 8:00 pm 32 kanały DS18b20 na jednym ESP8266 to żaden problem.
Próbuję odpalić 8 DS-ów na jednej płytce i tak naprawdę działa jeden - ten pierwszy.
Odczyt w nim jest odświeżany co 15 - 20 sekund.
Drugi - wydaje mi się, że raz na kilka - kilkanaście minut.
Reszta - pojawia się odczyt w momencie konfigurowania kanału w cloud i taki stan zostaje - wartości temp. są, ale nie są odświeżane.
Da się coś z tym zrobić?
W RBPi 8 kanałów śmiga aż miło...

Kod: Zaznacz cały

/* Przygotowane przez kolegę elmaya na poniższych bibliotekach
   Działa z bibliotekami: FS.h            w wersji: 1.0.3
                          WiFiManager.h   w wersji: 0.12.0
                          ArduinoJson.h   w wersji: 5.13.2
   zmodyfikowany przez wotas567 dodane kilka praktycznych dodatków :) */

#include <FS.h>

#include <ESP8266WiFi.h>
#define SUPLADEVICE_CPP
#include <SuplaDevice.h>

#include <ESP8266WebServer.h>
#include <DNSServer.h>
#include <WiFiManager.h>
#include <ArduinoJson.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPUpdateServer.h>
extern "C" {
#include "user_interface.h"
}
#include <DHT.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define DHTPIN 3 // GPIO 3-RX
#define DHTTYPE DHT22

// Setup a DHT instance
DHT dht(DHTPIN, DHTTYPE);

// Setup a oneWire instance
OneWire oneWire(2); // GPIO 02

// Pass oneWire reference to Dallas Temperature
DallasTemperature sensors(&oneWire);

DeviceAddress jeden = { 0x28, 0xEE, 0x39, 0x65, 0x1F, 0x16, 0x2, 0xAD };      
DeviceAddress dwa = { 0x28, 0xEE, 0xE7, 0xD6, 0x22, 0x16, 0x1, 0x64};    
DeviceAddress trzy = { 0x28, 0x17, 0x14, 0x43, 0x98, 0x22, 0x0, 0x96 };  
DeviceAddress cztery = { 0x28, 0xFF, 0xF8, 0x49, 0x80, 0x14, 0x2, 0xAA };   
DeviceAddress piec = { 0x28, 0xFF, 0x66, 0xCA, 0x51, 0x17, 0x4, 0xD4 };       
DeviceAddress szesc = { 0x28, 0xFF, 0xBE, 0xC5, 0x51, 0x17, 0x4, 0x2E };      
DeviceAddress siedem = { 0x28, 0xFF, 0xE3, 0xE5, 0x51, 0x17, 0x4, 0x27 };  
DeviceAddress osiem = { 0x28, 0xFF, 0xE7, 0x44, 0x80, 0x14, 0x2, 0x24 };  

// Obsługa czujnika DS18B20 i odczyt parametrów modułu ESP
double get_temperature(int channelNumber, double last_val) {
  double t = -275;
  if ( sensors.getDeviceCount() > 0 )
  {
    sensors.requestTemperatures();
    switch (channelNumber)
    {
      case 1:

        t = sensors.getTempC(jeden);
        break;
      case 2:
        t = sensors.getTempC(dwa);
        break;
      case 3:
        t = sensors.getTempC(trzy);
        break;
      case 4:
        t = sensors.getTempC(cztery);
        break;
      case 5:
        t = sensors.getTempC(piec);
        break;
      case 6:
        t = sensors.getTempC(szesc);
        break;
      case 7:
        t = sensors.getTempC(siedem);
        break;
      case 8:
        t = sensors.getTempC(osiem);
        break;
    };
  };
  return t;
}  

//ADC_MODE(ADC_VCC);

//#define BTN_COUNT 2

WiFiClient client;
const char* host = "supla";
const char* update_path = "/nowy";
const char* update_username = "admin";
const char* update_password = "supla";

ESP8266WebServer httpServer(81);
ESP8266HTTPUpdateServer httpUpdater;

//define your default values here, if there are different values in config.json, they are overwritten.
//length should be max size + 1
char Supla_server[40];
char Location_id[15];
char Location_Pass[20];
byte mac[6];

//flag for saving data
bool shouldSaveConfig = false;
bool initialConfig = false;

#define TRIGGER_PIN 0
int timeout           = 120; // seconds to run for

//callback notifying us of the need to save config
void saveConfigCallback () {
  Serial.println("Powinien zapisać konfigurację");
  shouldSaveConfig = true;
}
void ondemandwifiCallback () {
  // The extra parameters to be configured (can be either global or just in the setup)
  // After connecting, parameter.getValue() will get you the configured value
  // id/name placeholder/prompt default length
  WiFiManagerParameter custom_Supla_server("server", "supla server", Supla_server, 40);
  WiFiManagerParameter custom_Location_id("ID", "Location_id", Location_id, 15);
  WiFiManagerParameter custom_Location_Pass("Password", "Location_Pass", Location_Pass, 20);

  //WiFiManager
  //Local intialization. Once its business is done, there is no need to keep it around
  WiFiManager wifiManager;

  //set config save notify callback
  wifiManager.setSaveConfigCallback(saveConfigCallback);

  //add all your parameters here
  wifiManager.addParameter(&custom_Supla_server);
  wifiManager.addParameter(&custom_Location_id);
  wifiManager.addParameter(&custom_Location_Pass);

  //set minimu quality of signal so it ignores AP's under that quality
  //defaults to 8%
  wifiManager.setMinimumSignalQuality();

  // set configportal timeout
  wifiManager.setConfigPortalTimeout(timeout);

  if (!wifiManager.startConfigPortal("SUPLA-IDE")) {
    Serial.println("nie udało się połączyć w osiągniętym limicie czasu");
    delay(3000);
    //reset and try again, or maybe put it to deep sleep
    ESP.restart();
    delay(5000);
  }
  //if you get here you have connected to the WiFi
  Serial.println("połaczono... :)");

  //read updated parameters
  strcpy(Supla_server, custom_Supla_server.getValue());
  strcpy(Location_id, custom_Location_id.getValue());
  strcpy(Location_Pass, custom_Location_Pass.getValue());
}
/*
// obsługa przycisków
typedef struct {
  int pin;
  int relay_pin;
  int channel;
  int ms;
  char last_val;
  unsigned long last_time;
  } _btn_t;

  _btn_t btn[BTN_COUNT];

  void supla_timer() {
  char v;
  unsigned long now = millis();

  for(int a=0;a<BTN_COUNT;a++)
    if (btn[a].pin > 0) {
        v = digitalRead(btn[a].pin);
        if (v != btn[a].last_val && now - btn[a].last_time ) {
           btn[a].last_val = v;
           btn[a].last_time = now;
           if (v==0)
             {
             if ( btn[a].ms > 0 ) {
                     SuplaDevice.relayOn(btn[a].channel, btn[a].ms);
                 } else {
                 if ( digitalRead(btn[a].relay_pin) == 0 ) {
                  SuplaDevice.relayOff(btn[a].channel);
                  Serial.print("BTN Switsh off relay ");
                  Serial.println(btn[a].relay_pin);
                 } else {
                  SuplaDevice.relayOn(btn[a].channel, 0);
                  Serial.print("BTN Switsh on relay ");
                  Serial.println(btn[a].relay_pin);
                 }
             }
        }
      }
  }
  }
  void supla_btn_init() {
  for(int a=0;a<BTN_COUNT;a++)
    if (btn[a].pin > 0) {
        pinMode(btn[a].pin, INPUT_PULLUP);
        btn[a].last_val = digitalRead(btn[a].pin);
        btn[a].last_time = millis();
    }
  }*/

// Obsługa czujnika DHT22 lub BME280 itp
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(115200);
  delay(10);

  wifi_station_set_hostname("SUPLA-IDE");  //nazwa w sieci lokalnej

  pinMode(TRIGGER_PIN, INPUT);

  if (WiFi.SSID() == "") {
    //Serial.println("We haven't got any access point credentials, so get them now");
    initialConfig = true;
  }

  //read configuration from FS json
  Serial.println("adaptacja FS...");

  if (SPIFFS.begin()) {
    Serial.println("ładowanie plików systemu");
    if (SPIFFS.exists("/config.json")) {
      //file exists, reading and loading
      Serial.println("odczyt pliku konfiguracyjnego");
      File configFile = SPIFFS.open("/config.json", "r");
      if (configFile) {
        Serial.println("otwarty plik konfiguracji");
        size_t size = configFile.size();
        // Allocate a buffer to store contents of the file.
        std::unique_ptr<char[]> buf(new char[size]);

        configFile.readBytes(buf.get(), size);
        DynamicJsonBuffer jsonBuffer;
        JsonObject& json = jsonBuffer.parseObject(buf.get());
        Serial.println(jsonBuffer.size());
        json.printTo(Serial);
        if (json.success()) {
          Serial.println("\njson przeanalizowany");

          strcpy(Supla_server, json["Supla_server"]);
          strcpy(Location_id, json["Location_id"]);
          strcpy(Location_Pass, json["Location_Pass"]);

        } else {
          Serial.println("nie udało się załadować konfiguracji json");

        }
      }
    }
    WiFi.softAPdisconnect(true); // wyłączenie rozgłaszania sieci ESP
  } else {
    Serial.println("nie udało się zaadaptować FS");
  }
  WiFi.mode(WIFI_STA); // Force to station mode because if device was switched off while in access point mode it will start up next time in access point mode.

  // Inicjalizacja DHT
  dht.begin();
  SuplaDevice.setTemperatureHumidityCallback(&get_temperature_and_humidity);

  // Inicjalizacja DS18B20
  sensors.begin();
  SuplaDevice.setTemperatureCallback(&get_temperature);

  // Replace the falowing GUID
  uint8_t mac[WL_MAC_ADDR_LENGTH];
  WiFi.macAddress(mac);
  char GUID[SUPLA_GUID_SIZE] = {mac[WL_MAC_ADDR_LENGTH - 6],
                                mac[WL_MAC_ADDR_LENGTH - 5],
                                mac[WL_MAC_ADDR_LENGTH - 4],
                                mac[WL_MAC_ADDR_LENGTH - 3],
                                mac[WL_MAC_ADDR_LENGTH - 2],
                                mac[WL_MAC_ADDR_LENGTH - 1]
                               };

  // CHANNEL0 - DHT22
  SuplaDevice.addDHT22();               // na GPIO3

  // CHANNEL1,2,3... - DS, wifi, zasilanie
  SuplaDevice.addDS18B20Thermometer();  // DS na GPIO02
  SuplaDevice.addDS18B20Thermometer();  
  SuplaDevice.addDS18B20Thermometer();  
  SuplaDevice.addDS18B20Thermometer();  
  SuplaDevice.addDS18B20Thermometer();  
  SuplaDevice.addDS18B20Thermometer();  
  SuplaDevice.addDS18B20Thermometer(); 
  SuplaDevice.addDS18B20Thermometer();

  // CHANNEL9,10 - RELAY
  SuplaDevice.addRelay(4, false);      
  SuplaDevice.addRelay(5, false);     
  SuplaDevice.addRelay(12, false);      
  SuplaDevice.addRelay(13, false);
  SuplaDevice.addRelay(14, false);       
  SuplaDevice.addRelay(16, false);  

  // CHANNEL5,6 - TWO RELAYS (Roller shutter operation)
  //SuplaDevice.addRollerShutterRelays(5,            // 46 - Pin number where the 1st relay is connected
  //                                   13, true);    // 47 - Pin number where the 2nd relay is connected

  // CHANNEL6,7 - Opening sensor (Normal Open)
  // SuplaDevice.addSensorNO(14);   // A0 - Pin number where the sensor is connected
  // SuplaDevice.addSensorNO(12);  // Call SuplaDevice.addSensorNO(A0, true) with an extra "true" parameter
  // to enable the internal pull-up resistor

  /*  memset(btn, 0, sizeof(btn));
    btn[0].pin =14;         // pin gpio  button D5
    btn[0].relay_pin =4;    // pin gpio on which is relay  D1
    btn[0].channel =4;      // supla channel
    btn[0].ms =0;           // if = 0 Bistable -- if > 0 Monostable for X ms
    btn[1].pin =12;         // pin gpio  button D6
    btn[1].relay_pin =13;   // pin gpio on which is relay  D2
    btn[1].channel =5;      // supla channel
    btn[1].ms =2000;           // if = 0 Bistable -- if > 0 Monostable for X ms
    supla_btn_init();
    SuplaDevice.setTimerFuncImpl(&supla_timer);*/
  SuplaDevice.setName("UNI-TEMP by@slawek");

  int LocationID = atoi(Location_id);
  SuplaDevice.begin(GUID,              // Global Unique Identifier
                    mac,               // Ethernet MAC address
                    Supla_server,      // SUPLA server address
                    LocationID,        // Location ID
                    Location_Pass);    // Location Password


  Serial.println();
  Serial.println("Uruchamianie serwera aktualizacji...");
  WiFi.mode(WIFI_STA);

  MDNS.begin(host);
  httpUpdater.setup(&httpServer, update_path, update_username, update_password);
  httpServer.begin();
  MDNS.addService("http", "tcp", 81);
  Serial.printf("HTTPUpdateServer ready! Open http://%s.local%s in your browser and login with username '%s' and password '%s'\n", host, update_path, update_username, update_password);
}

void loop() {

  // is configuration portal requested?
  if ( digitalRead(TRIGGER_PIN) == LOW || (initialConfig))  {
    ondemandwifiCallback () ;
    initialConfig = false;
  }
  //save the custom parameters to FS
  if (shouldSaveConfig) {
    Serial.println("zapisywanie konfiguracji");
    DynamicJsonBuffer jsonBuffer;
    JsonObject& json = jsonBuffer.createObject();
    json["Supla_server"] = Supla_server;
    json["Location_id"] = Location_id;
    json["Location_Pass"] = Location_Pass;

    File configFile = SPIFFS.open("/config.json", "w");
    if (!configFile) {
      Serial.println("nie udało się otworzyć pliku konfiguracyjnego do zapisu");
    }
    json.prettyPrintTo(Serial);
    json.printTo(configFile);
    configFile.close();
    Serial.println("konfiguracia zapisana");
    shouldSaveConfig = false;
    //end save
  }

  if (WiFi.status() != WL_CONNECTED)
  {
    WiFi_up();
  }

  SuplaDevice.iterate();
  SuplaDevice.setTemperatureHumidityCallback(&get_temperature_and_humidity);
  SuplaDevice.setTemperatureCallback(&get_temperature);
  httpServer.handleClient();
}


// Supla.org ethernet layer
int supla_arduino_tcp_read(void *buf, int count) {
  _supla_int_t size = client.available();

  if ( size > 0 ) {
    if ( size > count ) size = count;
    return client.read((uint8_t *)buf, size);
  };

  return -1;
};

int supla_arduino_tcp_write(void *buf, int count) {
  return client.write((const uint8_t *)buf, count);
};

bool supla_arduino_svr_connect(const char *server, int port) {
  return client.connect(server, 2015);
}

bool supla_arduino_svr_connected(void) {
  return client.connected();
}

void supla_arduino_svr_disconnect(void) {
  client.stop();
}

void supla_arduino_eth_setup(uint8_t mac[6], IPAddress *ip) {

  WiFi_up();
}

SuplaDeviceCallbacks supla_arduino_get_callbacks(void) {
  SuplaDeviceCallbacks cb;

  cb.tcp_read = &supla_arduino_tcp_read;
  cb.tcp_write = &supla_arduino_tcp_write;
  cb.eth_setup = &supla_arduino_eth_setup;
  cb.svr_connected = &supla_arduino_svr_connected;
  cb.svr_connect = &supla_arduino_svr_connect;
  cb.svr_disconnect = &supla_arduino_svr_disconnect;
  cb.get_temperature = &get_temperature;
  cb.get_temperature_and_humidity = get_temperature_and_humidity;

  return cb;
}

void WiFi_up() // Procedimiento de conexión para redes WiFi
{
  Serial.print("Łączenie z siecią ");

  WiFi.begin(); // Intentar conectarse a la red

  for (int x = 60; x > 0; x--)
  {
    if (WiFi.status() == WL_CONNECTED)

    {
      break;
    }
    else
    {
      Serial.print(".");
      delay(500);
    }

  }

  if (WiFi.status() == WL_CONNECTED)
  {
    Serial.println("");
    Serial.println("Połączono z");
    Serial.println("Adres IP: ");
    Serial.print(WiFi.localIP());
    Serial.print(" / ");
    Serial.println(WiFi.subnetMask());
    Serial.print("geteway: ");
    Serial.println(WiFi.gatewayIP());
    long rssi = WiFi.RSSI();
    Serial.print("siła sygnału (RSSI): ");
    Serial.print(rssi);
    Serial.println(" dBm");
  }
  else
  {
    Serial.println("");
    Serial.println("brak połączenia");
  }
}
TEORIA jest wtedy gdy wszystko wiemy i nic nie działa
PRAKTYKA jest wtedy gdy wszystko działa a my nie wiemy dlaczego
My łączymy teorię z praktyką czyli nic nie działa i nikt nie wie dlaczego
Awatar użytkownika
slawek
Posty: 2465
Rejestracja: pn mar 14, 2016 11:48 pm
Lokalizacja: Biała Podlaska

Z moich obserwacji dochodzę do wniosku, że odczytywany jest za każdym razem tylko jeden termometr - pierwszy, który zmienił wskazanie...
Dołączam wykresy - wszystkie termometry zamontowane są na wspólnej 20 cm "szynie" - do godz. 0:30 zmieniałem im temperaturę, potem zostawiłem w spokoju... przed godz. 10 znów "mieszam" temperaturą historia się powtarza - wartość zmienia tylko pierwszy. Pozostałe prawdopodobnie zostaną odczytane po ustabilizowaniu poprzednich.
Jak to poprawić?
Załączniki
Screenshot - 2018-10-07 , 11_08_50.jpg
Screenshot - 2018-10-07 , 11_08_50.jpg (58.91 KiB) Przejrzano 6901 razy
TEORIA jest wtedy gdy wszystko wiemy i nic nie działa
PRAKTYKA jest wtedy gdy wszystko działa a my nie wiemy dlaczego
My łączymy teorię z praktyką czyli nic nie działa i nikt nie wie dlaczego
Sibikk
Posty: 366
Rejestracja: pn lis 07, 2016 12:42 pm
Lokalizacja: Katowice
Kontakt:

Panowie jeszcze do Was Prośba, Przemek ma na pewno na głowie ważniejsze sprawy dlatego zgłaszam się do Was o pomoc.

Czego potrzebuję:
Dwie rolety każda z jednym fizyczny przyciskiem ->do otwierania
Czujnik temperatury DS // w kodzie jest obsługa 2 może tak zostać
Czujnik wilgotności DHT22

Kod: Zaznacz cały

#include <DHTesp.h>

#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 5
#define DHTTYPE DHT22
 
// Setup a DHT instance
DHT dht(DHTPIN, DHTTYPE);

OneWire oneWire(4);
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] = {ESP.getChipId()};
  // 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 - RELAY
 // SuplaDevice.addRelay(D5, true);           //definiujemy co chcemy widzieć pod danym kanałem. Tu mamy przekaźnik. true oznacza, ze 
                    //aktywujemy go masą. D5 to GPIO14. mozna wpisywać naprzemiennie

// CHANNEL1 - TWO RELAYS (Roller shutter operation)
SuplaDevice.addRollerShutterRelays(0, 2, true); 
setRollerShutterButtons(int channel_number 1, int btnUpPin 10 , int btnDownPin 102 ); // Piny dla przycisków sterujących 

SuplaDevice.setDigitalReadFuncImpl(&supla_DigitalRead); 102
SuplaDevice.setDigitalWriteFuncImpl(&suplaDigitalWrite); 102

int supla_DigitalRead(int channelNumber, 1 uint8_t pin) {
if (pin > 100) {
return 0;
};

return digitalRead(pin);
}
void suplaDigitalWrite(int channelNumber, 1 uint8_t pin, uint8_t val) { 
if (pin > 100) {
return;
}
digitalWrite(pin, val);
}

 // CHANNEL2 - TWO RELAYS (Roller shutter operation)
SuplaDevice.addRollerShutterRelays(14,     // D1 - Pin number where the 1st relay is connected   
                             12, true);    // D3 - Pin number where the 2nd relay is connected  
setRollerShutterButtons(int channel_number 2, int btnUpPin 9 , int btnDownPin 101 );

   // CHANNEL3 - RELAY
 // SuplaDevice.addRelay(D8, true);  

 // CHANNEL4 - Thermometer DS18B20
  SuplaDevice.addDS18B20Thermometer(5);  //kanał 4 to temomemetr

  
  // CHANNEL - Opening sensor (Normal Open)
  SuplaDevice.addSensorNO(13); // A0 - sensor otwarcia drzwi. na razie go nie używam. podłączamy go przez rezystor 10k  
                               // jezeli nie wiesz o czym mowa to zajrzyj tu https://forbot.pl/blog/microswitche-proste-czujniki-przeszkod-id1870


  // CHANNEL5 - Opening sensor (Normal Open)
  SuplaDevice.addSensorNO(15); // A1 - Pin number where the sensor is connected




  // CHANNEL6 - DHT22 Sensor // pozostałe możliwe czujniki do wykorzystania 
  // SuplaDevice.addDHT11();
  // SuplaDevice.addAM2302();
  SuplaDevice.addDHT22(5);

  SuplaDevice.begin(GUID,              // Global Unique Identifier 
                    mac,               // Ethernet MAC address
                    "svrxxxxx",  // SUPLA server address   // w miejsca xxxx wprowadzamy dane z clouda
                    xxxx,                 // Location ID 
                    "xxxx");               // Location Password

}

void loop() {
  SuplaDevice.iterate();


// ponizej kod umozliwiający włączać i wyłączać przekaźnik 1 z dodatkowego fizycznego przycisku dzwonkowego. W moim przypadku 
// otwieranie/zamykanie bramy

//  TSD_SuplaChannelNewValue przycisk1; //ustaw nazwe dla przycisku
//  przycisk1.SenderID = 0; // Powiadom clouda, że załączasz recznie. W przypadku siłowników ma być 0
//  przycisk1.ChannelNumber = 1; // nr kanału przekaźnika
//  przycisk1.DurationMS = 0; //czas wlaczenia

//button1 = digitalRead(16); 
//if(digitalRead(16)==LOW){ // tu dodajemy jeszcze raz zeby nie pstrykalo samo czyli przerwa i ponowne zapytanie
 // delay(100);
//if(digitalRead(16)==LOW){   //sprawdzam 2 razy stan na PINie 16 w odstępach 100ms . bez tego było dużo zakłuceń
//przycisk1.value[0] = !przycisk1.value[0]; 
//SuplaDevice.channelSetValue(&przycisk1);
//while(digitalRead(16)==LOW);
//delay(20);
}
  
}}

// Supla.org ethernet layer
    int supla_arduino_tcp_read(void *buf, int count) {
        _supla_int_t size = client.available();
       
        if ( size > 0 ) {
            if ( size > count ) size = count;
            return client.read((uint8_t *)buf, size);
        };
    
        return -1;
    };
    
    int supla_arduino_tcp_write(void *buf, int count) {
        return client.write((const uint8_t *)buf, count);
    };
    
    bool supla_arduino_svr_connect(const char *server, int port) {
          return client.connect(server, 2015);
    }
    
    bool supla_arduino_svr_connected(void) {
          return client.connected();
    }
    
    void supla_arduino_svr_disconnect(void) {
         client.stop();
    }
    
    void supla_arduino_eth_setup(uint8_t mac[6], IPAddress *ip) {

       // Serial.println("WiFi init");
        WiFi.begin(ssid, password);

        while (WiFi.status() != WL_CONNECTED) {
            delay(500);
        //    Serial.print(".");
        }

        //Serial.print("\nlocalIP: ");
        //Serial.println(WiFi.localIP());
        //Serial.print("subnetMask: ");
        //Serial.println(WiFi.subnetMask());
        //Serial.print("gatewayIP: ");
        //Serial.println(WiFi.gatewayIP());
    }

SuplaDeviceCallbacks supla_arduino_get_callbacks(void) {
          SuplaDeviceCallbacks cb;
          
          cb.tcp_read = &supla_arduino_tcp_read;
          cb.tcp_write = &supla_arduino_tcp_write;
          cb.eth_setup = &supla_arduino_eth_setup;
          cb.svr_connected = &supla_arduino_svr_connected;
          cb.svr_connect = &supla_arduino_svr_connect;
          cb.svr_disconnect = &supla_arduino_svr_disconnect;
          cb.get_temperature = NULL; //&get_temperature;
          cb.get_temperature_and_humidity = NULL;
          cb.get_rgbw_value = NULL;
          cb.set_rgbw_value = NULL;
          
          return cb;
}
I wali mi błedami

Kod: Zaznacz cały

Arduino:1.8.7 (Windows Store 1.8.15.0) (Windows 10), Płytka:"NodeMCU 1.0 (ESP-12E Module), 80 MHz, 4M (1M SPIFFS), v2 Prebuilt (MSS=536), Disabled, None, 115200"

UWAGA: biblioteka SuplaDevice działa na architekturze(/architekturach) (avr) i może nie być kompatybilna z obecną płytką która działa na architekturze(/architekturach) (esp8266).
In file included from C:\Users\Sibinski\Documents\Arduino\libraries\SuplaDevice/SuplaDevice.h:299:0,

                 from C:\Users\Sibinski\Desktop\Nowy folder1\Programy\sketch_oct15b\sketch_oct15b.ino:8:

C:\Users\Sibinski\Documents\Arduino\libraries\SuplaDevice/supla_main_helper._cpp_: In function 'SuplaDeviceCallbacks supla_arduino_get_callbacks()':

C:\Users\Sibinski\Documents\Arduino\libraries\SuplaDevice/supla_main_helper._cpp_:77:21: error: invalid conversion from 'long int (*)(void*, int)' to '_cb_arduino_rw {aka int (*)(void*, int)}' [-fpermissive]

         cb.tcp_read = &supla_arduino_tcp_read;

                     ^

C:\Users\Sibinski\Documents\Arduino\libraries\SuplaDevice/supla_main_helper._cpp_:81:24: error: invalid conversion from 'bool (*)(const char*, long int)' to '_cb_arduino_connect {aka bool (*)(const char*, int)}' [-fpermissive]

         cb.svr_connect = &supla_arduino_svr_connect;

                        ^

C:\Users\Sibinski\Desktop\Nowy folder1\Programy\sketch_oct15b\sketch_oct15b.ino: In function 'void setup()':

sketch_oct15b:110:25: error: expected primary-expression before 'int'

 setRollerShutterButtons(int channel_number 1, int btnUpPin 10 , int btnDownPin 102 ); // Piny dla przyciskĂłw sterujÄ…cych 

                         ^

sketch_oct15b:110:47: error: expected primary-expression before 'int'

 setRollerShutterButtons(int channel_number 1, int btnUpPin 10 , int btnDownPin 102 ); // Piny dla przyciskĂłw sterujÄ…cych 

                                               ^

sketch_oct15b:110:65: error: expected primary-expression before 'int'

 setRollerShutterButtons(int channel_number 1, int btnUpPin 10 , int btnDownPin 102 ); // Piny dla przyciskĂłw sterujÄ…cych 

                                                                 ^

sketch_oct15b:110:84: error: 'setRollerShutterButtons' was not declared in this scope

 setRollerShutterButtons(int channel_number 1, int btnUpPin 10 , int btnDownPin 102 ); // Piny dla przyciskĂłw sterujÄ…cych 

                                                                                    ^

sketch_oct15b:112:37: error: 'supla_DigitalRead' was not declared in this scope

 SuplaDevice.setDigitalReadFuncImpl(&supla_DigitalRead); 102

                                     ^

sketch_oct15b:113:1: error: expected ';' before 'SuplaDevice'

 SuplaDevice.setDigitalWriteFuncImpl(&suplaDigitalWrite); 102

 ^

sketch_oct15b:115:1: error: expected ';' before 'int'

 int supla_DigitalRead(int channelNumber, 1 uint8_t pin) {

 ^

sketch_oct15b:250:1: error: expected '}' at end of input

 }

 ^

Znaleziono wiele bibliotek w "Ethernet.h"
Wykorzystane: C:\Users\Sibinski\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.4.0\libraries\Ethernet
Niewykorzystane: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\libraries\Ethernet
exit status 1
expected primary-expression before 'int'

Ten raport powinien zawierać więcej informacji jeśli w 
File -> Preferencje zostanie włączona opcja "Pokaż
szczegółowe informacje podczas kompilacji"
Obrazek
Awatar użytkownika
pzygmunt
Posty: 18277
Rejestracja: wt sty 19, 2016 9:26 am
Lokalizacja: Paczków
Kontakt:

Komunikat błędu wyraźnie wskazuje co się nie zgadza.
Masz złe typy zmiennych przy funkcjach na które wskazujesz.

Tu masz jak powinno być
https://github.com/SUPLA/arduino/blob/m ... elper._cpp_

np

Kod: Zaznacz cały

long supla_arduino_tcp_read(void *buf, _supla_int_t count)
a Ty masz

Kod: Zaznacz cały

 int supla_arduino_tcp_read(void *buf, int count) 
itd..
ODPOWIEDZ

Wróć do „FAQ / Jak to zrobić”