Skip to content

Commit 9f7dbfa

Browse files
Himura2lasky3d
authored andcommitted
Add ESP32 support (#9)
1 parent 7eebfae commit 9f7dbfa

File tree

6 files changed

+83
-67
lines changed

6 files changed

+83
-67
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ python:
33
- "2.7"
44

55
env:
6-
- PLATFORMIO_CI_SRC=examples/ESP8266/ESP8266.ino
6+
- PLATFORMIO_CI_SRC=examples/control/control.ino
77

88
install:
99
- pip install -U platformio
@@ -16,7 +16,7 @@ install:
1616
- platformio lib -g install 64 89
1717

1818
script:
19-
- platformio ci --lib="." --board=nodemcuv2
19+
- platformio ci --lib="." --board=nodemcuv2 --board=esp32dev
2020

2121
notifications:
2222
slack:

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017 Cloud4RPi
3+
Copyright (c) 2017-2019 Cloud4RPi
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 58 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ Cloud4RPi Client Library for [Arduino](https://www.arduino.cc/) Framework
44

55
The package provides a client library that simplifies connecting Internet-enabled Arduino devices to the Cloud4RPi service.
66

7-
Currently supported hardware:
7+
Supported hardware:
88

99
* [ESP8266](https://en.wikipedia.org/wiki/ESP8266) boards (like [NodeMCU Dev Kit](http://www.nodemcu.com/index_en.html#fr_54747661d775ef1a3600009e) and others).
10+
* [ESP32](https://en.wikipedia.org/wiki/ESP32) boards (like [ESP32-DevKitC](https://www.espressif.com/en/products/hardware/esp32-devkitc/overview) and others).
1011

1112
Supported ecosystems:
1213

@@ -21,62 +22,68 @@ The [Cloud4RPi library](http://platformio.org/lib/show/2045/cloud4rpi-esp-arduin
2122

2223
1. Create a new PlatformIO project for your board as described in the PlatformIO documentation ([Visual Studio Code](http://docs.platformio.org/en/latest/ide/vscode.html#id3), [Atom](http://docs.platformio.org/en/latest/ide/atom.html#setting-up-the-project))
2324
2. Open your `platformio.ini` and add the following lines to the end:
24-
```
25-
lib_deps =
26-
cloud4rpi-esp-arduino
27-
28-
build_flags=
29-
; Required for PubSub library
30-
-D MQTT_MAX_PACKET_SIZE=1024
31-
-D MQTT_MAX_TRANSFER_SIZE=128
32-
; Enables the verbose output to Serial
33-
-D CLOUD4RPI_DEBUG=1
34-
```
35-
4. Save the `platformio.ini` file and open the `src\main.cpp` file.
36-
5. Copy-paste the [sample code](examples/ESP8266/ESP8266.ino) into it. <!-- common part begins here -->
37-
4. [Log in to your Cloud4RPi account](https://cloud4rpi.io/signin) or [create a new one](https://cloud4rpi.io/register).
38-
5. Copy [your device](https://cloud4rpi.io/devices)'s **Device Token**. You can create a device on the [Devices](https://cloud4rpi.io/devices) page and copy its **Device Token** if you do not have one.
39-
6. Replace the `__YOUR_DEVICE_TOKEN__` string with your device token.
40-
7. Replace the `__SSID__` and `__PASSWORD__` strings with your Wi-Fi network data.
41-
7. If you know the pin number connected to an LED on your board, replace the `BUILTIN_LED` constant with it.
42-
6. Hit the `Build` button and wait until the compilation is done.
43-
8. Connect the board in the flashing mode and hit the `Upload` button.
44-
9. Once flashing is complete, open `Serial Monitor` and watch the sample code's output.
45-
8. Notice that the [device](https://cloud4rpi.io/devices) went online and started sending data.
46-
9. Go to the [Control Panels](https://cloud4rpi.io/control-panels/) page and add a new control panel.
47-
10. Add a new **Chart** widget and bind it to the `Uptime` variable.
48-
10. Add a new **Switch** widget and bind it to the `LED On` variable.
49-
11. Add a new **Text** widget and bind it to the `STATUS` variable. Configure different colors for the **"IDLE"**, **"RING"** and **"BOOM!"** strings.
25+
```
26+
lib_deps =
27+
cloud4rpi-esp-arduino
28+
29+
build_flags=
30+
; Required for PubSub library
31+
-D MQTT_MAX_PACKET_SIZE=1024
32+
-D MQTT_MAX_TRANSFER_SIZE=128
33+
; Enables the verbose output to Serial
34+
-D CLOUD4RPI_DEBUG=1
35+
```
36+
3. Save the `platformio.ini` file and open the `src\main.cpp` file.
37+
4. Copy-paste the sample code ([ESP8266](https://github.com/cloud4rpi/cloud4rpi-esp-arduino/blob/master/examples/ESP8266/ESP8266.ino), [ESP32](https://github.com/cloud4rpi/cloud4rpi-esp-arduino/blob/master/examples/ESP32/ESP32.ino)). <!-- common part begins here -->
38+
5. [Log in to your Cloud4RPi account](https://cloud4rpi.io/signin) or [create a new one](https://cloud4rpi.io/register).
39+
6. Copy [your device](https://cloud4rpi.io/devices)'s **Device Token**. You can create a device on the [Devices](https://cloud4rpi.io/devices) page and copy its **Device Token** if you do not have one.
40+
7. Replace the `__YOUR_DEVICE_TOKEN__` string with your device token.
41+
8. Replace the `__SSID__` and `__PASSWORD__` strings with your Wi-Fi network data.
42+
9. If the `LED_BUILTIN` constant is not defined in your board's library, change this constant to the LED's pin number (for example, `2`).
43+
10. Hit the `Build` button and wait until the compilation is completed.
44+
11. Hit the `Upload` button.
45+
11. If the upload fails, try to start the board in the flashing mode (connect the power supply with the GPIO0 pin connected to GND) and try uploading again.
46+
12. Once flashing is complete, open `Serial Monitor` to monitor the device's status.
47+
13. Notice that the device on the [Devices page](https://cloud4rpi.io/devices) went online and started sending data.
48+
14. Go to the [Control Panels](https://cloud4rpi.io/control-panels/) page and add a new control panel.
49+
15. Add a new **Number** widget and bind it to the `Uptime` variable.
50+
16. Add a new **Switch** widget and bind it to the `LED On` variable.
51+
17. Add a new **Text** widget and bind it to the `State` variable. Configure different colors for the **"IDLE"**, **"RING"** and **"BOOM!"** strings.
52+
18. Add a new **Slider** widget and bind it to the `DesiredTemp` variable, set its minimum value to 10 and maximum value to 30.
53+
19. Add a new **Gauge** widget and bind it to the `DesiredTemp` variable, set its minimum value to 10 and maximum value to 30.
5054

5155

5256
## Arduino
5357

54-
1. Create a new Arduino sketch and select your board in the **Tools** | **Board** menu. [Add ESP8266 support](https://github.com/esp8266/Arduino) if required.
55-
2. Install the Cloud4RPi library from the **Library Manager**: open the **Sketch** | **Include Library** | **Manage Libraries** menu, enter `cloud4rpi` into the search field and install the **cloud4rpi-esp-arduino** package.
56-
3. Install **ArduinoJson** and **PubSubClient** libraries. You should do it manually because the **Library Manager** does not manage package dependencies.
58+
1. Open **Arduino** and select your board in the **Tools** | **Board** menu. Add [ESP8266](https://github.com/esp8266/Arduino#installing-with-boards-manager) or [ESP32](https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/boards_manager.md) support if it is not added yet.
59+
2. Install the Cloud4RPi library from the **Library Manager**. To do this, open the **Sketch** | **Include Library** | **Manage Libraries** menu, enter `cloud4rpi` into the search field and install the **cloud4rpi-esp-arduino** package.
60+
3. Install the dependencies: **ArduinoJson** and **PubSubClient** libraries.
5761
4. Configure the installed libraries:
5862
1. Open the `%HOMEPATH%\Documents\Arduino\libraries\PubSubClient\src\PubSubClient.h` (`~/Documents/Arduino/libraries/PubSubClient/src/PubSubClient.h` on Mac) file with any text editor (for instance, [VS Code](https://code.visualstudio.com)).
59-
2. Add the following define statements at the beginning:
60-
```c
61-
#define MQTT_MAX_PACKET_SIZE 1024
62-
#define MQTT_MAX_TRANSFER_SIZE 128
63-
```
64-
3. Open the `%HOMEPATH%\Documents\Arduino\libraries\cloud4rpi-esp-arduino\src\Cloud4RPi.h` (`~/Documents/Arduino/libraries/cloud4rpi-esp-arduino/src/Cloud4RPi.h` on Mac) file and enable verbose output by adding the `#define CLOUD4RPI_DEBUG 1` line at the beginning.
65-
5. Open the sample code using the **File** | **Examples** | **cloud4rpi-esp-arduino** | **ESP8266** menu item. Restart Arduino IDE if this item did not appear. <!-- common part begins here -->
66-
4. [Log in to your Cloud4RPi account](https://cloud4rpi.io/signin) or [create a new one](https://cloud4rpi.io/register).
67-
5. Copy [your device](https://cloud4rpi.io/devices)'s **Device Token**. You can create a device on the [Devices](https://cloud4rpi.io/devices) page and copy its **Device Token** if you do not have one.
68-
6. Replace the `__YOUR_DEVICE_TOKEN__` string with your device token.
69-
7. Replace the `__SSID__` and `__PASSWORD__` strings with your Wi-Fi network data.
70-
7. If you know the pin number connected to an LED on your board, replace the `BUILTIN_LED` constant with it.
71-
6. Hit the `Verify` button and wait until the compilation is done.
72-
8. Connect the board in the flashing mode and hit the `Upload` button.
73-
9. Once flashing is complete, open `Serial Monitor` and watch the sample code's output.
74-
8. Notice that the [device](https://cloud4rpi.io/devices) went online and started sending data.
75-
9. Go to the [Control Panels](https://cloud4rpi.io/control-panels/) page and add a new control panel.
76-
10. Add a new **Chart** widget and bind it to the `Uptime` variable.
77-
10. Add a new **Switch** widget and bind it to the `LED On` variable.
78-
11. Add a new **Text** widget and bind it to the `STATUS` variable. Configure different colors for the **"IDLE"**, **"RING"** and **"BOOM!"** strings.
79-
63+
2. Add the following define directives at the beginning:
64+
```c
65+
#define MQTT_MAX_PACKET_SIZE 1024
66+
#define MQTT_MAX_TRANSFER_SIZE 128
67+
```
68+
3. [Optional] Open the `%HOMEPATH%\Documents\Arduino\libraries\cloud4rpi-esp-arduino\src\Cloud4RPi.h` (`~/Documents/Arduino/libraries/cloud4rpi-esp-arduino/src/Cloud4RPi.h` on Mac) file and add the `#define CLOUD4RPI_DEBUG 1` line at the beginning to enable verbose output.
69+
5. Use the **File** | **Examples** | **cloud4rpi-esp-arduino** menu item to open the sample code. Restart Arduino IDE if this item does not appear.
70+
5. Select the **ESP32 Dev Module** board in **Tools** menu.
71+
6. [Log in to your Cloud4RPi account](https://cloud4rpi.io/signin) or [create a new one](https://cloud4rpi.io/register).
72+
7. Copy [your device](https://cloud4rpi.io/devices)'s **Device Token**. You can create a device on the [Devices](https://cloud4rpi.io/devices) page and copy its **Device Token** if you do not have one.
73+
8. Replace the `__YOUR_DEVICE_TOKEN__` string with your device token.
74+
9. Replace the `__SSID__` and `__PASSWORD__` strings with your Wi-Fi network data.
75+
10. If the `LED_BUILTIN` constant is not defined in your board's library, change this constant to the LED's pin number (for example, `2`).
76+
11. Hit the `Build` button and wait until the compilation is completed.
77+
12. Hit the `Upload` button.
78+
13. If the upload fails, try to start the board in the flashing mode (connect the power supply with the GPIO0 pin connected to GND) and try uploading again.
79+
13. Once flashing is complete, open `Serial Monitor` to monitor the device's status.
80+
14. Notice that the device on the [Devices page](https://cloud4rpi.io/devices) went online and started sending data.
81+
15. Go to the [Control Panels](https://cloud4rpi.io/control-panels/) page and add a new control panel.
82+
16. Add a new **Number** widget and bind it to the `Uptime` variable.
83+
17. Add a new **Switch** widget and bind it to the `LED On` variable.
84+
18. Add a new **Text** widget and bind it to the `State` variable. Configure different colors for the **"IDLE"**, **"RING"** and **"BOOM!"** strings.
85+
19. Add a new **Slider** widget and bind it to the `DesiredTemp` variable, set its minimum value to 10 and maximum value to 30.
86+
20. Add a new **Gauge** widget and bind it to the `DesiredTemp` variable, set its minimum value to 10 and maximum value to 30.
8087

8188

8289
## See Also
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
#include <ESP8266WiFi.h>
1+
#ifdef ESP8266
2+
#include <ESP8266WiFi.h>
3+
#else
4+
#include <WiFi.h>
5+
#endif
26
#include <Cloud4RPi.h>
37

48
const String deviceToken = "__YOUR_DEVICE_TOKEN__";
59
char wifiSSID[] = "__SSID__";
610
char wifiPassword[] = "__PASSWORD__";
711

8-
int ledPin = BUILTIN_LED;
12+
#define SERIAL_BAUD_RATE 9600 // bits per second
13+
14+
#ifndef LED_BUILTIN
15+
#define LED_BUILTIN 2
16+
#endif
917

1018
const int dataSendingInterval = 30000; // milliseconds
1119
const int diagSendingInterval = 60000; // milliseconds
@@ -27,11 +35,11 @@ bool onLEDCommand(bool value);
2735
double onDesiredTempCommand(double value);
2836

2937
void setup() {
30-
Serial.begin(9600);
38+
Serial.begin(SERIAL_BAUD_RATE);
3139
ensureWiFiConnection();
3240

33-
pinMode(ledPin, OUTPUT);
34-
digitalWrite(ledPin, HIGH);
41+
pinMode(LED_BUILTIN, OUTPUT);
42+
digitalWrite(LED_BUILTIN, LOW);
3543

3644
c4r.begin(wifiClient);
3745
c4r.printLogo();
@@ -114,8 +122,8 @@ void ensureWiFiConnection() {
114122
bool onLEDCommand(bool value) {
115123
Serial.print("LED state set to ");
116124
Serial.println(value);
117-
digitalWrite(ledPin, value ? LOW : HIGH);
118-
return !digitalRead(ledPin);
125+
digitalWrite(LED_BUILTIN, value ? HIGH : LOW);
126+
return digitalRead(LED_BUILTIN);
119127
}
120128

121129
double onDesiredTempCommand(double value) {

library.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "cloud4rpi-esp-arduino",
33
"keywords": "arduino, nodemcu, esp8266, esp32, mqtt, iot, cloud",
4-
"description": "Cloud4RRi client library for ESP8266 based boards and Arduino language",
4+
"description": "Cloud4RPi client library for ESP8266 and ESP32 based boards",
55
"repository":
66
{
77
"type": "git",
@@ -23,10 +23,11 @@
2323
"build": {
2424
"flags": "-DMQTT_MAX_PACKET_SIZE=1024 -DMQTT_MAX_TRANSFER_SIZE=128"
2525
},
26-
"version": "0.0.7",
26+
"version": "0.0.8",
2727
"examples": "examples/*/*.ino",
2828
"frameworks": "arduino",
2929
"platforms": [
30-
"espressif8266"
30+
"espressif8266",
31+
"espressif32"
3132
]
3233
}

library.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name=cloud4rpi-esp-arduino
2-
version=0.0.7
2+
version=0.0.8
33
author=Cloud4RPi <[email protected]>
44
maintainer=Cloud4RPi <[email protected]>
55
sentence=Connect a board to the Cloud4RPi control panel using MQTT - https://cloud4rpi.io.
6-
paragraph=Cloud4RRi client library for ESP8266 based boards and Arduino language.
6+
paragraph=Cloud4RPi client library for ESP8266 and ESP32 based boards. Dependencies: ArduinoJson, PubSubClient.
77
category=Communication
88
url=https://github.com/cloud4rpi/cloud4rpi-esp-arduino
9-
architectures=esp8266
9+
architectures=esp8266,esp32
1010
includes=Cloud4RPi.h

0 commit comments

Comments
 (0)