Skip to content

Commit 8bf0243

Browse files
committed
Update README.md
1 parent afd6913 commit 8bf0243

File tree

1 file changed

+51
-55
lines changed

1 file changed

+51
-55
lines changed

README.md

Lines changed: 51 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ microgear-esp8266-arduino is a client library that is used to connect an ESP826
66
We have tested this library and found it compatible with (but not limited to) the following hardware
77
- ESP8266-01, 07, 12E, 12F
88
- NodeMCU v1, v2, V3
9+
- Espresso Lite v2.0
910

1011
## Installation
11-
* Download Arduino IDE 1.6.5 from https://www.arduino.cc/en/Main/Software
12+
* Download Arduino IDE 1.6.9 or later from https://www.arduino.cc/en/Main/Software
1213
* After installation, open Preferences
1314
* Enter `http://arduino.esp8266.com/stable/package_esp8266com_index.json`in the field Additional Board Manager URLs
1415
* Open Boards Manager menu Tools. Search for `esp8266` and click install
@@ -19,22 +20,16 @@ We have tested this library and found it compatible with (but not limited to) th
1920

2021
Usage Example
2122
```c++
22-
#include <AuthClient.h>
23-
#include <MicroGear.h>
24-
#include <MQTTClient.h>
25-
#include <SHA1.h>
26-
#include <Arduino.h>
2723
#include <ESP8266WiFi.h>
28-
#include <EEPROM.h>
2924
#include <MicroGear.h>
3025

3126
const char* ssid = <WIFI_SSID>;
3227
const char* password = <WIFI_KEY>;
3328

34-
#define APPID <APPID>
29+
#define APPID <APPID>
3530
#define KEY <APPKEY>
3631
#define SECRET <APPSECRET>
37-
#define ALIAS "mygear"
32+
#define ALIAS "esp8266"
3833

3934
WiFiClient client;
4035
AuthClient *authclient;
@@ -43,30 +38,31 @@ int timer = 0;
4338
MicroGear microgear(client);
4439

4540
void onMsghandler(char *topic, uint8_t* msg, unsigned int msglen) {
46-
Serial.print("Incoming message --> ");
47-
msg[msglen] = '\0';
48-
Serial.println((char *)msg);
41+
Serial.print("Incoming message --> ");
42+
msg[msglen] = '\0';
43+
Serial.println((char *)msg);
4944
}
5045

5146
void onFoundgear(char *attribute, uint8_t* msg, unsigned int msglen) {
52-
Serial.print("Found new member --> ");
53-
for (int i=0; i<msglen; i++)
54-
Serial.print((char)msg[i]);
55-
Serial.println();
47+
Serial.print("Found new member --> ");
48+
for (int i=0; i<msglen; i++)
49+
Serial.print((char)msg[i]);
50+
Serial.println();
5651
}
5752

5853
void onLostgear(char *attribute, uint8_t* msg, unsigned int msglen) {
59-
Serial.print("Lost member --> ");
60-
for (int i=0; i<msglen; i++)
61-
Serial.print((char)msg[i]);
62-
Serial.println();
54+
Serial.print("Lost member --> ");
55+
for (int i=0; i<msglen; i++)
56+
Serial.print((char)msg[i]);
57+
Serial.println();
6358
}
6459

6560
void onConnected(char *attribute, uint8_t* msg, unsigned int msglen) {
66-
Serial.println("Connected to NETPIE...");
67-
microgear.setAlias("mygear");
61+
Serial.println("Connected to NETPIE...");
62+
microgear.setName(ALIAS);
6863
}
6964

65+
7066
void setup() {
7167
/* Event listener */
7268
microgear.on(MESSAGE,onMsghandler);
@@ -79,56 +75,56 @@ void setup() {
7975

8076
if (WiFi.begin(ssid, password)) {
8177

82-
while (WiFi.status() != WL_CONNECTED) {
83-
delay(500);
84-
Serial.print(".");
85-
}
78+
while (WiFi.status() != WL_CONNECTED) {
79+
delay(500);
80+
Serial.print(".");
81+
}
82+
}
8683

87-
Serial.println("WiFi connected");
88-
Serial.println("IP address: ");
89-
Serial.println(WiFi.localIP());
84+
Serial.println("WiFi connected");
85+
Serial.println("IP address: ");
86+
Serial.println(WiFi.localIP());
9087

91-
//uncomment the line below if you want to reset token -->
92-
//microgear.resetToken();
93-
microgear.init(KEY, SECRET, ALIAS);
94-
microgear.connect(APPID);
95-
}
88+
//uncomment the line below if you want to reset token -->
89+
//microgear.resetToken();
90+
microgear.init(KEY,SECRET,ALIAS);
91+
microgear.connect(APPID);
9692
}
9793

9894
void loop() {
99-
if (microgear.connected()) {
100-
Serial.println("connected");
101-
microgear.loop();
102-
if (timer >= 1000) {
103-
Serial.println("Publish...");
104-
microgear.chat("mygear","Hello");
105-
timer = 0;
106-
}
107-
else timer += 100;
108-
}
109-
else {
110-
Serial.println("connection lost, reconnect...");
111-
if (timer >= 5000) {
112-
microgear.connect(APPID);
113-
timer = 0;
95+
if (microgear.connected()) {
96+
Serial.println("connected");
97+
microgear.loop();
98+
if (timer >= 1000) {
99+
Serial.println("Publish...");
100+
microgear.chat(ALIAS,"Hello");
101+
timer = 0;
102+
}
103+
else timer += 100;
114104
}
115-
else timer += 100;
116-
}
117-
delay(100);
105+
else {
106+
Serial.println("connection lost, reconnect...");
107+
if (timer >= 5000) {
108+
microgear.connect(APPID);
109+
timer = 0;
110+
}
111+
else timer += 100;
112+
}
113+
delay(100);
118114
}
119-
120115
```
121116
## Library Usage
122117
---
123118
**microgear.init (*key*, *secret*, *alias*)**
124119
125120
**arguments**
126-
* *gearkey* `string` - is used as a microgear identity.
127-
* *gearsecret* `string` comes in a pair with gearkey. The secret is used for authentication and integrity.
121+
* *key* `string` - is used as a microgear identity.
122+
* *secret* `string` comes in a pair with gearkey. The secret is used for authentication and integrity.
128123
* *alias* `string` - specifies the device alias.
129124
130125
```c++
131126
microGear.init("sXfqDcXHzbFXiLk",
132127
"DNonzg2ivwS8ceksykGntrfQjxbL98",
133128
"myplant");
134129
```
130+

0 commit comments

Comments
 (0)