Skip to content

Commit 6a31576

Browse files
committed
feat: update azure to release_2018_07_11
1 parent 9603a15 commit 6a31576

24 files changed

+196
-229
lines changed

README.md

+99-101
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,121 @@
1-
# a MQTT Demo that Connect ESP32 to Azure Cloud
1+
# A MQTT Demo that Connects ESP device to Azure Cloud
2+
23
# Table of Contents
3-
- [Introduction](#Introduction)
4-
- [Part 1: Prerequisites](#prerequisites)
5-
- [Part 2: Prepare your iothub](#prepare)
6-
- [Part 3: SDK and Tools Preparation](#tools_prepare)
7-
- [Part 4: Configuring and building](#config_build)
8-
- [Part 5: Result shows](#results)
9-
- [TroubleShoot](#troubleshoot)
10-
11-
<span id = "Introduction">Introduction</span>
12-
------------------------------
13-
###### ESP32 is one of gorgeous ioT device that can interface with other systems to provide Wi-Fi and Bluetooth functionality through the SPI / SDIO or I2C / UART interfaces.for more details, click https://espressif.com/en/products/hardware/esp32/overview
14-
###### Azure cloud is one of wonderful cloud that could collect data from lot device or push data to lot device,for more details, click https://www.azure.cn/home/features/iot-hub/
15-
**Aim:**
16-
##### This page would guide you connecting your device(ESP32 or lot device with ESP32) to Azure by MQTT protocol, and then send data to Azure,receive message from Azure.Main workflow:
17-
![ESP32workflow](https://github.com/ustccw/RepoForShareData/blob/master/Microsoft/AzureData/Photos/ESP32AzureWorkflow.png)https://github.com/ustccw/RepoForShareData/blob/master/Microsoft/AzureData/Photos/ESP32AzureWorkflow.png
18-
19-
<span id = "prerequisites">Part 1: Prerequisites</span>
20-
------------------------------
21-
- **ubuntu environment** for building your demo.
22-
- **ESP32 device** for running the demo.
23-
![ESP32 device](https://github.com/ustccw/RepoForShareData/blob/master/Microsoft/AzureData/Photos/ESP32-DevKitC.png)https://github.com/ustccw/RepoForShareData/blob/master/Microsoft/AzureData/Photos/ESP32-DevKitC.png
24-
25-
26-
27-
<span id = "prepare">Part 2: Prepare your iothub</span>
28-
------------------------------
29-
follow the guide: https://github.com/ustccw/RepoForShareData/blob/master/Microsoft/AzureData/start_Iothub.docx
30-
you would get an **iothub login connect string** like that:
4+
- [Introduction](#introduction)
5+
- [Preparation](#preparation)
6+
- [Configuring and Building](#configuring-and-building)
7+
- [Checking Result](#checking-result)
8+
- [Troubleshooting](#troubleshooting)
9+
10+
## Introduction
11+
<a name="Introduction"></a>
12+
13+
Espressif offers a wide range of fully-certified Wi-Fi & BT modules powered by our own advanced SoCs. For more details, see [Espressif Modules](https://www.espressif.com/en/products/hardware/modules).
14+
15+
Azure cloud is one of the most wonderful clouds that collects data from lots of devices or pushes data to IoT devices. For more details, see [Azure IoT Hub](https://www.azure.cn/en-us/home/features/iot-hub/).
16+
17+
This demo demonstrates how to firstly connect your device (ESP devices or IoT devices with ESP devices inside) to Azure, using MQTT protocol, then send data to Azure as well as receive message from Azure.
18+
19+
Main workflow:
20+
21+
![esp-azure-workflow](doc/_static/esp-azure-workflow.png)
22+
23+
## Preparation
24+
25+
<a name="preparation"></a>
26+
### 1. Hardware
27+
- An **ubuntu environment** should be set up to build your demo;
28+
- Any **[ESP device](https://www.espressif.com/en/products/hardware/modules)** can be used to run your demo.
29+
30+
### 2. Azure IoT Hub
31+
- [Get iothub connection string (primary key)](https://www.azure.cn/en-us/pricing/1rmb-trial-full/?form-type=identityauth) from the Azure IoT Hub, which will be used later. An example can be seen below:
32+
3133
```
3234
HostName=yourname-ms-lot-hub.azure-devices.cn;SharedAccessKeyName=iothubowner;SharedAccessKey=zMeLQ0JTlZXVcHBVOwRFVmlFtcCz+CtbDpUPBWexbIY=
3335
```
36+
- For step-by-step instructions, please click [here](doc/IoT_Suite.md).
3437

35-
<span id = "tools_prepare">Part 3: SDK and Tools Preparation</span>
36-
------------------------------
37-
#### 3.1 iothub-explorer install
38-
The iothub-explorer tool enables you to provision, monitor, and delete devices in your IoT hub. It runs on any operating system where Node.js is available.
39-
- Download and install Node.js from here. https://nodejs.org/en/
40-
- From a command line (Command Prompt on Windows, or Terminal on Mac OS X), execute the following:
41-
```
42-
npm install -g iothub-explorer
43-
```
44-
##### if success, you can get version information like:
45-
```shell
38+
### 3. iothub-explorer
39+
- Install [Node.js](https://nodejs.org/en/);
40+
- Install [iothub-explorer](https://www.npmjs.com/package/iothub-explorer) with command line `npm install -g iothub-explorer`.
41+
- If failed, please check [here](http://thinglabs.io/workshop/esp8266/setup-azure-iot-hub/) for more information.
42+
- If succeeded, please check the version information with the command lines below:
43+
```
4644
$ node -v
4745
v6.9.5
4846
$ iothub-explorer -V
4947
1.1.6
5048
```
51-
##### if failed,please click http://thinglabs.io/workshop/esp8266/setup-azure-iot-hub/
52-
53-
##### after finished:
54-
then you can use your iothub-explorer to manager your iot-device.click https://github.com/ustccw/RepoForShareData/blob/master/Microsoft/AzureData/iothub-explorer
5549

56-
login with: **iothub login connect string** that gets from Part 2
50+
After that, you should be able to use iothub-explorer to manage your iot-device.
5751

58-
then you can get one **device connect string** after you create one device like that:
59-
```
52+
### 4. Device Connection String
53+
- login with the **iothub connection string (primary key)** you got earlier with command lines;
54+
- create your device, and get a **device connection string**. An example can be seen:
55+
56+
```
6057
"HostName=esp-hub.azure-devices.net;DeviceId=yourdevice;SharedAccessKey=L7tvFTjFuVTQHtggEtv3rp+tKEJzQLLpDnO0edVGKCg=";
6158
```
62-
keep this **device connect string** in mind.
6359

64-
65-
#### 3.2 SDK get
66-
you can get AZURE-SDK from https://github.com/ustccw/AzureESP32
67-
this SDK can implement that connect ESP32 to Azure by MQTT protocol.
68-
you can get IDF-SDK from https://github.com/espressif/esp-idf
69-
this SDK can make ESP32 work well
70-
71-
#### 3.3 Compiler get
72-
follow the guide: http://esp-idf.readthedocs.io/en/latest/get-started/linux-setup.html
73-
60+
For detailed instruction, please click [Here](doc/iothub_explorer.md).
7461

75-
<span id = "config_build">Part 4: Configuring and building</span>
76-
------------------------------
77-
### 4.1 Update Variables
78-
[/examples/project_template/user/iothub_client_sample_mqtt.c](#)
62+
### 5. SDK
63+
- [AZURE-SDK](https://github.com/espressif/esp-azure) can be implemented to connect your ESP devices to Azure, using MQTT protocol.
64+
- Espressif SDK
65+
- For ESP32 platform: [ESP-IDF](https://github.com/espressif/esp-idf)
66+
- For ESP8266 platform: [ESP8266_RTOS_SDK](https://github.com/espressif/ESP8266_RTOS_SDK)
67+
68+
### 6. Compiler
69+
- For ESP32 platform: [Here](https://github.com/espressif/esp-idf/blob/master/README.md)
70+
- For ESP8266 platform: [Here](https://github.com/espressif/ESP8266_RTOS_SDK/blob/master/README.md)
71+
72+
## Configuring and Building
73+
74+
<a name="Configuring_and_Building"></a>
75+
76+
### 1. Updating variables
77+
- Replace the `connectionString` variable with your device connection string in [esp-azure/main/iothub_client_sample_mqtt.c](https://github.com/espressif/esp-azure/blob/master/main/iothub_client_sample_mqtt.c).
7978

80-
Update the connectionString variable to the device-specific connection string you got earlier from the Setup Azure IoT step:
8179
```
82-
static const char* connectionString = '[azure connection string]'
80+
static const char* connectionString = '[azure connection string]';
8381
```
84-
The azure connection string contains Hostname, DeviceId, and SharedAccessKey in the format:
82+
- The azure connection string contains Hostname, DeviceId, and SharedAccessKey in the format:
83+
8584
```
8685
"HostName=<host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>"
87-
```
88-
### 4.2 config your Wifi
89-
```
90-
make menuconfig
91-
```
92-
choose example configuration to **set Wifi SSID and Password!**
93-
94-
### 4.3 build your demo and flash to ESP32
95-
```
96-
$make flash
97-
```
98-
if failed,try:
99-
- make sure that ESP32 had connect to PC by serial port
100-
- make sure you flash to correct serial port
101-
- try type command:
102-
> sudo usermod -a -G dialout $USER
103-
104-
<span id = "results">Part 5: Result shows</span>
105-
------------------------------
106-
login iothub-explorer,and monitor events:
107-
```
108-
iothub-explorer monitor-events AirConditionDevice_001 --login 'HostName=youriothub-ms-lot-hub.azure-devices.cn;SharedAccessKeyName=iothubowner;SharedAccessKey=zMeLQ0JTlZXVcHBVOwRFVmlFtcCz+CtbDpUPBWexbIY='
10986
```
110-
- restart ESP32 after bin had flashed,you would see the ESP32 send data to lothub-explorer by minicom,and iothub-explorer would receive data!
111-
- At the same time,you can send message to ESP32 by iothub-explorer until you send a quit message
112-
113-
<span id = "troubleshoot">TroubleShoot</span>
114-
------------------------------
115-
- close some firewall settings
116-
- build failed,try:
117-
- git submodule init
118-
- git submodule update
119-
- export your compiler path
120-
- export your SDK path
121-
- get start with http://espressif.com/en/support/download/documents?keys=&field_type_tid%5B%5D=13
122-
- make sure you had input correct device connect-string which get from Part 3
123-
87+
88+
### 2. Configuring your Wi-Fi and serial port
89+
- Go to `make menuconfig` -> `Example configuration` to configure your Wi-Fi SSID and Password;
90+
- Go to `make menuconfig` -> `Serial flasher config` to configure you serial port.
91+
92+
### 3. Building your demo and flash to ESP device with `$make flash`.
93+
If failed, please:
94+
- make sure your ESP device had connected to PC with serial port;
95+
- make sure you have selected the corrected serial port;
96+
- command `> sudo usermod -a -G dialout $USER` can also be used.
97+
98+
## Checking Result
99+
100+
<a name="Checking_Result"></a>
101+
102+
Please check results on both the iothub and device side:
103+
104+
- iothub: log into iothub-explorer, and monitor events with command `iothub-explorer monitor-events yourdevice --login 'yourprimarykey'`
105+
- ESP device: monitor events with command `make monitor`
106+
107+
ESP device would send data to the Azure cloud, and then you would be able to receive data at the iothub side.
108+
109+
## Troubleshooting
110+
<a name="Troubleshooting"></a>
111+
112+
1. Some common problems can be fixed by disabling the firewall.
113+
114+
2. You can try with the followings, if your build fails:
115+
- git submodule init
116+
- git submodule update
117+
- export your compiler path
118+
- export your IDF path
119+
- get start from [Here](https://www.espressif.com/en/support/download/documents)
120+
121+
3. Make sure the device connection string you are using, which you get from Azure IoT Hub, is correct.

components/azure_iot/component.mk

-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
# Component configuration in preprocessor defines
66
CFLAGS += -DUSE_LWIP_SOCKET_FOR_AZURE_IOT
77

8-
ifdef CONFIG_TARGET_PLATFORM_ESP8266
9-
CFLAGS += -DCONFIG_FREERTOS_HZ=100
10-
endif
11-
128
COMPONENT_ADD_INCLUDEDIRS := \
139
pal \
1410
pal/inc \

components/azure_iot/pal/inc/sntp_os.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
//This file pulls in OS-specific header files to allow compilation of socket_async.c under
55
// most OS's except for Windows.
66

7-
// For ESP32 lwIP systems which use the ESP-IDF's non-standard lwIP include structure
7+
// For ESP platform lwIP systems which use the ESP-IDF's non-standard lwIP include structure
88
// Tested with:
9-
// ESP32
9+
// ESP platform
1010

1111
#ifndef LWIP_SNTP_OS_H
1212
#define LWIP_SNTP_OS_H
1313

1414
#include "apps/sntp/sntp.h"
1515

16-
#endif // LWIP_SNTP_OS_H
16+
#endif // LWIP_SNTP_OS_H

components/azure_iot/pal/inc/socket_async_os.h

+3-9
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,13 @@
66

77
// For lwIP systems
88
// Tested with:
9-
// ESP32
9+
// ESP platform
1010

1111
#ifndef SOCKET_ASYNC_OS_H
1212
#define SOCKET_ASYNC_OS_H
1313

1414
#include "sdkconfig.h"
15-
16-
#ifdef CONFIG_TARGET_PLATFORM_ESP8266
17-
#include "sys/socket.h"
18-
#else
19-
#include "lwip/sockets.h"
20-
#endif
21-
22-
#include "lwip/netdb.h"
15+
#include <sys/socket.h>
16+
#include <netdb.h>
2317

2418
#endif // SOCKET_ASYNC_OS_H

components/azure_iot/pal/src/platform_esp.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void initialize_sntp(void);
3030
int platform_init(void)
3131
{
3232
initialize_sntp();
33-
printf("ESP32 sntp inited!\n");
33+
printf("ESP platform sntp inited!\n");
3434
time_t now = sntp_get_current_timestamp();
3535

3636
char strftime_buf[64];
@@ -58,5 +58,5 @@ STRING_HANDLE platform_get_platform_info(void)
5858
{
5959
// Expected format: "(<runtime name>; <operating system name>; <platform>)"
6060

61-
return STRING_construct("(native; freertos; esp32)");
61+
return STRING_construct("(native; freertos; esp platform)");
6262
}

components/azure_iot/pal/src/tlsio_openssl_compact.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ static void dowork_poll_open_ssl(TLS_IO_INSTANCE* tls_io_instance)
650650

651651
int connect_result = SSL_connect(tls_io_instance->ssl);
652652

653-
// The following note applies to the Espressif ESP32 implementation
653+
// The following note applies to the Espressif ESP platform implementation
654654
// of OpenSSL:
655655
// The manual pages say that 0 is a failure,
656656
// but by experiment, 0 is the success result, at least when using

doc/IoT_Suite.md

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
## Applying an Azure Trail Account
2+
3+
1. Go to [Azure IoT Suite](https://www.azure.cn/en-us/home/features/iot-suite/) and click on 1RMB Trail.
4+
5+
![](_static/IoT_Suite.png)
6+
7+
2. Enter you phone number and complete the verification process.
8+
9+
![](_static/phone_number.png)
10+
11+
3. Enter basic information and complete the real name authentication.
12+
13+
![](_static/basic_information.png)
14+
15+
4. Register
16+
17+
![](_static/about_you.png)
18+
19+
5. Pay 1 RMB to complete the register
20+
21+
![](_static/purchase.png)
22+
23+
## Obtaining Connection String
24+
25+
1. Go to [Azure IoT Portal](https://portal.azure.cn).
26+
27+
![](_static/portal.png)
28+
29+
2. Click on "All services", and choose "IoT Hub".
30+
31+
![](_static/all_service.png)
32+
33+
3. Create a new IoT hub.
34+
35+
![](_static/new_iot_hub.png)
36+
37+
4. Name your new hub.
38+
39+
![](_static/name_iot_hub.png)
40+
41+
5. Obtain your connection string as instructed in the figure below:
42+
43+
![](_static/connection_string.png)

doc/_static/About_you_Natasha.png

113 KB
Loading

doc/_static/IoT_Suite.png

82 KB
Loading

doc/_static/about_you.png

104 KB
Loading

doc/_static/all_service.png

142 KB
Loading

doc/_static/basic_information.png

144 KB
Loading

doc/_static/connection_string.png

238 KB
Loading

doc/_static/esp-azure-workflow.png

61.1 KB
Loading

doc/_static/name_iot_hub.png

75.4 KB
Loading

doc/_static/new_iot_hub.png

90.8 KB
Loading

doc/_static/phone_number.png

71.3 KB
Loading

doc/_static/portal.png

134 KB
Loading

doc/_static/purchase.png

110 KB
Loading

doc/iothub_explorer.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# iothub-explorer usage
2+
3+
## login [any operation should login first]
4+
```
5+
iothub-explorer login "HostName=chenwu-ms-lot-hub.azure-devices.cn;SharedAccessKeyName=iothubowner;SharedAccessKey=zMeLQ0JTlZXVcHBVOwRFVmlFtcCz+CtbDpUPBWexbIY="
6+
```
7+
8+
## list all device
9+
```
10+
iothub-explorer list
11+
```
12+
13+
## get special device detail info
14+
```
15+
iothub-explorer get myFirstNodeDevice --connection-string
16+
```
17+
18+
## create one device
19+
```
20+
iothub-explorer create AirConditionDevice_001 --connection-string
21+
```
22+
23+
## delete one device
24+
```
25+
iothub-explorer delete myFirstNodeDevice
26+
```
27+
28+
## monitor your device
29+
```
30+
iothub-explorer monitor-events AirConditionDevice_001 --login 'HostName=chenwu-ms-lot-hub.azure-devices.cn;SharedAccessKeyName=iothubowner;SharedAccessKey=zMeLQ0JTlZXVcHBVOwRFVmlFtcCz+CtbDpUPBWexbIY='
31+
```
32+
33+
## send message to device
34+
```
35+
iothub-explorer send AirConditionDevice_001 "hello,my friends!"
36+
```
37+
```
38+
iothub-explorer send AirConditionDevice_001 quit
39+
```
40+
41+

0 commit comments

Comments
 (0)