Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Tools/IoTConnectionTools/analog-in/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cmake_minimum_required (VERSION 3.0)

# Set default build type to RelWithDebInfo if not specified
if (NOT CMAKE_BUILD_TYPE)
message (STATUS "Default CMAKE_BUILD_TYPE not set using Release with Debug Info")
set (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE
STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel"
FORCE)
endif()

# Set language standard
set(CMAKE_CXX_STANDARD "11")

project (ANALOG-IN)

# OS checks
if(WIN32)
message(FATAL_ERROR, "This sample cannot be compiled natively on Windows OS.")
endif()

# Dependency checks
find_package(PkgConfig)
pkg_search_module (MRAA REQUIRED mraa)

add_subdirectory(cpp)
9 changes: 9 additions & 0 deletions Tools/IoTConnectionTools/analog-in/License.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright (c) 2020 Intel Corporation
*
* This program and the accompanying materials are made available under the
* terms of the The MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
*/
37 changes: 37 additions & 0 deletions Tools/IoTConnectionTools/analog-in/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Analog In

## Introduction
This is a simple sample you could use for a quick test of an analog input.

## What it is
This project demonstrates how to read an analog value from an input pin using the Eclipse* MRAA library.

## Hardware requirements
A board with an accessible GPIO input pin.
Some analog input device or sensor such as the Rotary Angle Sensor, Light Sensor, Sound Sensor, Temperature Sensor in Starter Kits.

## Supported boards
This sample has been tested on
- [UP Squared\* AI Vision Kit](https://software.intel.com/en-us/iot/hardware/up-squared-ai-vision-dev-kit)

The sample might need minor modifications depending on the board and shield you are using.

## Software requirements
This sample is supported on Linux systems only.

This version of the sample has been tested on Ubuntu Linux. It requires the [Eclipse* MRAA library](https://github.com/intel-iot-devkit/mraa).

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).

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/).

## Setup
Create a new project using this sample in Eclipse* IDE and after installing the Intel® oneAPI IoT Toolkit.
Connect the input device to an analog input pin on your IoT board.

## Note
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.
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).

## Disclaimer
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.
4 changes: 4 additions & 0 deletions Tools/IoTConnectionTools/analog-in/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MRAA_CFLAGS}")
add_executable (analog-in analog-in.cpp)
add_custom_target (run ./analog-in)
target_link_libraries(analog-in ${MRAA_LDFLAGS})
97 changes: 97 additions & 0 deletions Tools/IoTConnectionTools/analog-in/cpp/analog-in.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* ==============================================================
* Copyright (c) 2015 - 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
* ============================================================= */

/* Analog input
* Read values from a gpio analog input pin.
*/

#include <unistd.h>

#include <iostream>
#include <mraa.hpp>

// Define the following if using a Grove Pi Shield
#define USING_GROVE_PI_SHIELD
using namespace std;
using namespace mraa;

// leave warning/error message in console and wait for user to press Enter
void consoleMessage(const string& str) {
cerr << str << endl;
sleep(10);
}

// check if running as root
void checkRoot(void) {
int euid = geteuid();
if (euid) {
consoleMessage(
"This project uses Mraa I/O operations that may require\n"
"'root' privileges, but you are running as non - root user.\n"
"Passwordless keys(RSA key pairs) are recommended \n"
"to securely connect to your target with root privileges. \n"
"See the project's Readme for more info.\n\n");
}
return;
}

// set pin values depending on the current board (platform)
void initPlatform(int& gpioPin) {
// check which board we are running on
Platform platform = getPlatformType();
switch (platform) {
case INTEL_UP2:
#ifdef USING_GROVE_PI_SHIELD
gpioPin = 2 + 512; // A2 Connector (512 offset needed for the shield)
break;
#endif
default:
string unknownPlatformMessage =
"This sample uses the MRAA/UPM library for I/O access, "
"you are running it on an unrecognized platform.\n"
"You may need to modify the MRAA/UPM initialization code to "
"ensure it works properly on your platform.\n";
consoleMessage(unknownPlatformMessage);
}
return;
}

