Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Oct 12, 2023. It is now read-only.

Commit d263f4a

Browse files
Sync the Arduino Library azure-iot-arduino-protocol-mqtt with the latest azure-iot-sdks version
1 parent 2e453a2 commit d263f4a

File tree

5 files changed

+34
-29
lines changed

5 files changed

+34
-29
lines changed

‎.travis.yml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
language: generic
55
env:
66
global:
7-
- IDE_VERSION=1.6.8
7+
- IDE_VERSION=1.6.12
88
matrix:
99
- BOARD="arduino:samd:arduino_zero_edbg"
1010
- BOARD="arduino:samd:mkr1000"
@@ -21,6 +21,7 @@ before_install:
2121
- if [[ "$BOARD" =~ "arduino:samd:" ]]; then
2222
arduino --install-boards arduino:samd;
2323
arduino --install-library WiFi101;
24+
arduino --install-library WiFi101;
2425
arduino --install-library RTCZero;
2526
arduino --install-library NTPClient;
2627
fi
@@ -45,6 +46,8 @@ before_install:
4546
arduino --verbose-build --verify --board $BOARD $EXAMPLE_SKETCH;
4647
}
4748
install:
49+
- arduino --install-library "AzureIoTUtility"
50+
- arduino --install-library "AzureIoTProtocol_MQTT"
4851
- ln -s $PWD $HOME/Arduino/libraries/.
4952
script:
5053
- buildExampleSketch simplesample_mqtt

