Skip to content

Commit

Permalink
Merge pull request #16 from AIS-DeviceIntegration/main
Browse files Browse the repository at this point in the history
fix wrong dir library magellan
  • Loading branch information
maxpromer authored Aug 5, 2023
2 parents ae5f1ab + b90a5ae commit a1bb491
Show file tree
Hide file tree
Showing 24 changed files with 1,594 additions and 5,612 deletions.
7 changes: 4 additions & 3 deletions src/utils/Attribute_MQTT_core.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/*
library version: v2.6.1
Author:(POC Device Magellan team)
library version: v2.5.3
Author:Worawit Sayned (POC Device Magellan team)
Create Date: 25 April 2022.
Modified: 1 november 2022.
Modified: 1 september 2022.
Released for private usage.
*/
#include "Attribute_MQTT_core.h"

BuiltinSensor mySensor;
utility utls;
StorageMemory ext_mem;
FileSystem fileSys;
manageConfigOTAFile configOTAFile;
22 changes: 20 additions & 2 deletions src/utils/Attribute_MQTT_core.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/*
library version: v2.6.1
Author:(POC Device Magellan team)
Create Date: 25 April 2022.
Modified: 1 september 2022.
Modified: 16 february 2023.
Released for private usage.
*/
#ifndef ATTRIBUTE_CORE_H
Expand All @@ -11,13 +10,19 @@ Released for private usage.
#include <Client.h>
#include "../PubSubClient.h"
#include "../ArduinoJson-v6.18.3.h"
#include "./StorageMemory.h"
#include "./FileSystem.h"
#include "./BuiltinSensor.h"
#include "./manageConfigOTAFile.h"
#define useGSMClient 0
#define useExternalClient 1
#include "SPIFFS.h"

#define _major_ver 1
#define _feature_ver 2
#define _enhance_ver 0
#define lib_ver "v"+String(_major_ver) +"."+ String(_feature_ver)+"."+String(_enhance_ver)

class Attribute_MQTT_core
{
public:
Expand Down Expand Up @@ -69,6 +74,19 @@ class Attribute_MQTT_core
static StaticJsonDocument<512> docClientConf;
static DynamicJsonDocument *adjDoc;
static DynamicJsonDocument *docSensor;
//1.2.0
static boolean checkUpdate_inside;
static unsigned int delayCheckUpdate_inside;
static unsigned int delayRequest_download;
static size_t buffer_JSON_bufferSize;
static size_t max_payload_report;
static int matchMsgId_cb;
static int matchMsgId_send;
static int maxRetransmit;

static boolean isMatchMsgId;
static boolean reqRetransmit;

};
extern Attribute_MQTT_core attr;
#endif
256 changes: 252 additions & 4 deletions src/utils/BuiltinSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,262 @@ boolean BuiltinSensor::GPSavailable()
}
else{
GPS_state = GPS.available();
// if(!GPS_state)
// {
// // Serial.println(F("# GPS not available please check signal or antenna GPS connect to board"));
// }
if(!GPS_state)
{
// Serial.println(F("# GPS not available please check signal or antenna GPS connect to board"));
}
}
return GPS_state;
}

void BuiltinSensor::setLocalTimeZone(int timeZone)
{
char _lc[] = "00:00";
char _lc_h[] = "00";
if (!attr.useBuiltInSensor)
{
Serial.println(F("#[Warning] Can't set \"setLocalTimeZone\" allow \"true\" useBuiltinSensor in begin function"));
}
else{
this->local_timeZone = timeZone;
if(local_timeZone >= 0)
{
sprintf(_lc_h, "%02i", local_timeZone);
sprintf(_lc, "%03s:%02s", "+"+String(_lc_h), "00");
}
else
{
sprintf(_lc_h, "%03i", local_timeZone);
sprintf(_lc, "%03s:%02s", String(_lc_h), "00");
}
Serial.println("# Setting local timezone on GPS GMT: " + String(_lc));
}
}

// tm BuiltinSensor::utls.convertUnix(unsigned long unix, int timeZone)
// {
// time_t timestamp = unix + (timeZone * secPerHour);
// tm *local_time = gmtime(&timestamp);
// return *local_time;
// }

int BuiltinSensor::getDay()
{
int _day = 0;
if (!attr.useBuiltInSensor)
{
Serial.println(F("#[Warning] Can't read \"getDay\" allow \"true\" useBuiltinSensor in begin function"));
return _day;
}
else
{
if(GPS.available())
{
_day = utls.convertUnix(GPS.getTime(), local_timeZone).tm_mday;
}
else{
Serial.println(F("# GPS not ready"));
}
}

return _day;
}

String BuiltinSensor::getDayToString()
{
return String(getDay());
}

int BuiltinSensor::getMonth()
{
int _month = 0;
if (!attr.useBuiltInSensor)
{
Serial.println(F("#[Warning] Can't read \"getMonth\" allow \"true\" useBuiltinSensor in begin function"));
return _month;
}
else
{
if(GPS.available())
{
_month = utls.convertUnix(GPS.getTime(), local_timeZone).tm_mon;
}
else{
Serial.println(F("# GPS not ready"));
}
}
return _month;
}

