@@ -26,7 +26,7 @@ void msgCallback(char* topic, uint8_t* payload, unsigned int length) {
2626 }
2727 else if (strcmp (rtopic," &resetendpoint" ) == 0 ) {
2828 #ifdef DEBUG_H
29- Serial.println (" RESETTTT-EP " );
29+ Serial.println (" to reset endpoint " );
3030 #endif
3131 if (mg) mg->resetEndpoint ();
3232 }
@@ -89,7 +89,7 @@ int MicroGear::getHTTPReply(Client *client, char *buff, size_t buffsize) {
8989}
9090
9191void MicroGear::resetEndpoint () {
92- writeEEPROM (" " ,EEPROM_ENDPOINTSOFFSET,MAXENDPOINTLENGTH );
92+ writeEEPROM (" " ,EEPROM_ENDPOINTSOFFSET,1 );
9393}
9494
9595void MicroGear::initEndpoint (Client *client, char * endpoint) {
@@ -562,9 +562,9 @@ bool MicroGear::connect(char* appid) {
562562}
563563
564564bool MicroGear::connected () {
565- if (constate == CLIENT_NOTCONNECT) return CLIENT_NOTCONNECT;
566- else return this ->mqttclient ->connected ();
567- // return this->sockclient->connected();
565+ // if (constate == CLIENT_NOTCONNECT) return CLIENT_NOTCONNECT;
566+ // else return this->mqttclient->connected();
567+ return this ->sockclient ->connected ();
568568}
569569
570570void MicroGear::subscribe (char * topic) {
@@ -583,16 +583,48 @@ void MicroGear::unsubscribe(char* topic) {
583583 mqttclient->unsubscribe (top);
584584}
585585
586- void MicroGear::publish (char * topic, char * message) {
587- publish (topic, message, false );
588- }
589-
590- void MicroGear::publish (char * topic, char * message, bool retained) {
586+ bool MicroGear::publish (char * topic, char * message, bool retained) {
591587 char top[MAXTOPICSIZE] = " /" ;
592588
593589 strcat (top,appid);
594590 strcat (top,topic);
595- mqttclient->publish (top, message, retained);
591+ return mqttclient->publish (top, message, retained);
592+ }
593+
594+ bool MicroGear::publish (char * topic, char * message) {
595+ return publish (topic, message, false );
596+ }
597+
598+ bool MicroGear::publish (char * topic, double message, int n) {
599+ return publish (topic, message, n, false );
600+ }
601+
602+ bool MicroGear::publish (char * topic, double message, int n, bool retained) {
603+ char mstr[16 ];
604+ dtostrf (message,0 ,n,mstr);
605+ return publish (topic, mstr, retained);
606+ }
607+
608+ bool MicroGear::publish (char * topic, double message) {
609+ return publish (topic, message, 8 , false );
610+ }
611+
612+ bool MicroGear::publish (char * topic, double message, bool retained) {
613+ return publish (topic, message, 8 , retained);
614+ }
615+
616+ bool MicroGear::publish (char * topic, int message) {
617+ return publish (topic, message, 0 , false );
618+ }
619+
620+ bool MicroGear::publish (char * topic, int message, bool retained) {
621+ return publish (topic, message, 0 , retained);
622+ }
623+
624+ bool MicroGear::publish (char * topic, String message, bool retained) {
625+ char buff[MAXBUFFSIZE];
626+ message.toCharArray (buff,MAXBUFFSIZE);
627+ return publish (topic, buff, retained);
596628}
597629
598630/*
@@ -620,10 +652,38 @@ void MicroGear::setAlias(char* gearalias) {
620652 publish (top," " );
621653}
622654
623- void MicroGear::chat (char * targetgear, char * message) {
655+ bool MicroGear::chat (char * targetgear, char * message) {
656+ bool result;
624657 char top[MAXTOPICSIZE];
658+
625659 sprintf (top," /%s/gearname/%s" ,appid,targetgear);
626- mqttclient->publish (top, message);
660+ result = mqttclient->publish (top, message);
661+ mqttclient->loop ();
662+ return result;
663+ }
664+
665+ bool MicroGear::chat (char * topic, double message, int n) {
666+ bool result;
667+ char mstr[16 ];
668+
669+ dtostrf (message,0 ,n,mstr);
670+ result = chat (topic, mstr);
671+ mqttclient->loop ();
672+ return result;
673+ }
674+
675+ bool MicroGear::chat (char * topic, double message) {
676+ return chat (topic, message, 8 );
677+ }
678+
679+ bool MicroGear::chat (char * topic, int message) {
680+ return chat (topic, message, 0 );
681+ }
682+
683+ bool MicroGear::chat (char * topic, String message) {
684+ char buff[MAXBUFFSIZE];
685+ message.toCharArray (buff,MAXBUFFSIZE);
686+ return chat (topic, buff);
627687}
628688
629689int MicroGear::init (char * gearkey,char * gearsecret) {
0 commit comments