Forum Replies Created
-
AuthorPosts
-
10 February 2021 at 18:09 in reply to: ‘class PCF8574’ has no member named ‘analogWrite’ problem #9804
Hi Pedja,
pcf8574 is a digital I/O expander, analogWrite work only for analog expander or PWM pin, so can’t work with pcf8574.
Bye Renzo
8 February 2021 at 22:15 in reply to: Problem on SMTP: 554 5.6.0 Message contains invalid header. #9754Hi Gilles,
I try to do a fix and i write here when ready.
Bye RenzoHi Cameron,
I understand what you want to do, but It’s discouraged because you lost some information (GTM for example), but here the code modified.
I advise you to use strftime that offer a lot of features here a list.I update local time directly when the value is returned because if you call the functione more than one time you apply N time the DST and you lost control of the time.
unsigned long epoch = tz.toLocal(timeClient.getEpochTime()); setTime(epoch);
and use a strftime like so
Serial.println(getEpochStringByParams(now(), "%H:%M:%S %d.%m.%Y It's a beautiful %A of %B"));
and the complete sketch
pay attention I add my timezone:/* * Simple NTP client update system time with DST applyed (discouraged) * http://mischianti.org/ * * The MIT License (MIT) * written by Renzo Mischianti */ #define DEBUG const char *ssid = ""; const char *password = ""; #include // change next line to use with another board/shield #include //#include // for WiFi shield //#include // for WiFi 101 shield or MKR1000 #include #include #include #include // https://github.com/JChristensen/Timezone /** * Input time in epoch format and return tm time format * by Renzo Mischianti */ static tm getDateTimeByParams(long time) { struct tm *newtime; const time_t tim = time; newtime = localtime(&tim); return *newtime; } /** * Input tm time format and return String with format pattern * by Renzo Mischianti */ static String getDateTimeStringByParams(tm *newtime, char *pattern = (char*) "%d/%m/%Y %H:%M:%S") { char buffer[90]; strftime(buffer, 90, pattern, newtime); return buffer; } /** * Input time in epoch format format and return String with format pattern * by Renzo Mischianti */ static String getEpochStringByParams(long time, char *pattern = (char*) "%d/%m/%Y %H:%M:%S") { // struct tm *newtime; tm newtime; newtime = getDateTimeByParams(time); return getDateTimeStringByParams(&newtime, pattern); } WiFiUDP ntpUDP; // By default 'pool.ntp.org' is used with 60 seconds update interval and // no offset // NTPClient timeClient(ntpUDP); // You can specify the time server pool and the offset, (in seconds) // additionaly you can specify the update interval (in milliseconds). int GTMOffset = 0; // SET TO UTC TIME NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", GTMOffset * 60 * 60, 60 * 60 * 1000); // Central European Time (Frankfurt, Paris) TimeChangeRule CEST = { "CEST", Last, Sun, Mar, 2, 120 }; // Central European Summer Time TimeChangeRule CET = { "CET ", Last, Sun, Oct, 3, 60 }; // Central European Standard Time Timezone tz(CEST, CET); //// US Pacific Time Zone (Las Vegas, Los Angeles) //TimeChangeRule usPDT = {"PDT", Second, Sun, Mar, 2, -420}; //TimeChangeRule usPST = {"PST", First, Sun, Nov, 2, -480}; //Timezone tz(usPDT, usPST); void setup() { Serial.begin(115200); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } timeClient.begin(); delay(1000); if (timeClient.update()) { Serial.print("Adjust local clock"); // unsigned long epoch = timeClient.getEpochTime(); unsigned long epoch = tz.toLocal(timeClient.getEpochTime()); setTime(epoch); } else { Serial.print("NTP Update not WORK!!"); } } void loop() { // I print the time from local clock but first I check DST // to add hours if needed // Serial.println(getEpochStringByParams(tz.toLocal(now()))); Serial.println(getEpochStringByParams(now(), "%H:%M:%S %d.%m.%Y It's a beautiful %A of %B")); Serial.print("MyCrummyCode:"); digitalClockDisplay(); delay(1000); } tmElements_t tm; time_t current_time() { return make_unixtime(tz.toLocal(second()), tz.toLocal(minute()), tz.toLocal(hour()), tz.toLocal(day()), tz.toLocal(month()), tz.toLocal(year())); } time_t make_unixtime(uint8_t sec, uint8_t mn, uint8_t hr, uint8_t dy, uint8_t mon, uint16_t yr) { tm.Second = sec; tm.Hour = hr; tm.Minute = mn; tm.Day = dy; tm.Month = mon; tm.Year = yr - 1970; return makeTime(tm); } void digitalClockDisplay() { // digital clock display of the time #ifdef DEBUG yield(); Serial.print(hour()); yield(); printDigits(minute()); yield(); printDigits(second()); yield(); Serial.print(" "); yield(); Serial.print(day()); yield(); Serial.print("."); yield(); Serial.print(month()); yield(); Serial.print("."); yield(); Serial.print(year()); yield(); Serial.print(" "); yield(); Serial.println(dayStr(weekday())); #endif } void printDigits(int digits) { // utility for digital clock display: prints preceding colon and leading 0 yield(); Serial.print(":"); if (digits < 10) Serial.print('0'); yield(); Serial.print(digits); }
and here the result
MyCrummyCode:7:26:58 3.2.2021 Wednesday 07:26:59 03.02.2021 It's a beautiful Wednesday of February MyCrummyCode:7:26:59 3.2.2021 Wednesday 07:27:00 03.02.2021 It's a beautiful Wednesday of February MyCrummyCode:7:27:00 3.2.2021 Wednesday 07:27:01 03.02.2021 It's a beautiful Wednesday of February MyCrummyCode:7:27:01 3.2.2021 Wednesday 07:27:02 03.02.2021 It's a beautiful Wednesday of February MyCrummyCode:7:27:02 3.2.2021 Wednesday 07:27:03 03.02.2021 It's a beautiful Wednesday of February MyCrummyCode:7:27:03 3.2.2021 Wednesday
Bye Renzo
Attachments:
You must be logged in to view attached files.Hi Rainer,
It’s stragne, check again all the steps, then try to enable verbose debugFile->Preferences->Show verbose output during:. Tick boxes for compilation and upload
.And tell us the result.
Bye RenzoHi Jorn,
to manage pull up and pull down change in debounce, you must specify (like the Arduino pin) if the initial state is in pull up or pull down.By default It’s pull down.
The library has an internal state that memorizes the value change, and though you don’t use an interrupt you can read the button change.
So initialization of your pin to work must be
unit->pinMode(3, INPUT_PULLUP);
Bye Renzo
29 January 2021 at 22:54 in reply to: Weather radio station with Arduino UNO/MEGA Ethernet problem with EMailSender #9628Hi tpapas,
glad to have been helpful.
If you need more help write a topic.
Bye Renzo
28 January 2021 at 22:08 in reply to: Weather radio station with Arduino UNO/MEGA Ethernet problem with EMailSender #9601Hi tpapas,
first, check the code I commend the static IP Ethernet initialization, so to restore It you must uncomment
// start the Ethernet connection and server // Ethernet.begin(mac, ip, myDns, gateway, subnet);
and comment the dhcp initialization
if (Ethernet.begin(mac) == 0) { Serial.println(F("Failed to configure Ethernet using DHCP")); if (Ethernet.hardwareStatus() == EthernetNoHardware) { Serial.println(F("Ethernet shield was not found. Sorry, can't run without hardware. :(")); } else if (Ethernet.linkStatus() == LinkOFF) { Serial.println(F("Ethernet cable is not connected.")); } // no point in carrying on, so do nothing forevermore: while (true) { delay(1); } }
to change the debounce you must change this define
#define EMAIL_SEND_DEBOUNCE 5*60*1000
Try to change the variable like so (to activate immediately the email send)
unsigned long timeElapsed = millis()-EMAIL_SEND_DEBOUNCE;
and fix this
// Check if value > 30 and check if you already send this email if (sensors.getTempCByIndex(0) > 30 && emailSended == false){ emailSended = true; // check if you had already send an email in the last 5 minutes if (timeElapsed+EMAIL_SEND_DEBOUNCE < millis()){ timeElapsed = millis(); sendEmail(); } }else if (sensors.getTempCByIndex(0) < 30 && emailSended == true){ // The value return ok and so if you are going over 30 again new notification was sended emailSended = false; }
Give me a feedback, bye Renzo
Hi Arthur,
thanks for suggestion, It’s very interesting.
I must find some time, but surely I add this section.
Thank Renzo
27 January 2021 at 07:12 in reply to: Example WebSocket temperature humidity esp8266 compiling error #9587Hi VeloTobi,
I also update the github project, now there is the simple version and the more complex.
Bye Renzo
26 January 2021 at 17:01 in reply to: Example WebSocket temperature humidity esp8266 compiling error #9578Hi VeloTobi,
please check the core and library version, I test the sketch width these and It’s work
- Using board d1_mini
- Using core esp8266 2.7.4
- [ESP8266WiFi@1.0]
- [ESP8266WebServer@1.0]
- [WebSockets@2.1.4]
- [WebSockets@2.1.4]
- [Hash@1.0]
- [DHT12_sensor_library@0.9.0]
- [Wire@1.0]
- [ArduinoJson@6.13.0]
Bye Renzo
26 January 2021 at 15:52 in reply to: Weather radio station with Arduino UNO/MEGA Ethernet problem with EMailSender #9572Hi tpapas,
I add the EMailSender to the sketch, I attach the code.
#include <SPI.h> #include <Ethernet.h> #include <OneWire.h> #include <DallasTemperature.h> #include "TimerOne.h" #include <math.h> #include "cactus_io_BME280_I2C.h" #include <EMailSender.h> #define TX_Pin 8 // used to indicate web data tx // Data wire is plugged into digital pin 9 on the Arduino #define ONE_WIRE_BUS 9 #define WindSensor_Pin (2) // digital pin for wind speed sensor #define WindVane_Pin (A2) // analog pin for wind direction sensor #define VaneOffset 0 // define the offset for caclulating wind direction #define WEB_SERVER_PORT 8081 #define EMAIL_SEND_DEBOUNCE 5*60*1000 volatile unsigned int timerCount; // used to count ticks for 2.5sec timer count volatile unsigned long rotations; // cup rotation counter for wind speed calcs volatile unsigned long contactBounceTime; // timer to avoid contact bounce in wind speed sensor volatile float windSpeed; int vaneValue; // raw analog value from wind vane int vaneDirection; // translated 0 - 360 wind direction int calDirection; // calibrated direction after offset applied int lastDirValue; // last recorded direction value int deviceCount = 0; // how many DS18B20 we keep on the OneWire float OutminTemp; // keep track of minimum recorded Outside temp float OutmaxTemp; // keep track of maximum recorded Outside temp float InminTemp; // keep track of minimum recorded Inside temp float InmaxTemp; // keep track of maximum recorded Inside temp // Setup a oneWire instance to communicate with any OneWire device OneWire oneWire(ONE_WIRE_BUS); // Pass oneWire reference to DallasTemperature library DallasTemperature sensors(&oneWire); BME280_I2C bme; // I2C using address 0x77 // Here we setup the web server. We are using a static ip address and a mac address byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(192, 168, 1, 177); IPAddress myDns(192, 168, 1, 1); IPAddress gateway(192, 168, 1, 1); IPAddress subnet(255, 255, 255, 0); EthernetServer server(WEB_SERVER_PORT); // create a server listing on 192.168.1.45 port 80 EMailSender emailSend("apikey", "SG.FINTOFINTOFINTO.FINTOFINTO", "sender.mischianti@gmail.com", "smtp.sendgrid.net", 25 ); void isr_rotation(); void sendEmail(); void setup() { Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } // setup anemometer values lastDirValue = 0; rotations = 0; // setup timer values timerCount = 0; { sensors.begin(); // Start up the library // locate devices on the bus // Serial.print("Locating devices..."); // Serial.print("Found "); // deviceCount = sensors.getDeviceCount(); // Serial.print(deviceCount, DEC); // Serial.println(" devices."); // Serial.println(""); sensors.requestTemperatures(); InminTemp = sensors.getTempCByIndex(0); InmaxTemp = sensors.getTempCByIndex(0); OutminTemp = sensors.getTempCByIndex(1); OutmaxTemp = sensors.getTempCByIndex(1); } // disable the SD card by switching pin 4 High pinMode(4, OUTPUT); digitalWrite(4, HIGH); pinMode(53, OUTPUT); pinMode(10, OUTPUT); digitalWrite(10, HIGH); Serial.println(F("Pin start!")); // start the Ethernet connection and server // Ethernet.begin(mac, ip, myDns, gateway, subnet); if (Ethernet.begin(mac) == 0) { Serial.println(F("Failed to configure Ethernet using DHCP")); if (Ethernet.hardwareStatus() == EthernetNoHardware) { Serial.println(F("Ethernet shield was not found. Sorry, can't run without hardware. :(")); } else if (Ethernet.linkStatus() == LinkOFF) { Serial.println(F("Ethernet cable is not connected.")); } // no point in carrying on, so do nothing forevermore: while (true) { delay(1); } } Serial.println(F("Begin executed!")); server.begin(); if (!bme.begin()) { Serial.println(F("Could not find BME280 sensor, check wiring!")); while (1); } pinMode(TX_Pin, OUTPUT); //pinMode(RG11_Pin, INPUT); pinMode(WindSensor_Pin, INPUT); attachInterrupt(digitalPinToInterrupt(WindSensor_Pin), isr_rotation, FALLING); // setup the timer for 0.5 second Timer1.initialize(500000); Timer1.attachInterrupt(isr_timer); sei(); // Enable Interrupts Serial.print(F("IP: ")); Serial.println(Ethernet.localIP()); Serial.print(F("Web Server: http://")); Serial.print(Ethernet.localIP()); Serial.print(F(":")); Serial.print(WEB_SERVER_PORT); } bool emailSended = false; unsigned long timeElapsed = millis(); void loop() { // Send command to all the sensors for temperature conversion sensors.requestTemperatures(); bme.readSensor(); // update min and max temp values for Outside and Inside Temperatures if (sensors.getTempCByIndex(1) < OutminTemp) { OutminTemp = sensors.getTempCByIndex(1); } if (sensors.getTempCByIndex(1) > OutmaxTemp) { OutmaxTemp = sensors.getTempCByIndex(1); } if (sensors.getTempCByIndex(0) < InminTemp) { InminTemp = sensors.getTempCByIndex(0); } if (sensors.getTempCByIndex(0) > InmaxTemp) { InmaxTemp = sensors.getTempCByIndex(0); } // Check if value > 30 and check if you already send this email if (sensors.getTempCByIndex(0) > 30 && emailSended == false){ emailSended = true; // check if you had already send an email in the last 5 minutes if ((timeElapsed+EMAIL_SEND_DEBOUNCE)<millis()){ timeElapsed = millis(); sendEmail(); } }else{ // The value return ok and so if you are going over 30 again new notification was sended emailSended = false; } // listen for incoming clients EthernetClient client = server.available(); if (client) { // an http request ends with a blank line boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); Serial.write(c); // if you've gotten to the end of the line (received a newline // character) and the line is blank, the http request has ended, // so you can send a reply if (c == '\n' && currentLineIsBlank) { // send a standard http response header digitalWrite(TX_Pin, HIGH); client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); // connection closed completion of response client.println("Refresh: 10"); // refresh the page automatically every 10 sec client.println(); client.println("<!DOCTYPE HTML>"); client.print("<HTML><HEAD><TITLE>RadioActive Weather Server</TITLE></HEAD>"); client.println("<font color='red'><h2>RadioActive Weather Server</font></h2>"); client.print("Agios Merkouris, Sifnos @ 36.987832, 24.719809<br><br>"); client.println("<html><body>"); digitalWrite(TX_Pin, HIGH); // Turn the TX LED on client.print("<span style=\"font-size: 26px\";>Outside Temperature now "); client.print(sensors.getTempCByIndex(1)); client.println("C<br>"); client.print("<br> Inside Temperature now "); client.print(sensors.getTempCByIndex(0)); client.println("C<br>"); client.print("<br> Wind Speed now "); client.print(windSpeed); client.println(" mph<br>"); getWindDirection(); client.print("<br> Direction now "); client.print(calDirection); client.print(direction(calDirection)); client.println("<br>"); client.print("<br> Humidity now "); client.print(bme.getHumidity()); client.println("%<br>"); client.print("<br> Pressure now "); client.print(bme.getPressure_MB()); client.println("mb%<br>"); client.print("<br> Outside Min Temperature was "); client.print(OutminTemp); client.println("C<br>"); client.print("<br> Outside Max Temperature was "); client.print(OutmaxTemp); client.println("C<br>"); client.print("<br> Inside Min Temperature was "); client.print(InminTemp); client.println("C<br>"); client.print("<br> Inside Max Temperature was "); client.print(InmaxTemp); client.println("C"); client.println("</body></html>"); digitalWrite(TX_Pin, LOW); // Turn the TX LED off break; } if (c == '\n') { // you're starting a new line currentLineIsBlank = true; } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; } } } } // give the web browser time to receive the data delay(1); // close the connection: client.stop(); } // Interrupt handler routine for timer interrupt void isr_timer() { timerCount++; if (timerCount == 5) { // convert to mp/h using the formula V=P(2.25/T) // V = P(2.25/2.5) = P * 0.9 windSpeed = rotations * 0.9; rotations = 0; timerCount = 0; } } // Interrupt handler routine to increment the rotation count for wind speed void isr_rotation() { if ((millis() - contactBounceTime) > 15) { // debounce the switch contact rotations++; contactBounceTime = millis(); } } // Get Wind Direction void getWindDirection() { vaneValue = analogRead(WindVane_Pin); vaneDirection = map(vaneValue, 0, 1023, 0, 360); calDirection = vaneDirection + VaneOffset; if (calDirection > 360) calDirection = calDirection - 360; if (calDirection > 360) calDirection = calDirection - 360; } const char* direction(int calDirection){ if ((calDirection) < 23) { return " North"; } if ((calDirection > 22) && (calDirection < 68)) { return " NorthEast"; } if ((calDirection > 67) && (calDirection < 113)) { return " East"; } if ((calDirection > 112) && (calDirection < 158)) { return " SouthEast"; } if ((calDirection > 157) && (calDirection < 203)) { return " South"; } if ((calDirection > 202) && (calDirection < 247)) { return " SouthWest"; } if ((calDirection > 246) && (calDirection < 292)) { return " West"; } if ((calDirection > 291) && (calDirection < 337)) { return " NorthWest"; } if ((calDirection > 336) && (calDirection <= 360)) { return " North"; } return "No data!"; } void sendEmail(){ EMailSender::EMailMessage message; message.subject = "RadioActive Weather Server"; getWindDirection(); message.message = ("Ciao come stai<br>io bene." "<span style=\"font-size: 26px\";>Outside Temperature now " +String(sensors.getTempCByIndex(1))+ "C<br>" + ("<br> Inside Temperature now ") +String(sensors.getTempCByIndex(0))+ "C<br>" "<br> Wind Speed now " +String(windSpeed)+ " mph<br>" "<br> Direction now " +direction(calDirection)+ "<br>" "<br> Humidity now " +String(bme.getHumidity())+ "%<br>" "<br> Pressure now " +String (bme.getPressure_MB())+ "mb%<br>" "<br> Outside Min Temperature was " +String(OutminTemp)+ "C<br>" "<br> Outside Max Temperature was " +String(OutmaxTemp)+ "C<br>" "<br> Inside Min Temperature was " +String(InminTemp)+ "C<br>" "<br> Inside Max Temperature was " +String(InmaxTemp)+ "C"); const char* emailToSend = "receiver.mischianti@gmail.com"; EMailSender::Response resp = emailSend.send(emailToSend, message); Serial.println(F("Sending status: ")); Serial.println(resp.status); Serial.println(resp.code); Serial.println(resp.desc); }
I get a w5100 shield and now can try to test It.
Bye Renzo
Attachments:
You must be logged in to view attached files.26 January 2021 at 11:43 in reply to: Weather radio station with Arduino UNO/MEGA Ethernet problem with EMailSender #9568Hi tpapas,
try to add pin 10 HIGH (as documentation)pinMode(53, OUTPUT); pinMode(4, OUTPUT); digitalWrite(4, HIGH); pinMode(10, OUTPUT); digitalWrite(10, HIGH);
and add this code to check If there are some problem
// Check for Ethernet hardware present if (Ethernet.hardwareStatus() == EthernetNoHardware) { Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); while (true) { delay(1); // do nothing, no point running without Ethernet hardware } } if (Ethernet.linkStatus() == LinkOFF) { Serial.println("Ethernet cable is not connected."); }
I don’t have a w5100 shield, but this is a must have :P.
And check if shield is fitted good, sometime the problems is more simple than expected.
Bye Renzo
26 January 2021 at 10:26 in reply to: Using EMail Sender library with Arduino UNO Ethernet shield with Ethernet.h library #9565We are going quite off topic, so I create a topic in the relative section, and I need some time to check It. But I will response to you in that section.
Weather radio station with Arduino UNO/MEGA Ethernet problem
Bye Renzo
24 January 2021 at 22:24 in reply to: Using EMail Sender library with Arduino UNO Ethernet shield with Ethernet.h library #9533If the email work the ethernet work, the arduino clones, usually, work like a charm,
With this information It’s very difficult to do a debug.
You must give me more information, what kind of problem do you have?
Bye Renzo
24 January 2021 at 14:48 in reply to: Using EMail Sender library with Arduino UNO Ethernet shield with Ethernet.h library #9526Hehehehhe, I’m moved 😛
For the recipient you can follow the instruction on the article
Send email with attachments (v2.x library): Arduino Ethernet – 1
there is an example on library
and the relative forum topic
EMail distribution list – more than one recipient
If you have some trouble write here.
Bye Renzo
-
AuthorPosts