Skip to content

Commit

Permalink
working on esp32 stimawifi
Browse files Browse the repository at this point in the history
  • Loading branch information
pat1 committed Jan 18, 2024
1 parent 2e26f48 commit 6aa43f2
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 37 deletions.
46 changes: 37 additions & 9 deletions platformio/stima_v3/stimawifi/src/arduino_thread.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
#include "arduino_thread.h"
//#include "arduino_thread.h"
#include "stimawifi.h"

void printLocalTime()
{
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
LOGE("No time available (yet)");
return;
}
Serial.println(&timeinfo, "%y %m %d %H:%M:%S");
}

// Callback function (get's called when time adjusts via NTP)
void timeavailable(struct timeval *t)
{
LOGN("Got time adjustment from NTP!");
printLocalTime();
}

void analogWriteFreq(const double frequency){
//analogWriteFrequency(frequency);
Expand Down Expand Up @@ -180,7 +198,6 @@ String rmap_get_remote_config(){
url+="/default/json/"; // get one station, default boards

frtosLog.notice(F("readRmapRemoteConfig url: %s"),url.c_str());
//http.begin("http://rmap.cc/stations/pat1/luftdaten/json/");
http.begin(espClient,url.c_str());

int httpCode = http.GET();
Expand Down Expand Up @@ -329,7 +346,6 @@ int rmap_config(const String payload){
int ii = 0;

if (! (payload == String())) {
//StaticJsonDocument<2900> jsonBuffer;
DynamicJsonDocument doc(4000);
status = 3;
DeserializationError error = deserializeJson(doc,payload);
Expand Down Expand Up @@ -974,8 +990,19 @@ void setup() {

sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, ntp_server);
sntp_init();
// set notification call-back function
sntp_set_time_sync_notification_cb( timeavailable );

configTime(3600, 0, ntp_server);

if (esp_netif_sntp_sync_wait(pdMS_TO_TICKS(30000)) != ESP_OK) {
LOGE("Failed to update system time within 30s timeout");
}
printLocalTime();

//sntp_init();
// wait for time to be set
/*
time_t now = 0;
struct tm timeinfo = { 0 };
int retry = 0;
Expand All @@ -986,7 +1013,7 @@ void setup() {
time(&now);
localtime_r(&now, &timeinfo);
}

if(retry >= retry_count) {
if (oledpresent){
u8g2.clearBuffer();
Expand All @@ -1003,10 +1030,11 @@ void setup() {
delay(1000);
reboot(); //300 seconds timeout - reset board
}

frtosLog.notice(F("Time: %s"),ctime(&now));
setTime(now);

*/

time_t datetime = now();
frtosLog.notice(F("Time: %s"),ctime(&datetime));

frtosLog.notice(F("mqtt server: %s"),rmap_mqtt_server);

mqttclient.setServer(rmap_mqtt_server, 1883);
Expand Down
13 changes: 12 additions & 1 deletion platformio/stima_v3/stimawifi/src/arduino_thread.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
#include "stimawifi.h"
#include <WiFi.h>
#include <ESPmDNS.h>
#include <WebServer.h>
#include <HTTPClient.h>
//#include <ESP32httpUpdate.h>
#include <LittleFS.h>
#include "esp_netif_sntp.h"
#include "esp_netif.h"
#include "esp_sntp.h"
#include <TimeAlarms.h>
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
#include <LOLIN_I2C_BUTTON.h>

#ifndef ARDUINO_THREAD_H_
#define ARDUINO_THREAD_H_
Expand Down
2 changes: 1 addition & 1 deletion platformio/stima_v3/stimawifi/src/measure_thread.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "measure_thread.h"
#include "stimawifi.h"

void enqueueMqttMessage(char* values, const char* timerange, const char* level, Queue* MqttQueue ) {

Expand Down
2 changes: 1 addition & 1 deletion platformio/stima_v3/stimawifi/src/measure_thread.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "stimawifi.h"
#include <SensorDriverb.h>

#ifndef MEASURE_THREAD_H_
#define MEASURE_THREAD_H_
Expand Down
2 changes: 1 addition & 1 deletion platformio/stima_v3/stimawifi/src/publish_thread.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "publish_thread.h"
#include "stimawifi.h"

bool publish_maint() {

Expand Down
2 changes: 1 addition & 1 deletion platformio/stima_v3/stimawifi/src/publish_thread.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "stimawifi.h"
#include <PubSubClient.h>

#ifndef PUBLISH_THREAD_H_
#define PUBLISH_THREAD_H_
Expand Down
24 changes: 4 additions & 20 deletions platformio/stima_v3/stimawifi/src/stimawifi.h
Original file line number Diff line number Diff line change
@@ -1,43 +1,27 @@

#ifndef STIMAWIFI_H_
#define STIMAWIFI_H_

#include "Arduino.h"
#include "stimawifi-config.h"
#include "typedef.h"
#include <frtosLog.h>
#include <WiFi.h>
#include <ESPmDNS.h>
#include <WebServer.h>
#include <HTTPClient.h>
//#include <ESP32httpUpdate.h>
#include <LittleFS.h>
#include "thread.hpp"
//#include "critical.hpp"
#include "ticks.hpp"
#include "queue.hpp"
//needed for library
#include <DNSServer.h>
//#include <WebSocketsServer.h>
//#include "EspHtmlTemplateProcessor.h"
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
#include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson
#include <PubSubClient.h>
#include <TimeAlarms.h>
#include <Wire.h>
#include <SensorDriverb.h>
#include <U8g2lib.h>
#include "time.h"
#include <LOLIN_I2C_BUTTON.h>
#include <WiFiUdp.h>
#include "ozgps.h"
#include "esp_sntp.h"
//#include "esp_netif_sntp.h"

#include "udp_thread.h"
#include "measure_thread.h"
#include "publish_thread.h"
#include "arduino_thread.h"
#include "USB.h"

#ifndef STIMAWIFI_H_
#define STIMAWIFI_H_

//////////////// REMOVE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
extern String readconfig_rmap();
Expand Down
2 changes: 1 addition & 1 deletion platformio/stima_v3/stimawifi/src/stimawifi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ char rmap_longitude[11] = "";
char rmap_latitude[11] = "";
char rmap_network[31] = "";
char rmap_server[41] = "rmap.cc";
char ntp_server[41] = "0.europe.pool.ntp.org";
char ntp_server[41] = "europe.pool.ntp.org";
char rmap_mqtt_server[41] = "rmap.cc";
int rmap_sampletime = DEFAULT_SAMPLETIME;
char rmap_user[10] = "";
Expand Down
2 changes: 1 addition & 1 deletion platformio/stima_v3/stimawifi/src/udp_thread.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "udp_thread.h"
#include "stimawifi.h"

void doUdp(void){

Expand Down
3 changes: 2 additions & 1 deletion platformio/stima_v3/stimawifi/src/udp_thread.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "stimawifi.h"
#include <WiFiUdp.h>
#include "ozgps.h"

#ifndef UDP_THREAD_H_
#define UDP_THREAD_H_
Expand Down

0 comments on commit 6aa43f2

Please sign in to comment.