int main() {
// Check access permissions for the current user
// Can be commented out for targets with user level I/O access enabled
checkRoot();

int gpioPin = 2;
initPlatform(gpioPin);

#ifdef USING_GROVE_PI_SHIELD
addSubplatform(GROVEPI, "0");
#endif
// create an analog input object from MRAA using the pin
Aio* a_pin = new Aio(gpioPin);
if (a_pin == NULL) {
consoleMessage("Can't create mraa::Aio object, exiting");
return MRAA_ERROR_UNSPECIFIED;
}

// loop forever printing the input value every second
for (;;) {
uint16_t pin_value;
try {
// read the current input voltage
pin_value = a_pin->read();
} catch (const invalid_argument& readExc) {
// if incorrect voltage value input
cerr << "Invalid argument, exception thrown: " << readExc.what() << endl;
consoleMessage("MRAA cannot read pin value!");
return MRAA_ERROR_INVALID_PARAMETER;
}
cout << "analog input value " << pin_value << endl;
sleep(1);
}

return SUCCESS;
}
22 changes: 22 additions & 0 deletions Tools/IoTConnectionTools/analog-in/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"guid": "EEED3DAC-8D4E-4F4B-9C15-2B73CF0AC718",
"name": "Analog Input",
"categories": ["Toolkit/Intel® oneAPI IoT Toolkit/IoT Connection Tools"],
"description": "Demonstrate how to read an analog voltage value from an input pin using the Eclipse* MRAA library.",
"dependencies": ["pkg|mraa|https://mraa.io"],
"languages": [{"cpp":{}}],
"os": ["linux"],
"ciTests": {
"linux": [
{ "id": "analog-in",
"env": [],
"steps": [
"mkdir build",
"cd build",
"cmake ..",
"make"
]
}
]
}
}
53 changes: 53 additions & 0 deletions Tools/IoTConnectionTools/azure-iothub-telemetry/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
cmake_minimum_required(VERSION 2.8.11)
project(azure-iothub-telemetry)

if (CMAKE_VERSION VERSION_LESS "3.1")
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
set (CMAKE_C_FLAGS "--std=c99 ${CMAKE_C_FLAGS}")
if (NOT IN_OPENWRT)
set (CMAKE_CXX_FLAGS "--std=c++11 ${CMAKE_CXX_FLAGS}")
endif()
endif()
else()
set (CMAKE_C_STANDARD 99)
set (CMAKE_CXX_STANDARD 11)
endif()

set(iothub_c_files
cpp/iothub_ll_telemetry_sample.c
)

if(${use_sample_trusted_cert})
add_definitions(-DSET_TRUSTED_CERT_IN_SAMPLES)
include_directories(certs)
set(iothub_c_files certs/certs.c)
endif()

set(AZUREIOT_INC_FOLDER "." "/usr/include/azureiot" "/usr/include/azureiot/inc")

include_directories(${AZUREIOT_INC_FOLDER})

add_executable(azure-iothub-telemetry ${iothub_c_files})
target_link_libraries(azure-iothub-telemetry
iothub_client_mqtt_transport
iothub_client_amqp_transport
iothub_client_http_transport
iothub_client
umqtt
prov_auth_client
hsm_security_client
uhttp
aziotsharedutil
parson
uuid
pthread
curl
ssl
crypto
m
)

add_subdirectory(cpp)

add_custom_target (run ./azure-iothub-telemetry)

9 changes: 9 additions & 0 deletions Tools/IoTConnectionTools/azure-iothub-telemetry/License.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright (c) 2020 Intel Corporation
*
* This program and the accompanying materials are made available under the
* terms of the The MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
*/
33 changes: 33 additions & 0 deletions Tools/IoTConnectionTools/azure-iothub-telemetry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Azure IoTHub Telemetry

## Introduction
This is a simple sample you could use for a quick test of Azure cloud services.

## What it is
This project demonstrates how to send messages from a single device to Microsoft Azure IoT Hub via chosen protocol.

## Hardware requirements
The minimum requirements are for the device platform to support can be [found here](https://github.com/Azure/azure-iot-sdk-c).

## Software requirements
This sample is supported on Linux systems only.

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).

## Setup
Create and configure Azure IoTHub on [Microsoft Azure page](https://portal.azure.com/#home).
Detailed instructions are on [Microsoft website](https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-create-through-portal).

Paste the Device Connection String into the following line:
`static const char* connectionString = "[device connection string]"`

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):
`//#define SAMPLE_MQTT_OVER_WEBSOCKETS`
`//#define SAMPLE_AMQP`
`//#define SAMPLE_AMQP_OVER_WEBSOCKETS`
`//#define SAMPLE_HTTP`

Build and run the sample.

## Disclaimer
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.
Loading