Stacja pogodowa
W konfigu jest pole do wpisania wysokości ... przynajmniej było
W elektronice jak nie wiadomo o co chodzi to zwykle chodzi o zasilanie
Wezmę udział w Supla Offline Party 2024
Wezmę udział w Supla Offline Party 2024
a właśnie że ruszy
Kod: Zaznacz cały
Wire.begin(4,5);
bme.begin(0x76);
// if (!bme.begin(0x76)) {
// Serial.println("Could not find a valid BME280 sensor, check wiring!");
// while (1);
// }
jak coś nie działa to włącz zasilanie.....
Najnowsze dzieło:
Z BME280 - (nie musi być podłączony) - D1, D2 (I2C)
BH 1750 - D1, D2 (I2C)
Anemometr - wiatr na D13 (jak kontrakton to pull up)
Deszcz - D12 (kontrakton pull up)
. skompiloiwane pod ESP Generic więc do WeMOs też wgra się. I Reszty też ?? Nie wiem niech mnie ktoś poprawi ewewntualnie.
Wgrywamy tak (wgrywałem do WeMos )
.
Z BME280 - (nie musi być podłączony) - D1, D2 (I2C)
BH 1750 - D1, D2 (I2C)
Anemometr - wiatr na D13 (jak kontrakton to pull up)
Deszcz - D12 (kontrakton pull up)
. skompiloiwane pod ESP Generic więc do WeMOs też wgra się. I Reszty też ?? Nie wiem niech mnie ktoś poprawi ewewntualnie.
Wgrywamy tak (wgrywałem do WeMos )
.
Kod: Zaznacz cały
KOD:
/* *************************************************************************
*
* Dzieki kolegom @wojtas567 i @Duch__ powstała ta wersja.
*
*
* Wszystkie potrzebne modyfikacja znajdują się w pliku "supla_settings.h"
*
* *************************************************************************
*/
#include <srpc.h>
#include <log.h>
#include <eh.h>
#include <proto.h>
#include <IEEE754tools.h>
#include <lck.h>
#include <Bounce2.h>
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPUpdateServer.h>
#include <EEPROM.h>
#include <DoubleResetDetector.h> //Bilioteka by Stephen Denne
#define SUPLADEVICE_CPP
#include <SuplaDevice.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
Adafruit_BME280 bme; // I2C
#include <DHT.h>
#include <lck.h>
#include <BH1750FVI.h>
BH1750FVI LightSensor(BH1750FVI::k_DevModeContLowRes);
#include "supla_settings.h"
#include "supla_eeprom.h"
#include "supla_web_server.h"
//################## WIATR ########################################
#define WindImpuls 13 // D7 - nr wejścia impulsatora anemometru
double diameter = 2.75;
double mph; //Utworzenie zmiennej mile/godzinÄ
double kmh; //Utowrzenie zmiennej km/h
double ms; // Utworzenie zmiennej m/s
double pomiar[3];
int licz_pomiar;
//######################### DESZCZ #################################
const byte interruptPin = 12;
const int interval = 500;
volatile unsigned long tiptime = millis();
double rainrate;
unsigned long curtime;
//#################################################################
int rawVoltage ;
float voltage;
extern "C" {
#include "user_interface.h"
}
#define DRD_TIMEOUT 5// Number of seconds after reset during which a subseqent reset will be considered a double reset.
#define DRD_ADDRESS 0 // RTC Memory Address for the DoubleResetDetector to use
DoubleResetDetector drd(DRD_TIMEOUT, DRD_ADDRESS);
const char* Config_Wifi_name = CONFIG_WIFI_LOGIN;
const char* Config_Wifi_pass = CONFIG_WIFI_PASSWORD;
const char* www_username;
const char* www_password;
const char* update_path = UPDATE_PATH;
WiFiClient client;
ESP8266WebServer httpServer(80);
ESP8266HTTPUpdateServer httpUpdater;
// Setup a DHT instance
ETSTimer led_timer;
//SUPLA ****************************************************************************************************
char Supla_server[MAX_SUPLA_SERVER];
char Location_id[MAX_SUPLA_ID];
char Location_Pass[MAX_SUPLA_PASS];
//*********************************************************************************************************
//#############################################################
int half_revolution_time = 0; //Utworzenie zmiennej przechowujÄ
cej
double rpm = 0; //Utworzenie zmiennej RPM (obroty)
unsigned long lastmillis = 0; //Utworzenie zmiennej long lastmilis
void rpm_fan() {
unsigned long static last_event = 0;
if (millis() - last_event < 5) { //debouncing
return;
}
half_revolution_time = (millis() - last_event);
last_event = millis();
}
//##################################################################
void setup() {
EEPROM.begin(EEPROM_SIZE);
Serial.begin(115200);
LightSensor.begin();
delay(10);
//WIATR
pinMode(WindImpuls, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(WindImpuls), rpm_fan, FALLING);
//DESZCZ
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), count, FALLING);
Wire.begin(4,5);
bme.begin(0x76);
// if (!bme.begin(0x76)) {
// Serial.println("Could not find a valid BME280 sensor, check wiring!");
// while (1);
// }
supla_led_set(LED_CONFIG_PIN);
if ('1' != char(EEPROM.read(EEPROM_SIZE - 1))) {
czyszczenieEEPROM();
first_start();
save_guid();
}
String www_username1 = String(read_login().c_str());
String www_password1 = String(read_login_pass().c_str());
www_password = strcpy((char*)malloc(www_password1.length() + 1), www_password1.c_str());
www_username = strcpy((char*)malloc(www_username1.length() + 1), www_username1.c_str());
if (drd.detectDoubleReset()) {
drd.stop();
gui_color = GUI_GREEN;
Tryb_konfiguracji();
}
else gui_color = GUI_BLUE;
delay(5000);
drd.stop();
//SuplaDevice *********************************************************************************************
// SuplaDevice.addRelay(5);
// SuplaDevice.addRollerShutterRelays(5, 13);
// SuplaDevice.setRollerShutterButtons(0, 14, 12);
// SuplaDevice.setRollerShutterFuncImpl(&supla_rs_SavePosition, &supla_rs_LoadPosition, &supla_rs_SaveSettings, &supla_rs_LoadSettings);
// SuplaDevice.addSensorNO(4);
// SuplaDevice.addDS18B20Thermometer();
SuplaDevice.addDHT22();
SuplaDevice.addPressureSensor(); // cisnienie
SuplaDevice.addDistanceSensor();
SuplaDevice.addWindSensor();
SuplaDevice.addRainSensor(); //deszcz czujnik
// SuplaDevice.setPressureCallback(&get_pressure);
// SuplaDevice.addRelayButton(5, 14, INPUT_TYPE_BTN_MONOSTABLE, 0, SUPLA_BIT_RELAYFUNC_LIGHTSWITCH);
//SuplaDevice.addRelayButton(13, 12, INPUT_TYPE_BTN_BISTABLE);
//*********************************************************************************************************
// Pokaz_zawartosc_eeprom();
read_guid();
int Location_id = read_supla_id().toInt();
strcpy(Supla_server, read_supla_server().c_str());
strcpy(Location_Pass, read_supla_pass().c_str());
SuplaDevice.setStatusFuncImpl(&status_func);
if (String(read_wifi_ssid().c_str()) == 0
|| String(read_wifi_pass().c_str()) == 0
|| String(read_login().c_str()) == 0
|| String(read_login_pass().c_str()) == 0
|| String(read_supla_server().c_str()) == 0
|| String(read_supla_id().c_str()) == 0
|| String(read_supla_pass().c_str()) == 0
) {
gui_color = GUI_GREEN;
Tryb_konfiguracji();
}
read_guid();
my_mac_adress();
SuplaDevice.setStatusFuncImpl(&status_func);
SuplaDevice.setName(SUPLA_DEVICE_NAME);
SuplaDevice.begin(GUID, // Global Unique Identifier
mac, // Ethernet MAC address
Supla_server, // SUPLA server address
Location_id, // Location ID
Location_Pass);
Serial.println();
Serial.println("Uruchamianie serwera...");
WiFi.mode(WIFI_STA);
createWebServer();
httpUpdater.setup(&httpServer, UPDATE_PATH, www_username, www_password);
httpServer.begin();
}
//************************** VOID LOOP *****************************************************************
void loop() {
if (WiFi.status() != WL_CONNECTED) {
WiFi_up();
}
else httpServer.handleClient();
SuplaDevice.iterate();
//##########################################################
if (millis() - lastmillis >= 1000) {
//Aktualizuj co sekundę
lastmillis = millis(); // Aktualizacja lastmillis
noInterrupts(); // W trakcie kalkulacji wyącz obsĹę przerwań
if (half_revolution_time>0) rpm = (30000 / half_revolution_time) ;
interrupts() ; //Przywróć przerwania
if (rpm>0) {
mph = diameter / 5 * 3.14 * rpm * 60 / 5280;//Odczyt prÄdkoĹci wiatru w milach/godzinÄ
mph = mph * 3.5; // Kalibracja bĹÄdu odczytu, wartoĹÄ naleĹźy dobraÄ we wĹasnym zakresie
kmh = mph * 1.609;// Zamiana mil/godzine na km/h
ms = kmh / 3.6;
Serial.print("Wind meter = ");
Serial.print(ms);
Serial.println(" m/s");
}
pomiar[licz_pomiar]=ms;
if ((pomiar[0]==pomiar[1]) and (pomiar[1]==pomiar[2]) and (pomiar[2]==pomiar[3])) {
ms=0;
}
licz_pomiar=licz_pomiar+1;
if (licz_pomiar==4) licz_pomiar=0;
}
//##############################################################
}
//**********************************WYLICZ OPADY****************************************
void count() {
float de;
// Grab the current ms count for common calculations
unsigned long curtime = millis();
// Make sure we don't record bounces
if ((curtime - tiptime) < interval) {
return;
}
// How long since the last tip?
unsigned long tipcount = curtime - tiptime;
tiptime = curtime;
// Calculate mm/hr from period between cup tips
rainrate = 914400.0 / tipcount;
Serial.print("Cup tip: ");
Serial.print(tipcount);
Serial.println("ms");
Serial.print("Opady deszczu: ");
Serial.print(rainrate/10);
Serial.println("l/m2");
Serial.println("mm/h");
}
//**********************************WYLICZ OPADY END ****************************************
//*********************************************************************************************************
// 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_and_humidity = get_temperature_and_humidity;
cb.get_pressure = get_pressure;
cb.get_distance= get_distance;
cb.get_wind = &get_wind;
cb.get_rain = get_rain;
cb.get_rgbw_value = NULL;
cb.set_rgbw_value = NULL;
return cb;
}
//*********************************************************************************************************
void createWebServer() {
// My_mac = my_mac_adress();
httpServer.on("/", []() {
if (!httpServer.authenticate(www_username, www_password))
return httpServer.requestAuthentication();
httpServer.send(200, "text/html", supla_webpage_start(0));
});
httpServer.on("/set0", []() {
save_wifi_ssid(httpServer.arg("wifi_ssid"));
save_wifi_pass(httpServer.arg("wifi_pass"));
save_login( httpServer.arg("modul_login"));
save_login_pass(httpServer.arg("modul_pass"));
save_supla_server(httpServer.arg("supla_server"));
save_supla_hostname(httpServer.arg("supla_hostname"));
save_supla_id(httpServer.arg("supla_id"));
save_supla_pass(httpServer.arg("supla_pass"));
if (!httpServer.authenticate(www_username, www_password))
return httpServer.requestAuthentication();
httpServer.send(200, "text/html", supla_webpage_start(1));
});
//************************************************************
httpServer.on("/firmware_up", []() {
if (!httpServer.authenticate(www_username, www_password))
return httpServer.requestAuthentication();
httpServer.send(200, "text/html", supla_webpage_upddate());
});
//****************************************************************************************************************************************
httpServer.on("/reboot", []() {
if (!httpServer.authenticate(www_username, www_password))
return httpServer.requestAuthentication();
httpServer.send(200, "text/html", supla_webpage_start(2));
ESP.reset();
}
);
}
//****************************************************************************************************************************************
void Tryb_konfiguracji() {
supla_led_blinking(LED_CONFIG_PIN, 100);
my_mac_adress();
Serial.println("Tryb konfiguracji");
WiFi.disconnect();
delay(1000);
WiFi.mode(WIFI_AP);
WiFi.softAP(Config_Wifi_name, Config_Wifi_pass);
delay(1000);
Serial.println("Tryb AP");
createWebServer();
httpServer.begin();
Serial.println("Start Serwera");
Modul_tryb_konfiguracji = 2;
while (1) {
httpServer.handleClient();
}
}
void WiFi_up() {
// WiFi.setOutputPower(20.5);
supla_led_blinking(LED_CONFIG_PIN, 500);
WiFi.disconnect();
WiFi.hostname(String(read_supla_hostname().c_str()));
WiFi.softAPdisconnect(true);
String esid = String(read_wifi_ssid().c_str());
String epass = String(read_wifi_pass().c_str());
Serial.println("WiFi init");
Serial.print("SSID: ");
Serial.println(esid);
Serial.print("PASSWORD: ");
Serial.println(epass);
WiFi.mode(WIFI_STA);
WiFi.begin(esid.c_str(), epass.c_str());
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());
}
void first_start(void) {
EEPROM.begin(EEPROM_SIZE);
delay(100);
EEPROM.write(EEPROM_SIZE - 1, '1');
EEPROM.end();
delay(100);
save_login(DEFAULT_LOGIN);
save_login_pass(DEFAULT_PASSWORD);
save_supla_hostname(DEFAULT_HOSTNAME);
}
String read_rssi(void) {
long rssi = WiFi.RSSI();
return String(rssi) ;
}
//***************************** TEMP I WILGOTNOŚC *******************************************
void get_temperature_and_humidity(int channelNumber, double *temp, double *humidity) {
*temp = bme.readTemperature();
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" *C");
*humidity = bme.readHumidity();
Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println(" %");
if ( isnan(*temp) || isnan(*humidity) ) {
*temp = -275;
*humidity = -1;
}
}
//***************************** CIŚNIENIE *******************************************
double get_pressure(int channelNumber, double pressure) {
pressure = bme.readPressure() / 100.0F;
Serial.print("Pressure = ");
Serial.print(bme.readPressure()/100);
Serial.println(" hPa");
return pressure;
}
//***************************** LUX *******************************************
double get_distance(int channelNumber, double t) {
// float lux = analogRead(LIGHTSENSORPIN); //TEMT6000
double lux = LightSensor.GetLightIntensity(); //BH1750
t = abs(lux);
Serial.print("Natezenie swiatla = ");
Serial.print(LightSensor.GetLightIntensity());
delay(1250);
return t;
}
//***************************** WIATR *******************************************
double get_wind(int channelNumber, double last_val){
double t = -275;
t=ms;
return t;
}
//*****************************OPADY_DESZCZ*******************************************
double get_rain(int channelNumber, double t) {
//double t = -275;
t = rainrate*100;
return t;
}
//######################################## czujniki end ###############################
void supla_led_blinking_func(void *timer_arg) {
int val = digitalRead(LED_CONFIG_PIN);
digitalWrite(LED_CONFIG_PIN, val == HIGH ? 0 : 1);
}
void supla_led_blinking(int led, int time) {
os_timer_disarm(&led_timer);
os_timer_setfn(&led_timer, supla_led_blinking_func, NULL);
os_timer_arm (&led_timer, time, true);
}
void supla_led_blinking_stop(void) {
os_timer_disarm(&led_timer);
digitalWrite(LED_CONFIG_PIN, 0);
}
void supla_led_set(int ledPin) {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, 1);
}
jak coś nie działa to włącz zasilanie.....
- Robert Błaszczak
- Posty: 4005
- Rejestracja: sob gru 22, 2018 8:55 pm
- Lokalizacja: Zielona Góra
- Kontakt:
Zgadza się. W taki sposób ruszy. Tyle że ten warunek został napisany celem sprawdzenia poprawności podłączenia i działania BME z poziomu monitora portu szeregowego, a jeszcze przed podłączeniem urządzenia do SUPLIQLQ pisze: ↑ndz lip 14, 2019 8:23 am a właśnie że ruszy
Kod: Zaznacz cały
Wire.begin(4,5); bme.begin(0x76); // if (!bme.begin(0x76)) { // Serial.println("Could not find a valid BME280 sensor, check wiring!"); // while (1); // }
Pozdrawiam
Robert Błaszczak
Moja prywatna strona: www.blaszczak.pl
Robert Błaszczak
Moja prywatna strona: www.blaszczak.pl