Skip to content

Commit 325a26f

Browse files
committed
fix authen header problem
1 parent 673b3fb commit 325a26f

File tree

4 files changed

+44
-39
lines changed

4 files changed

+44
-39
lines changed

AuthClient.cpp

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,14 @@ bool AuthClient::readln(char *buffer, size_t buflen) {
8686
}
8787
return true;
8888
}
89-
if (pos < buflen)
90-
buffer[pos++] = byte;
89+
90+
if (byte != 255) {
91+
if (pos < buflen) buffer[pos++] = byte;
92+
}
93+
else{
94+
buffer[pos++] = '\0';
95+
return true;
96+
}
9197
}
9298
}
9399
return false;
@@ -315,41 +321,43 @@ int AuthClient::getGearToken(char mode, char* token, char* tokensecret, char* en
315321
while(true) {
316322
if (readln(buff, (size_t)MAXHEADERLINESIZE)) {
317323

318-
#ifdef DEBUG_H
319-
Serial.println(buff);
320-
#endif
321-
322-
if (pline<2) {
324+
#ifdef DEBUG_H
325+
Serial.println(buff);
326+
#endif
327+
if (httpstatus==0) {
323328
if (strncmp(buff,"HTTP",4)==0) {
324329
buff[12] = '\0';
325330
httpstatus = atoi(buff+9);
326331
}
327332
}
328333
else {
329-
char *p;
330-
char *s, *t;
331-
332-
int last = 0;
333-
p = buff;
334-
while (*p != '\0') {
335-
s = p;
336-
while (*s!='=' && *s!='\0' && *s!='&') s++; /* seek for = */
337-
t= s;
338-
while (*t!='\0' && *t!='&') t++; /* seek for & */
339-
*s = '\0';
340-
if (*t == '\0') last = 1;
341-
*t = '\0';
342-
343-
if (strcmp(p,"oauth_token")==0) strcpy(token,s+1);
344-
else if (strcmp(p,"oauth_token_secret")==0) strcpy(tokensecret,s+1);
345-
else if (strcmp(p,"endpoint")==0) strcpy(endpoint,s+1);
346-
delay(400);
347-
348-
if (!last) p = t+1; else break;
349-
}
350-
return httpstatus;
334+
if (strlen(buff) < 1) {
335+
readln(buff, (size_t)MAXHEADERLINESIZE);
336+
char *p;
337+
char *s, *t;
338+
int last = 0;
339+
p = buff;
340+
while (*p != '\0') {
341+
s = p;
342+
while (*s!='=' && *s!='\0' && *s!='&') s++; // seek for =
343+
t= s;
344+
while (*t!='\0' && *t!='&') t++; // seek for &
345+
*s = '\0';
346+
if (*t == '\0') last = 1;
347+
*t = '\0';
348+
if (strcmp(p,"oauth_token")==0) strcpy(token,s+1);
349+
else if (strcmp(p,"oauth_token_secret")==0) strcpy(tokensecret,s+1);
350+
else if (strcmp(p,"endpoint")==0) strcpy(endpoint,s+1);
351+
delay(200);
352+
if (!last) p = t+1; else break;
353+
}
354+
return httpstatus;
355+
}
351356
}
352-
if (strlen(buff)<6) pline++;
357+
358+
359+
360+
353361
}
354362
else {
355363
return 0;

AuthClient.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
#include "Client.h"
55
#include "SHA1.h"
6+
//#include "debug.h"
67

7-
#define GEARAUTHHOST "gearauth.netpie.io"
8+
#define GEARAUTHHOST "ga.netpie.io"
89
#define GEARAUTHPORT 8080
910
#define VERIFIER "1234"
1011
#define TOKENSIZE 16

MicroGear.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ void (* cb_present)(char*, uint8_t*,unsigned int);
66
void (* cb_absent)(char*, uint8_t*,unsigned int);
77

88
void msgCallback(char* topic, uint8_t* payload, unsigned int length) {
9-
#ifdef DEBUG_H
10-
Serial.println("Incoming msgcallback message-->");
11-
#endif
12-
139
/* remove /appid/ */
1410
char* rtopic = topic+topicprefixlen+1;
1511

MicroGear.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/*
2-
MicroGear Arduino library
2+
MicroGear-Arduino-ESP8255 library
33
NetPIE Project
44
http://netpie.io
5-
65
*/
76

87
#ifndef MICROGEAR_H
@@ -16,11 +15,12 @@
1615
#include <EEPROM.h>
1716
#include "SHA1.h"
1817
#include "AuthClient.h"
18+
//#include "debug.h"
1919

20-
#define GEARTIMEADDRESS "gearauth.netpie.io"
20+
#define GEARTIMEADDRESS "ga.netpie.io"
2121
#define GEARTIMEPORT 8080
2222

23-
#define CLIENTTYPE "arduino.v1"
23+
#define CLIENTTYPE "esp1"
2424

2525
#define MINBACKOFFTIME 10
2626
#define MAXBACKOFFTIME 10000

0 commit comments

Comments
 (0)