-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from CreatorKit/dev
Merge dev to master
- Loading branch information
Showing
11 changed files
with
928 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Paths | ||
######## | ||
ADD_SUBDIRECTORY(src) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,75 @@ | ||
# relay-gateway | ||
Relay gateway application running on Creator Ci40 platform | ||
|
||
![Creator logo](docs/creatorlogo.png) | ||
|
||
# Relay gateway application | ||
|
||
## Overview | ||
Relay gateway application runs on Ci40 board with Relay click inserted in click interface. It acts as AwaL2MWM client and connects to **Creator Device Server**. | ||
|
||
The device server is a LWM2M management server designed to be implemented alongside third party cloud services to integrate M2M capability into an IoT application. The device server exposes two secure interfaces; REST API/HTTPs and LWM2M/CoAP. | ||
|
||
Relay gateway app defines IPSO 3201 (DigitalOutput) object and subscribes to it's resource 5550 (DigitalOutputState) change. | ||
Mobile app can control that resource by sending request to Device Server using REST API. | ||
Upon message receipt Ci40 app is changing relay state according to current IPSO resource value. | ||
|
||
Relay gateway application serves the purpose of: | ||
- It acts as Awalwm2m client | ||
- It communicates with device server | ||
|
||
| Object Name | Object ID | Resource Name | Resource ID | | ||
| :---- | :--------------| :-------------------| :-----------| | ||
| RelayDevice | 3201 | DigitalOutputState | 5550 | | ||
|
||
|
||
## Prerequisites | ||
### Hardware | ||
Relay click should be inserted on Ci40 in Mikrobus slot 1. | ||
|
||
### App provisioning | ||
Application needs valid certificate to communicate with Creator Device Server. Process of providing certificate for the app is called *provisioning*. | ||
|
||
You can obtain certificate by logging to creator developer console and selecting Identities > Certificates > Get Certificate. Then copy this certificate on Ci40 | ||
under | ||
/etc/config/relay_gateway.crt | ||
|
||
<br> | ||
This process is shown on image below | ||
|
||
![image](docs/provisioning.png) | ||
|
||
### Bootstrap URL | ||
App needs to know where your bootstrap server is. Put your bootstrap URL in application config file that can be found under | ||
/etc/config/relay_gateway.cfg | ||
|
||
## Application flow diagram | ||
![Relay-Gateway Controller Sequence Diagram](docs/relay-gateway-seq-diag.png) | ||
|
||
## Running Application on Ci40 board | ||
Relay gateway application can be started from the command line as: | ||
|
||
$ relay_gateway_appd | ||
|
||
Output looks something similar to this : | ||
|
||
Relay Gateway Application | ||
``` | ||
------------------------ | ||
Looking for certificate file under : /etc/config/relay_gateway.crt | ||
Certificate found. | ||
Observing IPSO object on path /3201/0/5550 | ||
Value of resource /3201/0/5550 changed to: 1 | ||
Changed relay state on Ci40 board to 1 | ||
Value of resource /3201/0/5550 changed to: 0 | ||
Changed relay state on Ci40 board to 0 | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
################################################################################################### | ||
# Copyright (c) 2016, Imagination Technologies Limited and/or its affiliated group companies | ||
# and/or licensors | ||
# | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without modification, are permitted | ||
# provided that the following conditions are met: | ||
# | ||
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions | ||
# and the following disclaimer. | ||
# | ||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of | ||
# conditions and the following disclaimer in the documentation and/or other materials provided | ||
# with the distribution. | ||
# | ||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to | ||
# endorse or promote products derived from this software without specific prior written | ||
# permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR | ||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY | ||
# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
# | ||
|
||
#!/bin/sh | ||
GPIO=$1 | ||
GPIODIR=/sys/class/gpio/gpio$GPIO | ||
|
||
#check if the gpio is already exported | ||
if [ ! -e "$GPIODIR" ] | ||
then | ||
echo $GPIO > /sys/class/gpio/export | ||
echo out > /sys/class/gpio/gpio$GPIO/direction | ||
echo 0 > /sys/class/gpio/gpio$GPIO/value | ||
fi | ||
|
||
if [ $? -ne 0 ];then | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
BOOTSTRAP_URL="coaps://deviceserver.flowcloud.systems:15684"; | ||
CERT_FILE_PATH="/etc/config/relay_gateway.crt"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/sh /etc/rc.common | ||
|
||
START=99 | ||
STOP=10 | ||
|
||
SERVICE_DAEMONIZE=1 | ||
SERVICE_WRITE_PID=1 | ||
|
||
APP=relay_gateway_appd | ||
LOGFILE=/var/log/$APP | ||
CONFIGFILE=/etc/config/relay_gateway.cfg | ||
|
||
start(){ | ||
sleep 5 | ||
service_start /usr/bin/$APP -l $LOGFILE -c $CONFIGFILE | ||
} | ||
|
||
stop() { | ||
service_stop /usr/bin/$APP | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Add executable targets | ||
######################## | ||
ADD_EXECUTABLE(relay_gateway_appd relay_gateway.c) | ||
# Add library targets | ||
##################### | ||
FIND_LIBRARY(LIB_AWA_STATIC libawa_static.so ${STAGING_DIR}/usr/lib) | ||
FIND_LIBRARY(LIB_CONFIG libconfig.so ${STAGING_DIR}/usr/lib) | ||
TARGET_LINK_LIBRARIES(relay_gateway_appd ${LIB_CONFIG} ${LIB_AWA_STATIC}) | ||
|
||
# Add install targets | ||
###################### | ||
INSTALL(TARGETS relay_gateway_appd RUNTIME DESTINATION bin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/*************************************************************************************************** | ||
* Copyright (c) 2016, Imagination Technologies Limited and/or its affiliated group companies | ||
* and/or licensors | ||
* | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are permitted | ||
* provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions | ||
* and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of | ||
* conditions and the following disclaimer in the documentation and/or other materials provided | ||
* with the distribution. | ||
* | ||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to | ||
* endorse or promote products derived from this software without specific prior written | ||
* permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR | ||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY | ||
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
/** | ||
* @file log.h | ||
* @brief Header file for logging. | ||
*/ | ||
|
||
#ifndef LOG_H | ||
#define LOG_H | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
#include <time.h> | ||
|
||
//! \{ | ||
#define LOG_FATAL (1) | ||
#define LOG_ERR (2) | ||
#define LOG_WARN (3) | ||
#define LOG_INFO (4) | ||
#define LOG_DBG (5) | ||
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) | ||
|
||
#define TIME_BUFFER_SIZE (32) | ||
//! \} | ||
|
||
/** Macro for printing logging message with current time, function and line no. */ | ||
#define DEBUG_PRINT \ | ||
do { \ | ||
time_t currentTime = time(NULL); \ | ||
char buffer[TIME_BUFFER_SIZE] = {0}; \ | ||
strftime(buffer, TIME_BUFFER_SIZE, "%x %X", localtime(¤tTime)); \ | ||
fprintf(g_debugStream,"[%s] %s:%d: ", buffer, __FILENAME__, __LINE__); \ | ||
} while (0) | ||
|
||
/** Macro for logging message at the specified level. */ | ||
#define LOG(level, ...) \ | ||
do { \ | ||
if (level <= g_debugLevel) \ | ||
{ \ | ||
if (g_debugStream == NULL) \ | ||
g_debugStream = stdout; \ | ||
fprintf(g_debugStream, "\n"); \ | ||
if (g_debugLevel == LOG_DBG) \ | ||
{ \ | ||
DEBUG_PRINT; \ | ||
} \ | ||
fprintf(g_debugStream, __VA_ARGS__); \ | ||
fprintf(g_debugStream, "\n"); \ | ||
fflush(g_debugStream); \ | ||
} \ | ||
} while (0) | ||
|
||
/** Output stream to dump logs. */ | ||
extern FILE *g_debugStream; | ||
/** Debug level for logs. */ | ||
extern int g_debugLevel; | ||
|
||
|
||
#endif /* LOG_H */ |
Oops, something went wrong.