‎README.md‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This library is a port of the compact implementation of the MQTT protocol from [
77
Currently supported hardware:
88
- Atmel SAMD Based boards
99
- Arduino/Genuino [MKR1000](https://www.arduino.cc/en/Main/ArduinoMKR1000)
10-
- Arduino/Genuino [Zero](https://www.arduino.cc/en/Main/ArduinoBoardZero) and [WiFi Shield 101](https://www.arduino.cc/en/Main/ArduinoWiFiShield101)
10+
- Arduino/Genuino [Zero](https://www.arduino.cc/en/Main/ArduinoBoardZero) and [WiFi Shield 101](https://www.arduino.cc/en/Main/ArduinoWiFiShield101)
1111
- Adafruit [Feather M0](https://www.adafruit.com/products/3010)
1212
- ESP8266 based boards with [esp8266/arduino](https://github.com/esp8266/arduino)
1313
- SparkFun [Thing](https://www.sparkfun.com/products/13711)
@@ -18,7 +18,7 @@ Currently supported hardware:
1818
You should have the following ready before beginning with any board:
1919
- [Setup your IoT hub](https://github.com/Azure/azure-iot-sdks/blob/master/doc/setup_iothub.md)
2020
- [Provision your device and get its credentials](https://github.com/Azure/azure-iot-sdks/blob/master/doc/manage_iot_hub.md)
21-
- [Arduino IDE 1.6.8](https://www.arduino.cc/en/Main/Software)
21+
- [Arduino IDE 1.6.12](https://www.arduino.cc/en/Main/Software)
2222
- Install the `AzureIoTHub` library via the Arduino IDE Library Manager
2323
- Install the `AzureIoTUtility` library via the Arduino IDE Library Manager
2424
- Install the `AzureIoTProtocol_MQTT` library via the Arduino IDE Library Manager
@@ -30,7 +30,7 @@ You should have the following ready before beginning with any board:
3030
2. Install the `WiFi101` library from the Arduino IDE Library Manager.
3131
3. Install the `NTPClient` library from the Arduino IDE Library Manager.
3232
4. Install the `RTCZero` library from the Arduino IDE Library Manager.
33-
5. Update Wifi SSID/Password in simplesample_mqtt.ino
33+
5. Update Wifi SSID/Password in simplesample_mqtt.ino
3434
* Ensure you are using a wifi network that does not require additional manual steps after connection, such as opening a web browser.
3535
6. Update IoT Hub Connection string in simplesample_mqtt.c
3636

@@ -40,12 +40,12 @@ You should have the following ready before beginning with any board:
4040
1. Install esp8266 board support into your Arduino IDE.
4141
* Start Arduino and open Preferences window.
4242
* Enter `http://arduino.esp8266.com/stable/package_esp8266com_index.json` into Additional Board Manager URLs field. You can add multiple URLs, separating them with commas.
43-
* Open Boards Manager from Tools > Board menu and install esp8266 platform 2.2.0 or later
43+
* Open Boards Manager from Tools > Board menu and install esp8266 platform 2.2.0 or later
4444
* Select your ESP8266 board from Tools > Board menu after installation
45-
45+
4646
2. Open the `simplesample_mqtt` example from the Arduino IDE File->Examples->AzureIoTHub menu.
4747
3. Update the sketch as directed by comments in the sample to support the ESP8266 board.
48-
4. Update Wifi SSID/Password in simplesample_mqtt.ino
48+
4. Update Wifi SSID/Password in simplesample_mqtt.ino
4949
* Ensure you are using a wifi network that does not require additional manual steps after connection, such as opening a web browser.
5050
5. Update IoT Hub Connection string in simplesample_mqtt.c
5151
6. Access the [SparkFun Get Started](https://azure.microsoft.com/en-us/documentation/samples/iot-hub-c-thingdev-getstartedkit/) tutorial to learn more about Microsoft Sparkfun Dev Kit.
@@ -56,14 +56,14 @@ You should have the following ready before beginning with any board:
5656
1. Install Feather M0 board support into your Arduino IDE.
5757
* Start Arduino and open Preferences window.
5858
* Enter `https://adafruit.github.io/arduino-board-index/package_adafruit_index.json` into Additional Board Manager URLs field. You can add multiple URLs, separating them with commas.
59-
* Open Boards Manager from Tools > Board menu and install Adafruit SAMD Boards 1.0.7 or later.
60-
* Select your Adafruit Feather M0 from Tools > Board menu after installation
59+
* Open Boards Manager from Tools > Board menu and install `Arduino SAMD Boards` and `Adafruit SAMD Boards` 1.0.7 or later.
60+
* Select your `Adafruit Feather M0` from Tools > Board menu after installation
6161
2. Install the [Adafruit WINC1500 wifi library](https://learn.adafruit.com/adafruit-feather-m0-wifi-atwinc1500/using-the-wifi-module)
6262
3. Install the `RTCZero` library from the Arduino IDE Library Manager.
6363
4. Install the `NTPClient` library from the Arduino IDE Library Manager.
6464
5. Open the `simplesample_mqtt` example from the Arduino IDE File->Examples->AzureIoTHub menu.
6565
6. Update the sketch as directed by comments in the sample to support the ESP8266 board.
66-
7. Update Wifi SSID/Password in simplesample_mqtt.ino
66+
7. Update Wifi SSID/Password in simplesample_mqtt.ino
6767
* Ensure you are using a wifi network that does not require additional manual steps after connection, such as opening a web browser.
6868
8. Update IoT Hub Connection string in simplesample_mqtt.c
6969
9. Access the [Feather M0 WiFi Get Started](https://azure.microsoft.com/en-us/documentation/samples/iot-hub-c-m0wifi-getstartedkit/) tutorial to learn more about Microsoft Feather M0 WiFi Dev Kit.
@@ -72,5 +72,5 @@ You should have the following ready before beginning with any board:
7272

7373
See [LICENSE](LICENSE) file.
7474

75-
[azure-certifiedforiot]: http://azure.com/certifiedforiot
75+
[azure-certifiedforiot]: http://azure.com/certifiedforiot
7676
[Microsoft-Azure-Certified-Badge]: images/Microsoft-Azure-Certified-150x150.png (Microsoft Azure Certified)

‎examples/simplesample_mqtt/simplesample_mqtt.c‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ BEGIN_NAMESPACE(WeatherStation);
3636
DECLARE_MODEL(ContosoAnemometer,
3737
WITH_DATA(ascii_char_ptr, DeviceId),
3838
WITH_DATA(int, WindSpeed),
39+
WITH_DATA(float, Temperature),
40+
WITH_DATA(float, Humidity),
3941
WITH_ACTION(TurnFanOn),
4042
WITH_ACTION(TurnFanOff),
4143
WITH_ACTION(SetAirResistance, int, Position)
4244
);
4345

4446
END_NAMESPACE(WeatherStation);
4547

48+
static char propText[1024];
4649

4750
EXECUTE_COMMAND_RESULT TurnFanOn(ContosoAnemometer* device)
4851
{
@@ -74,7 +77,7 @@ void sendCallback(IOTHUB_CLIENT_CONFIRMATION_RESULT result, void* userContextCal
7477
(void)printf("Result Call Back Called! Result is: %s \r\n", ENUM_TO_STRING(IOTHUB_CLIENT_CONFIRMATION_RESULT, result));
7578
}
7679

77-
static void sendMessage(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const unsigned char* buffer, size_t size)
80+
static void sendMessage(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const unsigned char* buffer, size_t size, ContosoAnemometer*myWeather)
7881
{
7982
static unsigned int messageTrackingId;
8083
IOTHUB_MESSAGE_HANDLE messageHandle = IoTHubMessage_CreateFromByteArray(buffer, size);
@@ -84,6 +87,13 @@ static void sendMessage(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const unsign
8487
}
8588
else
8689
{
90+
MAP_HANDLE propMap = IoTHubMessage_Properties(messageHandle);
91+
(void)sprintf_s(propText, sizeof(propText), myWeather->Temperature > 28 ? "true" : "false");
92+
if (Map_AddOrUpdate(propMap, "temperatureAlert", propText) != MAP_OK)
93+
{
94+
(void)printf("ERROR: Map_AddOrUpdate Failed!\r\n");
95+
}
96+
8797
if (IoTHubClient_LL_SendEventAsync(iotHubClientHandle, messageHandle, sendCallback, (void*)(uintptr_t)messageTrackingId) != IOTHUB_CLIENT_OK)
8898
{
8999
printf("failed to hand over the message to IoTHubClient");
@@ -149,6 +159,8 @@ void simplesample_mqtt_run(void)
149159
IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle = IoTHubClient_LL_CreateFromConnectionString(connectionString, MQTT_Protocol);
150160
srand((unsigned int)time(NULL));
151161
int avgWindSpeed = 10;
162+
float minTemperature = 20.0;
163+
float minHumidity = 60.0;
152164

153165
if (iotHubClientHandle == NULL)
154166
{
@@ -180,16 +192,18 @@ void simplesample_mqtt_run(void)
180192
{
181193
myWeather->DeviceId = "myFirstDevice";
182194
myWeather->WindSpeed = avgWindSpeed + (rand() % 4 + 2);
195+
myWeather->Temperature = minTemperature + (rand() % 10);
196+
myWeather->Humidity = minHumidity + (rand() % 20);
183197
{
184198
unsigned char* destination;
185199
size_t destinationSize;
186-
if (SERIALIZE(&destination, &destinationSize, myWeather->DeviceId, myWeather->WindSpeed) != CODEFIRST_OK)
200+
if (SERIALIZE(&destination, &destinationSize, myWeather->DeviceId, myWeather->WindSpeed, myWeather->Temperature, myWeather->Humidity) != CODEFIRST_OK)
187201
{
188202
(void)printf("Failed to serialize\r\n");
189203
}
190204
else
191205
{
192-
sendMessage(iotHubClientHandle, destination, destinationSize);
206+
sendMessage(iotHubClientHandle, destination, destinationSize, myWeather);
193207
free(destination);
194208
}
195209
}

‎examples/simplesample_mqtt/simplesample_mqtt.ino‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,11 @@ Adafruit_WINC1500 WiFi(WINC_CS, WINC_IRQ, WINC_RST);
4848
static char ssid[] = "yourNetwork"; // your network SSID (name)
4949
static char pass[] = "yourPassword"; // your network password (use for WPA, or use as key for WEP)
5050

51-
// In the next line we decide each client ssl we'll use.
52-
#ifdef ARDUINO_ARCH_ESP8266
53-
static WiFiClientSecure sslClient; // for ESP8266
54-
#elif ARDUINO_SAMD_FEATHER_M0
55-
static Adafruit_WINC1500SSLClient sslClient; // for Adafruit WINC1500
56-
#else
57-
static WiFiSSLClient sslClient;
58-
#endif
59-
60-
static AzureIoTHubClient iotHubClient;
6151

6252
void setup() {
6353
initSerial();
6454
initWifi();
6555
initTime();
66-
67-
iotHubClient.begin(sslClient);
6856
}
6957

7058
void loop() {
@@ -74,7 +62,9 @@ void loop() {
7462
void initSerial() {
7563
// Start serial and initialize stdout
7664
Serial.begin(115200);
65+
#ifdef ARDUINO_ARCH_ESP8266
7766
Serial.setDebugOutput(true);
67+
#endif
7868
}
7969

8070
void initWifi() {
@@ -130,8 +120,6 @@ void initTime() {
130120
Serial.print("Fetched NTP epoch time is: ");
131121
Serial.println(epochTime);
132122

133-
iotHubClient.setEpochTime(epochTime);
134-
135123
#elif ARDUINO_ARCH_ESP8266
136124
time_t epochTime;
137125

‎library.properties‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=AzureIoTProtocol_MQTT
2-
version=1.0.30
2+
version=1.0.33
33
author=Microsoft
44
maintainer=Microsoft <iotcert@microsoft.com>
55
sentence=Azure MQTT protocol library for Arduino. For the Arduino MKR1000 or Zero and WiFi Shield 101, Adafruit Huzzah and Feather M0, or SparkFun Thing.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /