在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):GoogleCloudPlatform/google-cloud-iot-arduino开源软件地址(OpenSource Url):https://github.com/GoogleCloudPlatform/google-cloud-iot-arduino开源编程语言(OpenSource Language):C++ 63.4%开源软件介绍(OpenSource Introduction):Google Cloud IoT JWTThis is an example of how to generate JSON Web Token (JWT) credentials for connecting to Google Cloud IoT Core. This contains two parts: a library to make a JWT (json web token) which is used to authenticate with Google Cloud IoT, and Arduino sketches that demonstrate how to connect to Google Cloud IoT using the available MQTT bridge. This example is not an officially supported Google product, does not have a SLA/SLO, and should not be used in production. Supported hardware targetsCurrently, we support the following hardware targets:
DependenciesSome examples use specific dependencies that need to be installed via the Arduino Library manager. QuickstartFirst, install the library using the Arduino Library Manager.
Next, enable the Cloud IoT Core API by opening the Google Cloud IoT Core console. Next, create your device registry as described in the Quickstart or by using the Google Cloud SDK. If you're using the SDK, the following commands will setup PubSub and Cloud IoT Core for testing on your Arduino device: Create the PubSub topic and subscription:
Create the Cloud IoT Core registry:
Generate an Eliptic Curve (EC) private / public key pair:
Register the device using the keys you generated:
At this point, your registry is created and your device has been added to the registry so you're ready to connect it. Select one of the available samples from the File > Examples > Google Cloud IoT Core JWT menu and find the configuration section (ciotc_config.h in newer examples). Find and replace the following values first:
You will also need to extract your private key using the following command:
... and will need to copy the output for the private key bytes into the private key string in your Arduino project. When you run the sample, the device will connect and receive configuration from Cloud IoT Core. When you change the configuration in the Cloud IoT Core console, that configuration will be reflrected on the device. Before the examples will work, you will also need to configure the root certificate as described in the configuration headers. After you have published telemetry data, you can read it from the PubSub topic using the Google Cloud SDK. With the SDK installed, run the following command to create a :
Then read the telemetry messages:
Notes on the certificateThe root certificate from Google is used to verify communication to Google. Although unlikely, it's possible for the certificate to expire or rotate, requiring you to update it. If you're using the ESP8266 project, you need to either install the Certificate to SPIFFS
using the SPIFFS upload utility or
will need to uncomment the certificate bytes in the sample. Note that the SPIFFS utility simply
uploads the files stored in the data subfolder. The sample assumes the file is called
To convert the certificate to the DER format, the following command shuold be used:
If you're using the ESP32, you can paste the certificate bytes (don't forget the \n characters) into the sample. You can use any of the root certificate bytes for the certificates with Google Trust Services (GTS) as the certificate authority (CA). This is easy to get using curl, e.g.
If you're using Genuino boards like the MKR1000, you will need to add SSL certificates to your
board as described on Hackster.io.
The MQTT server address is In future versions of this library, the MQTT domain and certificates will be changed for long term support (LTS) to:
The following examples show how to regenerate the certificates: Create Registry keys
Create Elipitic device keys
Print info to copy to code
For more information
DemosYou can see the Arduino client library in action in the Cloud IoT Demo from Google I/O 2018 Error codes, Debugging, and TroubleshootingThe error codes for the lwMQTT library are listed in this header file. If you're having trouble determining what's wrong, it may be helpful to enable more verbose debugging in Arduino by setting the debug level in the IDE under Tools > Core Debug Level > Verbose. If you are using newer versions of the ESP8266 SDK, you need to set SSL support to "All SSL Cyphers" and you may need to modify the memory settings in BearSSL by modifying Arduino/cores/esp8266/StackThunk.cpp. A few things worth checking while troubleshooting:
Known issuesSome private keys do not correctly encode to the Base64 format that required for the device bridge. If you've tried everything else, try regenerating your device credentials and registering your device again with
Some users have encountered issues with certain versions of the Community SDK for Espressif, if you've tried everything else, try using the SDK 2.4.2. LicenseApache 2.0; see LICENSE for details. DisclaimerThis project is not an official Google project. It is not supported by Google and Google specifically disclaims all warranties as to its quality, merchantability, or fitness for a particular purpose. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论