Skip to content

Commit

Permalink
examples/ambient_cli: Add Ambient CLI application
Browse files Browse the repository at this point in the history
Add new example to demonstrate uploading any data to the Ambient
service. This application uses the Ambient library.
  • Loading branch information
SPRESENSE committed Mar 9, 2022
1 parent 48858ac commit b65ac37
Show file tree
Hide file tree
Showing 5 changed files with 464 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples/ambient_cli/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#

config EXAMPLES_AMBIENT_CLI
tristate "Ambient CLI example"
default n
depends on SYSTEM_AMBIENT
---help---
Enable the Ambient CLI application

if EXAMPLES_AMBIENT_CLI

config EXAMPLES_AMBIENT_CLI_PROGNAME
string "Program name"
default "ambient_cli"
---help---
This is the name of the program that will be use when the NSH ELF
program is installed.

config EXAMPLES_AMBIENT_CLI_PRIORITY
int "Ambient CLI task priority"
default 100

config EXAMPLES_AMBIENT_CLI_STACKSIZE
int "Ambient CLI stack size"
default DEFAULT_TASK_STACKSIZE

endif
38 changes: 38 additions & 0 deletions examples/ambient_cli/Make.defs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
############################################################################
# examples/ambient_cli/Make.defs
#
# Copyright 2022 Sony Semiconductor Solutions Corporation
#
# 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 Sony Semiconductor Solutions Corporation 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 OWNER 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.
#
############################################################################

ifneq ($(CONFIG_EXAMPLES_AMBIENT_CLI),)
CONFIGURED_APPS += ambient_cli
endif
55 changes: 55 additions & 0 deletions examples/ambient_cli/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
############################################################################
# examples/ambient_cli/Makefile
#
# Copyright 2022 Sony Semiconductor Solutions Corporation
#
# 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 Sony Semiconductor Solutions Corporation 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 OWNER 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.
#
############################################################################

include $(APPDIR)/Make.defs
include $(SDKDIR)/Make.defs

# Ambient CLI built-in application info

PROGNAME = $(CONFIG_EXAMPLES_AMBIENT_CLI_PROGNAME)
PRIORITY = $(CONFIG_EXAMPLES_AMBIENT_CLI_PRIORITY)
STACKSIZE = $(CONFIG_EXAMPLES_AMBIENT_CLI_STACKSIZE)
MODULE = $(CONFIG_EXAMPLES_AMBIENT_CLI)

# Ambient CLI example

ASRCS =
CSRCS =
MAINSRC = ambient_cli_main.c

CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" \
"$(SDKDIR)$(DELIM)system$(DELIM)ambient"}

include $(APPDIR)/Application.mk
104 changes: 104 additions & 0 deletions examples/ambient_cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Examples / `ambient_cli` Ambient CLI application

## Description

The `ambient_cli` is an application to demonstrate uploading any data to the
Ambient service. Ambient is an IoT data visualization service. It receives,
stores, and visualizes sensor data sent from microcontrollers and other devices.

https://ambidata.io/

To use Ambient service, you need to register as a user.

Please see below for more details.

https://ambidata.io/docs/gettingstarted/

The procedure to use the Ambient service is as below:

1. User registration (free of charge)
2. Channel generation
3. Microcontroller-side programming
4. Data transmission
5. Visualization (graphing)

## How to configuration and build

This application uses an Ambient library and any network feature.
The explanation shows an example using LTE network.

```bash
$ cd spresense/sdk
$ ./tools/config.py feature/lte examples/ambient_cli
$ make
```

## Running this application


The first step is to connect to the LTE network.

```bash
*** Usage ***
nsh> lte_sysctl
lte_sysctl: missing required argument(s)

USAGE: lte_sysctl command
[-a <apn_name>] [-i <ip_type>] [-v <auth_type>] [-u <user_name>] [-p <password>] [-r <rat_type>] start
-a: APN name
-i: IP type 0=IPv4, 1=IPv6, 2=IPv4 and IPv6, 3=Non-IP
-v: Authenticaion type 0=NONE, 1=PAP, 2=CHAP
-u: User name for authenticaion
-p: Password for authenticaion
-r: Radio Access Technology type M1=CAT-M1, NB=NB-IoT
stop
stat
[-h]: Show this message

*** Specify the appropriate parameters based on your SIM and start ***
nsh> lte_sysctl -a <apn_name> -u <user_name> -p <password> start

*** Enable the network interface ***
nsh> ifup eth0
ifup eth0...OK

*** You can confirm if your board is connected to the network ***
nsh> ifconfig
```
The next step uses the channel ID and write key you generated on the Ambient server.
```bash
*** Usage ***
nsh> ambient_cli -h
Usage: ambient_cli [-c <channel>] [-w <write_key>] field=data ...
Options:
-c: channel ID
-w: write key string
field=data: field is 1~10. data is string to be sent.
```
For example, it shows a command in the following cases.
- channelID : 123456
- write_key : 1234567890123456
- send data (field, value) : (1, 0.55), (2, 0.67)
```bash
nsh> ambient_cli -c 123456 -w 1234567890123456 1=0.55 2=0.67
```
You can edit an `ambient_cli_main.c` and pre-set your own channel and write key.
Then you do not need to specify `-c` and `-w` options of the `ambient_cli` arguments.
```c
#define MY_CHANNEL 123456
#define MY_WRITEKEY "1234567890123456"
```
```bash
nsh> ambient_cli 1=0.55 2=0.67
```
Finally, you will view the sent data on the Ambient server.
Loading

0 comments on commit b65ac37

Please sign in to comment.