Skip to content

Commit ff5dc83

Browse files
committed
add retained publish option
1 parent 192fb25 commit ff5dc83

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

AuthClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ int AuthClient::getGearToken(char mode, char* token, char* tokensecret, char* en
320320

321321
writeln("Accept: */*");
322322
writeln("Connection: close");
323-
writeln("User-Agent: Arduigear");
323+
writeln("User-Agent: E8A");
324324
writeln("Content-length: 0");
325325
writeln("Content-Type: application/x-www-form-urlencoded");
326326
writeln(NULL);

AuthClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ class AuthClient {
4949
void addParam(char*, char*, char*, bool);
5050
unsigned long bootts;
5151
};
52-
#endif // HTTPCLIENT_H
52+
#endif

MicroGear.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ void MicroGear::getToken(char *gkey, char *galias, char* token, char* tokensecre
190190
tokensecret[0] = '\0';
191191

192192
readEEPROM(ekey,EEPROM_KEYOFFSET,KEYSIZE);
193-
if (strncmp(gkey,ekey,KEYSIZE)!=0)
194-
resetToken();
193+
if (strncmp(gkey,ekey,KEYSIZE)!=0) resetToken();
195194

196195
readEEPROM(state,EEPROM_STATEOFFSET,1);
197196
#ifdef DEBUG_H
@@ -268,6 +267,7 @@ void MicroGear::getToken(char *gkey, char *galias, char* token, char* tokensecre
268267
#ifdef DEBUG_H
269268
Serial.println("authclient is disconnected");
270269
#endif
270+
authclient->stop();
271271
delay(1000);
272272
}
273273
}
@@ -347,7 +347,7 @@ void MicroGear::getToken(char *gkey, char *galias, char* token, char* tokensecre
347347
authclient->stop();
348348
}
349349

350-
boolean MicroGear::connect(char* appid) {
350+
bool MicroGear::connect(char* appid) {
351351
char username[USERNAMESIZE+1];
352352
char password[PASSWORDSIZE+1];
353353
char buff[2*TOKENSECRETSIZE+2];
@@ -423,7 +423,6 @@ boolean MicroGear::connect(char* appid) {
423423

424424
if (cb_connected)
425425
cb_connected(NULL,NULL,0);
426-
427426
break;
428427
case CLIENT_NOTCONNECT :
429428
if (backoff < MAXBACKOFFTIME) backoff = 2*backoff;
@@ -435,7 +434,7 @@ boolean MicroGear::connect(char* appid) {
435434
else return false;
436435
}
437436

438-
boolean MicroGear::connected() {
437+
bool MicroGear::connected() {
439438
if (constate == CLIENT_NOTCONNECT) return CLIENT_NOTCONNECT;
440439
else return this->mqttclient->connected();
441440
//return this->sockclient->connected();
@@ -458,11 +457,15 @@ void MicroGear::unsubscribe(char* topic) {
458457
}
459458

460459
void MicroGear::publish(char* topic, char* message) {
460+
publish(topic, message, false);
461+
}
462+
463+
void MicroGear::publish(char* topic, char* message, bool retained) {
461464
char top[MAXTOPICSIZE] = "/";
462465

463466
strcat(top,appid);
464467
strcat(top,topic);
465-
mqttclient->publish(top, message);
468+
mqttclient->publish(top, message, retained);
466469
}
467470

468471
/*
@@ -505,7 +508,6 @@ int MicroGear::init(char* gearkey,char* gearsecret,char* gearalias) {
505508
}
506509

507510
int MicroGear::init(char* gearkey,char* gearsecret,char* gearalias, char* scope) {
508-
//this->gearid = gearkey;
509511
this->gearkey = gearkey;
510512
this->gearsecret = gearsecret;
511513
this->gearalias = gearalias;

MicroGear.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#define MINBACKOFFTIME 10
2525
#define MAXBACKOFFTIME 10000
2626
#define MAXENDPOINTLENGTH 200
27-
#define MAXGEARIDSIZE 64
2827
#define MAXTOPICSIZE 128
2928

3029
#define KEYSIZE 16
@@ -70,12 +69,9 @@ class MicroGear {
7069
char* gearsecret;
7170
char* gearalias;
7271
char* scope;
73-
char* app_topic;
74-
char* group_topic;
7572
char* token;
7673
char* tokensecret;
7774
char* endpoint;
78-
char gearid[MAXGEARIDSIZE];
7975
char mqtt_client_type;
8076
unsigned long bootts;
8177
int eepromoffset;
@@ -100,9 +96,10 @@ class MicroGear {
10096
MicroGear(Client&);
10197
void setName(char*);
10298
void setAlias(char*);
103-
boolean connect(char*);
104-
boolean connected();
99+
bool connect(char*);
100+
bool connected();
105101
void publish(char*, char*);
102+
void publish(char*, char*, bool);
106103
void subscribe(char*);
107104
void unsubscribe(char*);
108105
void chat(char*, char*);

0 commit comments

Comments
 (0)