diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2022-10-10 21:25:01 +0200 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2022-10-10 21:25:01 +0200 |
commit | d3d88101dc42ea5bd71ba2bf724db7e416a4f9a2 (patch) | |
tree | 993f617bda36a28b3e3b9de3502164be33cd06ec /hw | |
parent | prvi commit (diff) | |
download | števec-d3d88101dc42ea5bd71ba2bf724db7e416a4f9a2.tar števec-d3d88101dc42ea5bd71ba2bf724db7e416a4f9a2.tar.gz števec-d3d88101dc42ea5bd71ba2bf724db7e416a4f9a2.tar.bz2 števec-d3d88101dc42ea5bd71ba2bf724db7e416a4f9a2.tar.lz števec-d3d88101dc42ea5bd71ba2bf724db7e416a4f9a2.tar.xz števec-d3d88101dc42ea5bd71ba2bf724db7e416a4f9a2.tar.zst števec-d3d88101dc42ea5bd71ba2bf724db7e416a4f9a2.zip |
Diffstat (limited to 'hw')
-rw-r--r-- | hw/platformio.ini | 12 | ||||
-rw-r--r-- | hw/src/main.cpp | 75 |
2 files changed, 87 insertions, 0 deletions
diff --git a/hw/platformio.ini b/hw/platformio.ini new file mode 100644 index 0000000..5503719 --- /dev/null +++ b/hw/platformio.ini @@ -0,0 +1,12 @@ +; https://docs.platformio.org/page/projectconf.html + +[env:myboard] +platform = espressif8266 +board = nodemcuv2 +monitor_speed = 460800 +upload_speed = 460800 +build_flags = -DDEBUG_ESP_CORE -DDEBUG_ESP_WIFI -DDEBUG_ESP_PORT=Serial -DIP_FORWARD=1 -DMONITOR_SPEED=460800 +framework = arduino +board_build.filesystem = littlefs +board_build.ldscript = eagle.flash.4m2m.ld +src_filter = -<*> +<main.cpp> diff --git a/hw/src/main.cpp b/hw/src/main.cpp new file mode 100644 index 0000000..5b0d7f9 --- /dev/null +++ b/hw/src/main.cpp @@ -0,0 +1,75 @@ +#include <Arduino.h> +#include <EEPROM.h> +#include <WiFiUdp.h> +#include <ESP8266WiFi.h> +unsigned int packets = 0; +WiFiUDP u; +unsigned int doreport = 0; +uint64_t imp; +unsigned long last_imp = 0; +IRAM_ATTR void isr () { + unsigned long time = millis(); + unsigned long lumax = -1; + if (time < last_imp) { // debouncer + if (lumax - last_imp + time < (unsigned long) 100) // saj ne bo več kot 36 kW porabe + return; + } else + if (last_imp + (unsigned long) 100 > time) + return; + last_imp = time; + if (imp++ % 2) + digitalWrite(D8, HIGH); + else + digitalWrite(D8, LOW); +} +void setup () { + Serial.begin(MONITOR_SPEED); + pinMode(D5, INPUT); + pinMode(D6, OUTPUT); + pinMode(D7, OUTPUT); + pinMode(D8, OUTPUT); + EEPROM.begin(512); + EEPROM.get(0, imp); + WiFi.begin("OpenWrt", NULL); + IPAddress a(10,69,69,35); + IPAddress g(10,69,69,1); + IPAddress n(255,255,255,0); + IPAddress d1(10,69,69,1); + IPAddress d2(89,212,194,154); + WiFi.config(a, g, n, d1, d2); + u.begin(35358); + attachInterrupt(digitalPinToInterrupt(D5), isr, FALLING); +} +void loop () { + if (WiFi.status() == WL_CONNECTED) + digitalWrite(D7, LOW); + else + digitalWrite(D7, HIGH); + if (u.parsePacket()) { + packets++; + if (packets % 2) + digitalWrite(D6, HIGH); + else + digitalWrite(D6, LOW); + Serial.println(); + char p[512]; + u.read(p, 255); + if (!strncmp(p, "reset", 5)) { + imp = 0; + Serial.println("reset"); + } + } + uint64_t imp_stored; + EEPROM.get(0, imp_stored); + if (imp_stored != imp) { + EEPROM.put(0, imp); + EEPROM.commit(); + Serial.println(String(imp)); + IPAddress b(255,255,255,255); + u.beginPacket(b, 35358); + char buf[255]; + sprintf(buf, "%lld\n", imp); + u.write(buf); + u.endPacket(); + } +} |