Skip to content

Commit 21df5e4

Browse files
committed
Initial Support for WifiEsp Library(using ESP8266 with AT Commands from Arduino).
1 parent bf64107 commit 21df5e4

File tree

7 files changed

+102
-7
lines changed

7 files changed

+102
-7
lines changed

examples/ESP8266AT/ESP8266AT.ino

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Can be installed from Library Manager or https://github.com/bportaluri/WiFiEsp
2+
#include <WiFiEsp.h>
3+
#include <ThingerESP8266AT.h>
4+
5+
#define USERNAME "your_user_name"
6+
#define DEVICE_ID "your_device_id"
7+
#define DEVICE_CREDENTIAL "your_device_credential"
8+
9+
#define SSID "your_wifi_ssid"
10+
#define SSID_PASSWORD "your_wifi_ssid_password"
11+
12+
#define ARDUINO_LED 13
13+
14+
ThingerESP8266AT thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
15+
16+
void setup() {
17+
pinMode(ARDUINO_LED, OUTPUT);
18+
19+
thing.add_wifi(SSID, SSID_PASSWORD);
20+
21+
// digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc)
22+
thing["led"] << digitalPin(ARDUINO_LED);
23+
24+
// resource output example (i.e. reading a sensor value)
25+
thing["millis"] >> outputValue(millis());
26+
27+
// more details at http://docs.thinger.io/arduino/
28+
}
29+
30+
void loop() {
31+
thing.handle();
32+
}

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.5.2
2+
version=2.5.3
33
author=Alvaro Luis Bustamante <[email protected]>
44
maintainer=Thinger.io <[email protected]>
55
sentence=Arduino library for the Thinger.io Internet of Things Platform.

src/ThingerClient.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,14 @@ bool inverted_digital_pin(protoson::pson& in, int pin, bool& current_state){
343343
#endif
344344

345345
void analog_pin(protoson::pson& in, int pin){
346-
if(in.is_empty()) in = analogRead(pin);
347-
else analogWrite(pin, in);
346+
static int current = in;
347+
if(in.is_empty()){
348+
in = current;
349+
}
350+
else{
351+
current = in;
352+
analogWrite(pin, current);
353+
}
348354
}
349355

350356
/**

src/ThingerESP8266.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#ifndef _DISABLE_TLS_
3030
class ThingerESP8266 : public ThingerWifiClient<WiFiClientSecure>{
3131
#else
32-
class ThingerESP8266 : public ThingerWifiClient<>{
32+
class ThingerESP8266 : public ThingerWifiClient<WiFiClient>{
3333
#endif
3434

3535
public:

src/ThingerESP8266AT.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// The MIT License (MIT)
2+
//
3+
// Copyright (c) 2016 THINK BIG LABS SL
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_ESP8266_AT_H
25+
#define THINGER_ESP8266_AT_H
26+
27+
#include "ThingerWifi.h"
28+
29+
class ThingerESP8266AT : public ThingerWifiClient<WiFiEspClient>{
30+
31+
public:
32+
ThingerESP8266AT(const char* user, const char* device, const char* device_credential) :
33+
ThingerWifiClient(user, device, device_credential)
34+
{}
35+
36+
~ThingerESP8266AT(){
37+
38+
}
39+
40+
#ifndef _DISABLE_TLS_
41+
protected:
42+
virtual bool connect_socket(){
43+
return client_.connectSSL(THINGER_SERVER, THINGER_SSL_PORT);
44+
}
45+
46+
virtual bool secure_connection(){
47+
return true;
48+
}
49+
#endif
50+
51+
};
52+
53+
#endif

src/ThingerWifi.h

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

2727
#include "ThingerClient.h"
2828

29-
template <class Client = WiFiClient>
29+
template <class Client>
3030
class ThingerWifiClient : public ThingerClient {
3131

3232
public:
@@ -41,7 +41,7 @@ class ThingerWifiClient : public ThingerClient {
4141
protected:
4242

4343
virtual bool network_connected(){
44-
return WiFi.status() == WL_CONNECTED && !(WiFi.localIP() == INADDR_NONE);
44+
return WiFi.status() == WL_CONNECTED && WiFi.localIP() != INADDR_NONE;
4545
}
4646

4747
virtual bool connect_network(){
@@ -81,6 +81,6 @@ class ThingerWifiClient : public ThingerClient {
8181
const char* wifi_password_;
8282
};
8383

84-
#define ThingerWifi ThingerWifiClient<>
84+
#define ThingerWifi ThingerWifiClient<WiFiClient>
8585

8686
#endif

src/thinger/thinger.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ namespace thinger{
154154
return send_message(message);
155155
}
156156

157+
bool call_endpoint(const char* endpoint_name, const char* resource_name){
158+
return call_endpoint(endpoint_name, resources_[resource_name]);
159+
}
160+
157161
/**
158162
* Stream the given resource. This resource should be previously requested by an external process.
159163
* Otherwise, the resource will not be streamed as nothing will be listening for it.

0 commit comments

Comments
 (0)