summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorben Egmose <torben.egmose@gmail.com>2021-02-07 21:21:09 +0100
committerTorben Egmose <torben.egmose@gmail.com>2021-02-07 21:21:09 +0100
commit3d7b03a257c97b0c4147c733d21b038ab9123371 (patch)
treee7b41a45b5c442e9e5af0ceeee62b7b1e1c9aea4
old version
-rw-r--r--.gitignore5
-rw-r--r--.vscode/extensions.json7
-rw-r--r--include/README39
-rw-r--r--lib/README46
-rw-r--r--platformio.ini26
-rw-r--r--src/main.cpp90
-rw-r--r--test/README11
7 files changed, 224 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..89cc49c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+.pio
+.vscode/.browse.c_cpp.db*
+.vscode/c_cpp_properties.json
+.vscode/launch.json
+.vscode/ipch
diff --git a/.vscode/extensions.json b/.vscode/extensions.json
new file mode 100644
index 0000000..0f0d740
--- /dev/null
+++ b/.vscode/extensions.json
@@ -0,0 +1,7 @@
+{
+ // See http://go.microsoft.com/fwlink/?LinkId=827846
+ // for the documentation about the extensions.json format
+ "recommendations": [
+ "platformio.platformio-ide"
+ ]
+}
diff --git a/include/README b/include/README
new file mode 100644
index 0000000..194dcd4
--- /dev/null
+++ b/include/README
@@ -0,0 +1,39 @@
+
+This directory is intended for project header files.
+
+A header file is a file containing C declarations and macro definitions
+to be shared between several project source files. You request the use of a
+header file in your project source file (C, C++, etc) located in `src` folder
+by including it, with the C preprocessing directive `#include'.
+
+```src/main.c
+
+#include "header.h"
+
+int main (void)
+{
+ ...
+}
+```
+
+Including a header file produces the same results as copying the header file
+into each source file that needs it. Such copying would be time-consuming
+and error-prone. With a header file, the related declarations appear
+in only one place. If they need to be changed, they can be changed in one
+place, and programs that include the header file will automatically use the
+new version when next recompiled. The header file eliminates the labor of
+finding and changing all the copies as well as the risk that a failure to
+find one copy will result in inconsistencies within a program.
+
+In C, the usual convention is to give header files names that end with `.h'.
+It is most portable to use only letters, digits, dashes, and underscores in
+header file names, and at most one dot.
+
+Read more about using header files in official GCC documentation:
+
+* Include Syntax
+* Include Operation
+* Once-Only Headers
+* Computed Includes
+
+https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
diff --git a/lib/README b/lib/README
new file mode 100644
index 0000000..6debab1
--- /dev/null
+++ b/lib/README
@@ -0,0 +1,46 @@
+
+This directory is intended for project specific (private) libraries.
+PlatformIO will compile them to static libraries and link into executable file.
+
+The source code of each library should be placed in a an own separate directory
+("lib/your_library_name/[here are source files]").
+
+For example, see a structure of the following two libraries `Foo` and `Bar`:
+
+|--lib
+| |
+| |--Bar
+| | |--docs
+| | |--examples
+| | |--src
+| | |- Bar.c
+| | |- Bar.h
+| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
+| |
+| |--Foo
+| | |- Foo.c
+| | |- Foo.h
+| |
+| |- README --> THIS FILE
+|
+|- platformio.ini
+|--src
+ |- main.c
+
+and a contents of `src/main.c`:
+```
+#include <Foo.h>
+#include <Bar.h>
+
+int main (void)
+{
+ ...
+}
+
+```
+
+PlatformIO Library Dependency Finder will find automatically dependent
+libraries scanning project source files.
+
+More information about PlatformIO Library Dependency Finder
+- https://docs.platformio.org/page/librarymanager/ldf.html
diff --git a/platformio.ini b/platformio.ini
new file mode 100644
index 0000000..6479bc7
--- /dev/null
+++ b/platformio.ini
@@ -0,0 +1,26 @@
+; PlatformIO Project Configuration File
+;
+; Build options: build flags, source filter
+; Upload options: custom upload port, speed and extra flags
+; Library options: dependencies, extra library storages
+; Advanced options: extra scripting
+;
+; Please visit documentation for the other options and examples
+; https://docs.platformio.org/page/projectconf.html
+
+[env:d1_mini]
+platform = espressif8266
+board = d1_mini
+framework = arduino
+upload_protocol = espota
+upload_port = 172.19.1.200
+
+monitor_port = /dev/ttyUSB3
+monitor_speed = 115200
+
+lib_deps =
+ jchristensen/Timezone @ ^1.2.4
+ paulstoffregen/Time @ ^1.6
+ arduino-libraries/NTPClient @ ^3.1.0
+ smougenot/TM1637
+ paulstoffregen/DS1307RTC@0.0.0-alpha+sha.c2590c0033
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..3683a20
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,90 @@
+#include <Arduino.h>
+
+#include <Wire.h>
+#include <Timezone.h> // https://github.com/JChristensen/Timezone
+#include <TimeLib.h> // https://github.com/PaulStoffregen/Time
+#include <DS1307RTC.h> // https://github.com/PaulStoffregen/DS1307RTC
+#include <NTPClient.h> // https://github.com/arduino-libraries/NTPClient
+#include <TM1637Display.h> // https://github.com/avishorp/TM1637
+#include <WiFiManager.h>//https://github.com/tzapu/WiFiManager
+
+#include <ESP8266WiFi.h>
+#include <ESP8266WiFiMulti.h>
+#include <WiFiUdp.h>
+#include <ArduinoOTA.h>
+
+// 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 CE(CEST, CET);
+
+// NTP
+WiFiUDP ntpUDP;
+NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 0, 600000);
+
+// timelib
+time_t utc;
+time_t local;
+
+// display
+//TM1637Display display(1, 3);
+TM1637Display display(D8, D7); // pinClk, pinDIO
+
+uint8_t data[] = { 0xff, 0xff, 0xff, 0xff };
+uint8_t blank[] = { 0x00, 0x00, 0x00, 0x00 };
+
+char buf[4];
+char prev[4];
+
+void setup() {
+ WiFi.mode(WIFI_STA);
+
+ WiFiManager wifiManager;
+ wifiManager.setTimeout(600);
+
+ if(!wifiManager.autoConnect("clock")) {
+ ESP.reset();
+ }
+
+ ArduinoOTA.begin();
+ ESP.wdtEnable(WDTO_8S);
+
+ // put your setup code here, to run once:
+ //Wire.begin(0,2); // 00-sda,02-sdl
+ Wire.begin(D2,D1);
+ timeClient.begin();
+ setSyncProvider(RTC.get);
+ display.clear();
+}
+
+void loop() {
+ ESP.wdtFeed();
+ ArduinoOTA.handle();
+
+ yield();
+
+ // put your main code here, to run repeatedly:
+ if(timeClient.update()) {
+ RTC.set(timeClient.getEpochTime());
+ }
+
+ yield();
+
+ utc = now();
+ local = CE.toLocal(utc);
+
+ yield();
+
+ sprintf(buf, "%.2d%.2d",hour(local), minute(local));
+ data[0] = display.encodeDigit(buf[0] - '0');
+ data[1] = display.encodeDigit(buf[1] - '0');
+ data[2] = display.encodeDigit(buf[2] - '0');
+ data[3] = display.encodeDigit(buf[3] - '0');
+
+ if(strcmp(buf, prev) != 0) {
+ display.setSegments(data);
+ strcpy(prev , buf);
+ }
+
+ yield();
+}
diff --git a/test/README b/test/README
new file mode 100644
index 0000000..b94d089
--- /dev/null
+++ b/test/README
@@ -0,0 +1,11 @@
+
+This directory is intended for PlatformIO Unit Testing and project tests.
+
+Unit Testing is a software testing method by which individual units of
+source code, sets of one or more MCU program modules together with associated
+control data, usage procedures, and operating procedures, are tested to
+determine whether they are fit for use. Unit testing finds problems early
+in the development cycle.
+
+More information about PlatformIO Unit Testing:
+- https://docs.platformio.org/page/plus/unit-testing.html