Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pushOwner #18

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 22 additions & 29 deletions MicroGear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,34 +666,6 @@ bool MicroGear::publish(char* topic, String message, bool retained) {
return publish(topic, buff, retained);
}

bool MicroGear::publish(char* topic, String message, String apikey) {
char buff[MAXBUFFSIZE];
message.toCharArray(buff,MAXBUFFSIZE-1);

char top[MAXTOPICSIZE] = "";
strcat(top,topic);
if(apikey!=""){
strcat(top,"/");
char buffapikey[MAXBUFFSIZE];
apikey.toCharArray(buffapikey,MAXBUFFSIZE);
strcat(top,buffapikey);
}
return publish(top, buff);
}

bool MicroGear::publish(char* topic, String message, char* apikey) {
char buff[MAXBUFFSIZE];
message.toCharArray(buff,MAXBUFFSIZE-1);

char top[MAXTOPICSIZE] = "";
strcat(top,topic);
if(apikey!=""){
strcat(top,"/");
strcat(top,apikey);
}
return publish(top, buff);
}

bool MicroGear::writeFeed(char* feedname, char *data, char* apikey) {
char buff[MAXBUFFSIZE] = "/@writefeed/";

Expand All @@ -712,14 +684,35 @@ bool MicroGear::writeFeed(char* feedname, char *data) {
bool MicroGear::writeFeed(char* feedname, String data, char* apikey) {
char buff[MAXBUFFSIZE];
data.toCharArray(buff,MAXBUFFSIZE-1);

return writeFeed(feedname, buff, apikey);
}

bool MicroGear::writeFeed(char* feedname, String data) {
return writeFeed(feedname, data, NULL);
}

bool MicroGear::pushOwner(char *message) {
char buff[MAXBUFFSIZE] = "/@push/owner";
return publish(buff, message);
}

bool MicroGear::pushOwner(double message) {
char buff[MAXBUFFSIZE] = "/@push/owner";
return publish(buff, message);
}

bool MicroGear::pushOwner(int message) {
char buff[MAXBUFFSIZE] = "/@push/owner";
return publish(buff, message);
}

bool MicroGear::pushOwner(String message) {
char top[MAXBUFFSIZE] = "/@push/owner";
char buff[MAXBUFFSIZE];
message.toCharArray(buff,MAXBUFFSIZE-1);
return publish(top, message);
}

/*
setName() is deprecated
*/
Expand Down
5 changes: 5 additions & 0 deletions MicroGear.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ class MicroGear {
bool writeFeed(char*, String);
bool writeFeed(char*, String, char*);

bool pushOwner(char*);
bool pushOwner(double);
bool pushOwner(int);
bool pushOwner(String);

bool chat(char*, char*);
bool chat(char*, int);
bool chat(char*, double);
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,20 @@ To send a revoke token control message to NETPIE and delete the token from cache

---

**void microgear.pushOwner (char *message)**<br/>
**void microgear.pushOwner (double *message)**<br/>
**void microgear.pushOwner (int *message)**<br/>
**void microgear.pushOwner (String *message)**<br/>
push notification to NETPIE mobile application

**arguments**
* *message* - message to be sent

```js
microgear.pushOwner("temp:25.7");
```
---

**void MicroGear::loop()**

This method has to be called regularly in the arduino loop() function to keep connection alive and to handle incoming messages.
12 changes: 12 additions & 0 deletions README.th.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,19 @@ microgear.writeFeed("homesensor","{temp:25.7,humid:62.8,light:8.5}");
ส่งคำสั่ง revoke token ไปยัง netpie และลบ token ออกจาก cache ส่งผลให้ microgear ต้องขอ token ใหม่ในการเชื่อมต่อครั้งต่อไป

---
**void microgear.pushOwner (char *message)**<br/>
**void microgear.pushOwner (double *message)**<br/>
**void microgear.pushOwner (int *message)**<br/>
**void microgear.pushOwner (String *message)**<br/>
ส่งการแจ้งเตือน ไปยัง NETPIE mobile application

**arguments**
* *message* - ข้อความ

```js
microgear.pushOwner("temp:25.7");
```
---
**void MicroGear::loop()**

method นี้ควรถูกเรียกใน arduino loop() เป็นระยะๆ เพื่อที่ microgear library จะได้ keep alive connection alive และจัดการกับ message ที่เข้ามา