Skip to content

Commit

Permalink
Updated for ESP32-C3
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleyhuangyc committed Nov 2, 2021
1 parent 11cdc38 commit b694df6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 27 deletions.
2 changes: 1 addition & 1 deletion ESPRIT/gps_logger/config.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<config>
<target board="esp32 esp32_16m" monitor_baudrate="115200" compiler_opts="-DHAVE_CONFIG">
<target board="esp32 esp32c3" monitor_baudrate="115200" compiler_opts="-DHAVE_CONFIG">
<define name="Storage">
<option name="None" const="STORAGE=STORAGE_NONE"/>
<option name="Flash (SPIFFS)" const="STORAGE=STORAGE_SPIFFS" default="true"/>
Expand Down
10 changes: 5 additions & 5 deletions ESPRIT/gps_logger/datalogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class NullLogger {
write(buf, len);
m_dataCount++;
}
virtual void log(uint16_t pid, unsigned int value)
virtual void log(uint16_t pid, uint32_t value)
{
char buf[24];
byte len = sprintf(buf, "%X,%u", pid, value);
Expand Down Expand Up @@ -133,8 +133,8 @@ class SDLogger : public NullLogger {
SD.mkdir("/DATA");
char path[24];
sprintf(path, "/DATA/%u.CSV", m_id);
Serial.print("File: ");
Serial.println(path);
//Serial.print("File: ");
//Serial.println(path);
m_file = SD.open(path, FILE_WRITE);
if (!m_file) {
Serial.println("File error");
Expand Down Expand Up @@ -184,8 +184,8 @@ class SPIFFSLogger : public NullLogger {
m_id = getFileID(root);
char path[24];
sprintf(path, "/DATA/%u.CSV", m_id);
Serial.print("File: ");
Serial.println(path);
//Serial.print("File: ");
//Serial.println(path);
m_file = SPIFFS.open(path, FILE_WRITE);
if (!m_file) {
Serial.println("File error");
Expand Down
17 changes: 3 additions & 14 deletions ESPRIT/gps_logger/dataserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <FreematicsPlus.h>
#if defined(ESP32)
#include <WiFi.h>
#include <ESPmDNS.h>
#include <SPIFFS.h>
#include <apps/sntp/sntp.h>
#include <esp_spi_flash.h>
Expand All @@ -44,12 +43,6 @@

extern uint32_t fileid;

extern "C"
{
uint8_t temprature_sens_read();
uint32_t hall_sens_read();
}

#if ENABLE_HTTPD
HttpParam httpParam;

Expand All @@ -76,10 +69,6 @@ int handlerInfo(UrlHandlerParam* param)
timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec);
}

int deviceTemp = (int)temprature_sens_read() * 165 / 255 - 40;
bytes += snprintf(buf + bytes, bufsize - bytes, "\"cpu\":{\"temperature\":%d,\"magnetic\":%d},\n",
deviceTemp, hall_sens_read());

#if STORAGE == STORAGE_SPIFFS
bytes += snprintf(buf + bytes, bufsize - bytes, "\"spiffs\":{\"total\":%u,\"used\":%u}",
SPIFFS.totalBytes(), SPIFFS.usedBytes());
Expand Down Expand Up @@ -335,9 +324,9 @@ bool serverCheckup(int wifiJoinPeriod)
Serial.println(WiFi.localIP());

// start mDNS responder
MDNS.begin("gpslogger");
MDNS.addService("http", "tcp", 80);
MDNS.addService("nmea", "tcp", NMEA_TCP_PORT);
//MDNS.begin("gpslogger");
//MDNS.addService("http", "tcp", 80);
//MDNS.addService("nmea", "tcp", NMEA_TCP_PORT);

wifiStartTime = 0;
}
Expand Down
18 changes: 11 additions & 7 deletions ESPRIT/gps_logger/gps_logger.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* THE SOFTWARE.
*************************************************************************/

#include <SPI.h>
#include <Wire.h>
#include <FS.h>
#include <SD.h>
#include <SPIFFS.h>
Expand Down Expand Up @@ -282,9 +282,6 @@ public:
}
void logSensorData()
{
int deviceTemp = (int)temprature_sens_read() * 165 / 255 - 40;
store.log(PID_DEVICE_TEMP, deviceTemp);
store.log(PID_DEVICE_HALL, hall_sens_read() / 100);
store.log(PID_EXT_SENSOR1, analogRead(A0));
}
void waitGPS()
Expand Down Expand Up @@ -432,6 +429,12 @@ void setup()
pinMode(PIN_LED, OUTPUT);
pinMode(PIN_LED, HIGH);

#ifdef ARDUINO_ESP32C3_DEV
Wire.begin(4, 5);
#else
Wire.begin();
#endif

#if ENABLE_DISPLAY
lcd.begin();
initDisplay();
Expand Down Expand Up @@ -543,7 +546,7 @@ void setup()
lcd.println(TRACCAR_HOST);
#endif

Serial.print("File...");
Serial.print("File:");
fileid = store.open();
if (fileid) {
Serial.println(fileid);
Expand Down Expand Up @@ -585,8 +588,9 @@ void loop()
uint32_t ts = millis();

store.setTimestamp(ts);
logger.logSensorData();
//logger.logSensorData();
bool updated = logger.logGPSData();
Serial.println(gd->ts);
if (gd && millis() - gd->ts > GPS_SIGNAL_TIMEOUT) {
#ifdef ENABLE_WIFI_STATION
WiFi.disconnect(false);
Expand Down Expand Up @@ -644,7 +648,7 @@ void loop()
#if ENABLE_HTTPD
serverProcess(ts < MIN_LOOP_TIME ? (MIN_LOOP_TIME - ts) : 0);
#else
if (ts < MIN_LOOP_TIME) delay(MIN_LOOP_TIME - ts);
//if (ts < MIN_LOOP_TIME) delay(MIN_LOOP_TIME - ts);
#endif
#endif
}

0 comments on commit b694df6

Please sign in to comment.