Skip to content

Commit 7074453

Browse files
authored
tools: adding IoT Connection Tools and ISD code samples (#9)
* tools: initial version of IoT Connection Tools and ISD code samples Signed-off-by: Mihai Tudor Panu <[email protected]> * iotkit: update ciTests field in sample.json files Signed-off-by: Mihai Tudor Panu <[email protected]> * sample.json: update supported os list for hello IoT world and ISD tutorial Signed-off-by: Mihai Tudor Panu <[email protected]>
1 parent 4c3b5d3 commit 7074453

File tree

144 files changed

+5337
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+5337
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
cmake_minimum_required (VERSION 3.0)
2+
3+
# Set default build type to RelWithDebInfo if not specified
4+
if (NOT CMAKE_BUILD_TYPE)
5+
message (STATUS "Default CMAKE_BUILD_TYPE not set using Release with Debug Info")
6+
set (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE
7+
STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel"
8+
FORCE)
9+
endif()
10+
11+
# Set language standard
12+
set(CMAKE_CXX_STANDARD "11")
13+
14+
project (ANALOG-IN)
15+
16+
# OS checks
17+
if(WIN32)
18+
message(FATAL_ERROR, "This sample cannot be compiled natively on Windows OS.")
19+
endif()
20+
21+
# Dependency checks
22+
find_package(PkgConfig)
23+
pkg_search_module (MRAA REQUIRED mraa)
24+
25+
add_subdirectory(cpp)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright (c) 2020 Intel Corporation
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the The MIT License which is available at
6+
* https://opensource.org/licenses/MIT.
7+
*
8+
* SPDX-License-Identifier: MIT
9+
*/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Analog In
2+
3+
## Introduction
4+
This is a simple sample you could use for a quick test of an analog input.
5+
6+
## What it is
7+
This project demonstrates how to read an analog value from an input pin using the Eclipse* MRAA library.
8+
9+
## Hardware requirements
10+
A board with an accessible GPIO input pin.
11+
Some analog input device or sensor such as the Rotary Angle Sensor, Light Sensor, Sound Sensor, Temperature Sensor in Starter Kits.
12+
13+
## Supported boards
14+
This sample has been tested on
15+
- [UP Squared\* AI Vision Kit](https://software.intel.com/en-us/iot/hardware/up-squared-ai-vision-dev-kit)
16+
17+
The sample might need minor modifications depending on the board and shield you are using.
18+
19+
## Software requirements
20+
This sample is supported on Linux systems only.
21+
22+
This version of the sample has been tested on Ubuntu Linux. It requires the [Eclipse* MRAA library](https://github.com/intel-iot-devkit/mraa).
23+
24+
This sample requires additional system configuration when using Ubuntu OS with the UP series boards. Instructions on how to install the custom provided Linux kernel with the required drivers can be [found here](https://wiki.up-community.org/Ubuntu#Ubuntu_18.04_installation_and_configuration).
25+
26+
In order to enable the ADC on Intel® Atom based UP boards, refer to the following [download](https://downloads.up-community.org/download/how-to-access-adc-for-up-squared-atom/).
27+
28+
## Setup
29+
Create a new project using this sample in Eclipse* IDE and after installing the Intel® oneAPI IoT Toolkit.
30+
Connect the input device to an analog input pin on your IoT board.
31+
32+
## Note
33+
Accessing device sensors, including LEDs, requires MRAA I/O operations. Mraa I/O operations require permissions to UNIX character devices and sysfs classes not commonly granted to normal users by default.
34+
To learn how to use I/O devices from user space with the UP series boards refer to [this link](https://wiki.up-community.org/Ubuntu#Enable_the_HAT_functionality_from_userspace).
35+
36+
## Disclaimer
37+
IMPORTANT NOTICE: This software is sample software. It is not designed or intended for use in any medical, life-saving or life-sustaining systems, transportation systems, nuclear systems, or for any other mission-critical application in which the failure of the system could lead to critical injury or death. The software may not be fully tested and may contain bugs or errors; it may not be intended or suitable for commercial release. No regulatory approvals for the software have been obtained, and therefore software may not be certified for use in certain countries or environments.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MRAA_CFLAGS}")
2+
add_executable (analog-in analog-in.cpp)
3+
add_custom_target (run ./analog-in)
4+
target_link_libraries(analog-in ${MRAA_LDFLAGS})
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/* ==============================================================
2+
* Copyright (c) 2015 - 2020 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
* ============================================================= */
6+
7+
/* Analog input
8+
* Read values from a gpio analog input pin.
9+
*/
10+
11+
#include <unistd.h>
12+
13+
#include <iostream>
14+
#include <mraa.hpp>
15+
16+
// Define the following if using a Grove Pi Shield
17+
#define USING_GROVE_PI_SHIELD
18+
using namespace std;
19+
using namespace mraa;
20+
21+
// leave warning/error message in console and wait for user to press Enter
22+
void consoleMessage(const string& str) {
23+
cerr << str << endl;
24+
sleep(10);
25+
}
26+
27+
// check if running as root
28+
void checkRoot(void) {
29+
int euid = geteuid();
30+
if (euid) {
31+
consoleMessage(
32+
"This project uses Mraa I/O operations that may require\n"
33+
"'root' privileges, but you are running as non - root user.\n"
34+
"Passwordless keys(RSA key pairs) are recommended \n"
35+
"to securely connect to your target with root privileges. \n"
36+
"See the project's Readme for more info.\n\n");
37+
}
38+
return;
39+
}
40+
41+
// set pin values depending on the current board (platform)
42+
void initPlatform(int& gpioPin) {
43+
// check which board we are running on
44+
Platform platform = getPlatformType();
45+
switch (platform) {
46+
case INTEL_UP2:
47+
#ifdef USING_GROVE_PI_SHIELD
48+
gpioPin = 2 + 512; // A2 Connector (512 offset needed for the shield)
49+
break;
50+
#endif
51+
default:
52+
string unknownPlatformMessage =
53+
"This sample uses the MRAA/UPM library for I/O access, "
54+
"you are running it on an unrecognized platform.\n"
55+
"You may need to modify the MRAA/UPM initialization code to "
56+
"ensure it works properly on your platform.\n";
57+
consoleMessage(unknownPlatformMessage);
58+
}
59+
return;
60+
}
61+
62+
int main() {
63+
// Check access permissions for the current user
64+
// Can be commented out for targets with user level I/O access enabled
65+
checkRoot();
66+
67+
int gpioPin = 2;
68+
initPlatform(gpioPin);
69+
70+
#ifdef USING_GROVE_PI_SHIELD
71+
addSubplatform(GROVEPI, "0");
72+
#endif
73+
// create an analog input object from MRAA using the pin
74+
Aio* a_pin = new Aio(gpioPin);
75+
if (a_pin == NULL) {
76+
consoleMessage("Can't create mraa::Aio object, exiting");
77+
return MRAA_ERROR_UNSPECIFIED;
78+
}
79+
80+
// loop forever printing the input value every second
81+
for (;;) {
82+
uint16_t pin_value;
83+
try {
84+
// read the current input voltage
85+
pin_value = a_pin->read();
86+
} catch (const invalid_argument& readExc) {
87+
// if incorrect voltage value input
88+
cerr << "Invalid argument, exception thrown: " << readExc.what() << endl;
89+
consoleMessage("MRAA cannot read pin value!");
90+
return MRAA_ERROR_INVALID_PARAMETER;
91+
}
92+
cout << "analog input value " << pin_value << endl;
93+
sleep(1);
94+
}
95+
96+
return SUCCESS;
97+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"guid": "EEED3DAC-8D4E-4F4B-9C15-2B73CF0AC718",
3+
"name": "Analog Input",
4+
"categories": ["Toolkit/Intel® oneAPI IoT Toolkit/IoT Connection Tools"],
5+
"description": "Demonstrate how to read an analog voltage value from an input pin using the Eclipse* MRAA library.",
6+
"dependencies": ["pkg|mraa|https://mraa.io"],
7+
"languages": [{"cpp":{}}],
8+
"os": ["linux"],
9+
"ciTests": {
10+
"linux": [
11+
{ "id": "analog-in",
12+
"env": [],
13+
"steps": [
14+
"mkdir build",
15+
"cd build",
16+
"cmake ..",
17+
"make"
18+
]
19+
}
20+
]
21+
}
22+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
cmake_minimum_required(VERSION 2.8.11)
2+
project(azure-iothub-telemetry)
3+
4+
if (CMAKE_VERSION VERSION_LESS "3.1")
5+
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
6+
set (CMAKE_C_FLAGS "--std=c99 ${CMAKE_C_FLAGS}")
7+
if (NOT IN_OPENWRT)
8+
set (CMAKE_CXX_FLAGS "--std=c++11 ${CMAKE_CXX_FLAGS}")
9+
endif()
10+
endif()
11+
else()
12+
set (CMAKE_C_STANDARD 99)
13+
set (CMAKE_CXX_STANDARD 11)
14+
endif()
15+
16+
set(iothub_c_files
17+
cpp/iothub_ll_telemetry_sample.c
18+
)
19+
20+
if(${use_sample_trusted_cert})
21+
add_definitions(-DSET_TRUSTED_CERT_IN_SAMPLES)
22+
include_directories(certs)
23+
set(iothub_c_files certs/certs.c)
24+
endif()
25+
26+
set(AZUREIOT_INC_FOLDER "." "/usr/include/azureiot" "/usr/include/azureiot/inc")
27+
28+
include_directories(${AZUREIOT_INC_FOLDER})
29+
30+
add_executable(azure-iothub-telemetry ${iothub_c_files})
31+
target_link_libraries(azure-iothub-telemetry
32+
iothub_client_mqtt_transport
33+
iothub_client_amqp_transport
34+
iothub_client_http_transport
35+
iothub_client
36+
umqtt
37+
prov_auth_client
38+
hsm_security_client
39+
uhttp
40+
aziotsharedutil
41+
parson
42+
uuid
43+
pthread
44+
curl
45+
ssl
46+
crypto
47+
m
48+
)
49+
50+
add_subdirectory(cpp)
51+
52+
add_custom_target (run ./azure-iothub-telemetry)
53+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright (c) 2020 Intel Corporation
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the The MIT License which is available at
6+
* https://opensource.org/licenses/MIT.
7+
*
8+
* SPDX-License-Identifier: MIT
9+
*/
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Azure IoTHub Telemetry
2+
3+
## Introduction
4+
This is a simple sample you could use for a quick test of Azure cloud services.
5+
6+
## What it is
7+
This project demonstrates how to send messages from a single device to Microsoft Azure IoT Hub via chosen protocol.
8+
9+
## Hardware requirements
10+
The minimum requirements are for the device platform to support can be [found here](https://github.com/Azure/azure-iot-sdk-c).
11+
12+
## Software requirements
13+
This sample is supported on Linux systems only.
14+
15+
This version of the sample has been tested on Ubuntu Linux. This sample requires additional system configuration when using Ubuntu OS. Instructions on how to install the custom provided all dependency libraries for Linux can be [found here](https://github.com/Azure/azure-iot-sdk-c/blob/master/doc/ubuntu_apt-get_sample_setup.md).
16+
17+
## Setup
18+
Create and configure Azure IoTHub on [Microsoft Azure page](https://portal.azure.com/#home).
19+
Detailed instructions are on [Microsoft website](https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-create-through-portal).
20+
21+
Paste the Device Connection String into the following line:
22+
`static const char* connectionString = "[device connection string]"`
23+
24+
Choose one of the protocols to connect: MQTT over websockets, AMQP, AMQP over websockets or HTTP by uncommenting one of the following strings (MQTT protocol is chosen by default):
25+
`//#define SAMPLE_MQTT_OVER_WEBSOCKETS`
26+
`//#define SAMPLE_AMQP`
27+
`//#define SAMPLE_AMQP_OVER_WEBSOCKETS`
28+
`//#define SAMPLE_HTTP`
29+
30+
Build and run the sample.
31+
32+
## Disclaimer
33+
IMPORTANT NOTICE: This software is sample software. It is not designed or intended for use in any medical, life-saving or life-sustaining systems, transportation systems, nuclear systems, or for any other mission-critical application in which the failure of the system could lead to critical injury or death. The software may not be fully tested and may contain bugs or errors; it may not be intended or suitable for commercial release. No regulatory approvals for the software have been obtained, and therefore software may not be certified for use in certain countries or environments.

0 commit comments

Comments
 (0)