fixed longint conversion Mega

This commit is contained in:
2019-03-07 19:16:03 +03:00
parent eb43bc5d18
commit 515728207f
6 changed files with 31 additions and 20 deletions

View File

@@ -10,6 +10,12 @@ const char name_P[] PROGMEM = "$name";
const char nameval_P[] PROGMEM = "LightHub "; const char nameval_P[] PROGMEM = "LightHub ";
const char nodes_P[] PROGMEM = "$nodes"; const char nodes_P[] PROGMEM = "$nodes";
const char localip_P[] PROGMEM = "$localip";
const char mac_P[] PROGMEM = "$mac";
const char fwname_P[] PROGMEM = "$fw/name";
const char fwversion_P[] PROGMEM = "$fw/version";
const char implementation_P[] PROGMEM = "$implementation";
const char interval_P[] PROGMEM = "$stats/interval";
const char color_P[] PROGMEM = "color"; const char color_P[] PROGMEM = "color";
const char datatype_P[] PROGMEM = "$datatype"; const char datatype_P[] PROGMEM = "$datatype";

View File

@@ -113,6 +113,8 @@ int Input::poll() {
#ifndef DHT_DISABLE #ifndef DHT_DISABLE
else if (inType & IN_DHT22) else if (inType & IN_DHT22)
dht22Poll(); dht22Poll();
#endif
#ifndef COUNTER_DISABLE
else if (inType & IN_COUNTER) else if (inType & IN_COUNTER)
counterPoll(); counterPoll();
else if (inType & IN_UPTIME) else if (inType & IN_UPTIME)
@@ -497,20 +499,6 @@ void Input::onAnalogChanged(int newValue) {
} }
void Input::printUlongValueToStr(char *valstr, unsigned long value) {
char buf[11];
int i=0;
for(;value>0;i++){
unsigned long mod = value - ((unsigned long)(value/10))*10;
buf[i]=mod+48;
value = (unsigned long)(value/10);
}
for(int n=0;n<=i;n++){
valstr[n]=buf[i-n-1];
}
valstr[i]='\0';
}
bool Input::publishDataToDomoticz(int pollTimeIncrement, aJsonObject *emit, const char *format, ...) bool Input::publishDataToDomoticz(int pollTimeIncrement, aJsonObject *emit, const char *format, ...)
{ {
#ifdef WITH_DOMOTICZ #ifdef WITH_DOMOTICZ

View File

@@ -126,7 +126,6 @@ protected:
void uptimePoll(); void uptimePoll();
void printUlongValueToStr(char *valstr, unsigned long value);
bool publishDataToDomoticz(int , aJsonObject *, const char *format, ...); bool publishDataToDomoticz(int , aJsonObject *, const char *format, ...);
char* getIdxField(); char* getIdxField();

View File

@@ -1398,22 +1398,22 @@ void publishStat(){
long fr = freeRam(); long fr = freeRam();
char topic[64]; char topic[64];
char intbuf[16]; char intbuf[16];
uint32_t ut = millis()/1000; uint32_t ut = millis()/1000UL;
// debugSerial<<F("\nfree RAM: ")<<fr; // debugSerial<<F("\nfree RAM: ")<<fr;
setTopic(topic,sizeof(topic),T_DEV); setTopic(topic,sizeof(topic),T_DEV);
strncat_P(topic, stats_P, sizeof(topic)); strncat_P(topic, stats_P, sizeof(topic));
strncat(topic, "/", sizeof(topic)); strncat(topic, "/", sizeof(topic));
strncat_P(topic, freeheap_P, sizeof(topic)); strncat_P(topic, freeheap_P, sizeof(topic));
printUlongValueToStr(intbuf, fr);
mqttClient.publish(topic,itoa(fr,intbuf,10),true); mqttClient.publish(topic,intbuf,true);
setTopic(topic,sizeof(topic),T_DEV); setTopic(topic,sizeof(topic),T_DEV);
strncat_P(topic, stats_P, sizeof(topic)); strncat_P(topic, stats_P, sizeof(topic));
strncat(topic, "/", sizeof(topic)); strncat(topic, "/", sizeof(topic));
strncat_P(topic, uptime_P, sizeof(topic)); strncat_P(topic, uptime_P, sizeof(topic));
printUlongValueToStr(intbuf, ut);
mqttClient.publish(topic,itoa(ut,intbuf,10),true); mqttClient.publish(topic,intbuf,true);
} }
void setupMacAddress() { void setupMacAddress() {

View File

@@ -412,5 +412,22 @@ return buf;
} }
void printUlongValueToStr(char *valstr, unsigned long value) {
char buf[11];
int i=0;
for(;value>0;i++){
unsigned long mod = value - ((unsigned long)(value/10))*10;
buf[i]=mod+48;
value = (unsigned long)(value/10);
}
for(int n=0;n<=i;n++){
valstr[n]=buf[i-n-1];
}
valstr[i]='\0';
}
#pragma message(VAR_NAME_VALUE(debugSerial)) #pragma message(VAR_NAME_VALUE(debugSerial))
#pragma message(VAR_NAME_VALUE(SERIAL_BAUD)) #pragma message(VAR_NAME_VALUE(SERIAL_BAUD))

View File

@@ -54,3 +54,4 @@ int inet_aton(const char* aIPAddrString, IPAddress& aResult);
char *inet_ntoa_r(IPAddress addr, char *buf, int buflen); char *inet_ntoa_r(IPAddress addr, char *buf, int buflen);
void printIPAddress(IPAddress ipAddress); void printIPAddress(IPAddress ipAddress);
char* setTopic(char* buf, int8_t buflen, topicType tt, char* suffix = NULL); char* setTopic(char* buf, int8_t buflen, topicType tt, char* suffix = NULL);
void printUlongValueToStr(char *valstr, unsigned long value);