Skip to content

Commit bdab18a

Browse files
committed
Add support for LinkItOneGRPS.
Improved syntactic sugar for inputValue. Now it is not required to pass a callback if it is not necessary.
1 parent 2192062 commit bdab18a

File tree

6 files changed

+130
-7
lines changed

6 files changed

+130
-7
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <LGPRS.h>
2+
#include <LGPRSClient.h>
3+
#include <ThingerLinkItOneGPRS.h>
4+
5+
#define USERNAME "your_user_name"
6+
#define DEVICE_ID "your_device_id"
7+
#define DEVICE_CREDENTIAL "your_device_credential"
8+
9+
ThingerLinkItOneGPRS thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
10+
11+
void setup() {
12+
// SIM unlock using a PIN is not supported by LinkItOne. Remove PIN from SIM before use.
13+
14+
// Set your GPRS APN if it is not provided automatically by your SIM
15+
//thing.set_apn("orangeworld", "orange", "orange");
16+
17+
pinMode(2, OUTPUT);
18+
19+
// pin control example (i.e. turning on/off a light, a relay, etc)
20+
thing["led"] << digitalPin(2);
21+
22+
// resource output example (i.e. reading a sensor value, a variable, etc)
23+
thing["millis"] >> outputValue(millis());
24+
25+
// more details at http://docs.thinger.io/arduino/
26+
}
27+
28+
void loop() {
29+
thing.handle();
30+
}

examples/LinkItOne/LinkItOne.ino renamed to examples/LinkItOneWifi/LinkItOneWifi.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include <LTask.h>
22
#include <LWiFi.h>
33
#include <LWiFiClient.h>
4-
#include <ThingerLinkItOne.h>
4+
#include <ThingerLinkItOneWifi.h>
55

6-
ThingerLinkItOne thing("user_id", "device_id", "device_credential");
6+
ThingerLinkItOneWifi thing("user_id", "device_id", "device_credential");
77

88
void setup() {
99
thing.add_wifi("SSID", "SSID_Password");

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=thinger.io
2-
version=2.2.0
2+
version=2.3.0
33
author=Alvaro Luis Bustamante <[email protected]>
44
maintainer=Thinger.io <[email protected]>
55
sentence=Arduino library for the thinger.io IoT platform.

src/ThingerClient.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,13 @@ void analog_pin(protoson::pson& in, int pin){
282282
#define digitalPin(PIN) [](pson& in){ digital_pin(in, PIN);}
283283
#define invertedDigitalPin(PIN) [](pson& in){ inverted_digital_pin(in, PIN);}
284284
#define analogPin(PIN) [](pson& in){ analog_pin(in, PIN);}
285-
#define inputValue(value, callback) [](pson& in){ if(in.is_empty()){ in = value; } else{ value = in; callback; } }
286285
#define outputValue(value) [](pson& out){ out = value; }
287286
#define servo(servo) [](pson& in){ if(in.is_empty()) in = (int)servo.read(); else servo.write((int)in); }
288-
287+
#define inputValue_1(value) [](pson& in){ if(in.is_empty()){ in = value; } else{ value = in; } }
288+
#define inputValue_2(value, callback) [](pson& in){ if(in.is_empty()){ in = value; } else{ value = in; callback; } }
289+
#define inputValue_X(x, value, callback, FUNC, ...) FUNC
290+
#define inputValue(...) inputValue_X(,##__VA_ARGS__,\
291+
inputValue_2(__VA_ARGS__),\
292+
inputValue_1(__VA_ARGS__)\
293+
)
289294
#endif

src/ThingerLinkItOneGPRS.h

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// The MIT License (MIT)
2+
//
3+
// Copyright (c) 2016 THINGER LTD
4+
// Author: [email protected] (Alvaro Luis Bustamante)
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in
14+
// all copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
// THE SOFTWARE.
23+
24+
#ifndef THINGER_LINKITONE_H
25+
#define THINGER_LINKITONE_H
26+
27+
#include "ThingerClient.h"
28+
29+
class ThingerLinkItOneGPRS : public ThingerClient {
30+
31+
public:
32+
ThingerLinkItOneGPRS(const char* user, const char* device, const char* device_credential) :
33+
ThingerClient(client_, user, device, device_credential), connected_(false),
34+
apn_(NULL), user_(NULL), password_(NULL), pin_(NULL)
35+
{}
36+
37+
~ThingerLinkItOneGPRS(){
38+
}
39+
40+
protected:
41+
42+
virtual bool network_connected(){
43+
return connected_;
44+
}
45+
46+
virtual bool connect_network(){
47+
long gprs_timeout = millis();
48+
THINGER_DEBUG("NETWORK", "Connecting to GPRS...");
49+
while(!attachGPRS())
50+
{
51+
if (millis() - gprs_timeout > 30000) return false;
52+
delay(500);
53+
}
54+
connected_ = true;
55+
THINGER_DEBUG("NETWORK", "Connected to GPRS!");
56+
return connected_;
57+
}
58+
59+
public:
60+
void set_apn(const char* apn, const char* user=NULL, const char* password=NULL){
61+
apn_ = apn;
62+
user_ = user;
63+
password_ = password;
64+
}
65+
66+
void set_pin(const char* pin){
67+
pin_ = pin;
68+
}
69+
70+
private:
71+
bool connected_;
72+
LGPRSClient client_;
73+
const char* apn_;
74+
const char* user_;
75+
const char* password_;
76+
const char* pin_;
77+
78+
bool attachGPRS(){
79+
if(apn_!=NULL){
80+
return LGPRS.attachGPRS(apn_, user_, password_) == 1;
81+
}
82+
else{
83+
return LGPRS.attachGPRS() == 1;
84+
}
85+
}
86+
};
87+
88+
#endif

src/ThingerLinkItOne.h renamed to src/ThingerLinkItOneWifi.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626

2727
#include "ThingerClient.h"
2828

29-
class ThingerLinkItOne : public ThingerClient {
29+
class ThingerLinkItOneWifi : public ThingerClient {
3030

3131
public:
32-
ThingerLinkItOne(const char* user, const char* device, const char* device_credential) :
32+
ThingerLinkItOneWifi(const char* user, const char* device, const char* device_credential) :
3333
ThingerClient(client_, user, device, device_credential)
3434
{}
3535

0 commit comments

Comments
 (0)