String BuiltinSensor::getMonthToString()
{
return String(getMonth());
}

int BuiltinSensor::getYear()
{
int _year = 0;
if (!attr.useBuiltInSensor)
{
Serial.println(F("#[Warning] Can't read \"getYear\" allow \"true\" useBuiltinSensor in begin function"));
return _year;
}
else
{
if(GPS.available())
{
_year = utls.convertUnix(GPS.getTime(), local_timeZone).tm_year + 1900;
}
else{
Serial.println(F("# GPS not ready"));
}
}
return _year;
}

String BuiltinSensor::getYearToString()
{
return String(getYear());
}

int BuiltinSensor::getHour()
{
int _hour = 0;
if (!attr.useBuiltInSensor)
{
Serial.println(F("#[Warning] Can't read \"getHour\" allow \"true\" useBuiltinSensor in begin function"));
return _hour;
}
else
{
if(GPS.available())
{

_hour = utls.convertUnix(GPS.getTime(), local_timeZone).tm_hour;
}
else{
Serial.println(F("# GPS not ready"));
}
}
return _hour;
}

String BuiltinSensor::getHourToString()
{
return String(getHour());
}

int BuiltinSensor::getMinute()
{
int _minute = 0;
if (!attr.useBuiltInSensor)
{
Serial.println(F("#[Warning] Can't read \"getMinute\" allow \"true\" useBuiltinSensor in begin function"));
return _minute;
}
else
{
if(GPS.available())
{
_minute = utls.convertUnix(GPS.getTime(), local_timeZone).tm_min;
}
else{
Serial.println(F("# GPS not ready"));
}
}
return _minute;
}

String BuiltinSensor::getMinuteToString()
{
return String(getMinute());
}

int BuiltinSensor::getSecond()
{
int _sec = 0;
if (!attr.useBuiltInSensor)
{
Serial.println(F("#[Warning] Can't read \"getSecond\" allow \"true\" useBuiltinSensor in begin function"));
return _sec;
}
else
{
if(GPS.available())
{
_sec = utls.convertUnix(GPS.getTime(), local_timeZone).tm_sec;
}
else{
Serial.println(F("# GPS not ready"));
}
}
return _sec;
}

String BuiltinSensor::getSecondToString()
{
return String(getSecond());
}

String BuiltinSensor::getDateTimeString()
{
tm buff_tm = utls.convertUnix(GPS.getTime(), local_timeZone);
char dateSTR[] = "00/00/0000 00:00:00";
if (!attr.useBuiltInSensor)
{
Serial.println(F("#[Warning] Can't read \"getDateTimeString\" allow \"true\" useBuiltinSensor in begin function"));
return String(dateSTR);
}
else
{
if(GPS.available())
{
sprintf(dateSTR, "%02i/%02i/%04i %02i:%02i:%02i", buff_tm.tm_mday, buff_tm.tm_mon, buff_tm.tm_year + 1900, buff_tm.tm_hour, buff_tm.tm_min, buff_tm.tm_sec);
}
else{
Serial.println(F("# GPS not ready"));
}
}
return String(dateSTR);
}

String BuiltinSensor::getUniversalTime()
{
tm buff_tm = utls.convertUnix(GPS.getTime(), local_timeZone);
char _utc[] = "0000-00-00T00:00:00";
char _lc[] = "00:00";
char _lc_h[] = "00";
String result = "0000-00-00T00:00:00+00:00";
if (!attr.useBuiltInSensor)
{
Serial.println(F("#[Warning] Can't read \"getUniversalTime\" allow \"true\" useBuiltinSensor in begin function"));
return result;
}
else
{
if(GPS.available())
{
sprintf(_utc, "%04i-%02i-%02iT%02i:%02i:%02i", buff_tm.tm_year + 1900, buff_tm.tm_mon, buff_tm.tm_mday,
buff_tm.tm_hour,buff_tm.tm_min, buff_tm.tm_sec);

if(local_timeZone >= 0)
{
sprintf(_lc_h, "%02i", local_timeZone);
sprintf(_lc, "%03s:%02s", "+"+String(_lc_h), "00");
}
else{
sprintf(_lc_h, "%03i", local_timeZone);
sprintf(_lc, "%03s:%02s", String(_lc_h), "00");
}
result = String(_utc) + String(_lc);
}
else{
Serial.println(F("# GPS not ready"));
}
}
return result;
}

unsigned long BuiltinSensor::getUnixTime()
{
unsigned long _unix = (long)0000000000;
Expand Down
19 changes: 18 additions & 1 deletion src/utils/BuiltinSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,24 @@ class BuiltinSensor: private utility
float readTemperature();
float readHumidity();
String readLocation();
unsigned long getUnixTime();

void setLocalTimeZone(int timeZone);
int getDay();
String getDayToString();
int getMonth();
String getMonthToString();
int getYear();
String getYearToString();
int getHour();
String getHourToString();
int getMinute();
String getMinuteToString();
int getSecond();
String getSecondToString();
String getDateTimeString();//*
String getUniversalTime();//*
unsigned long getUnixTime(); //*

};

extern BuiltinSensor mySensor;
Expand Down
Loading

0 comments on commit a1bb491

Please sign in to comment.