Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contiki awa support #90

Open
wants to merge 4 commits into
base: creator
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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 apps/awa-lwm2m/Makefile.awa-lwm2m
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
AWA_URL?=https://github.com/FlowM2M/AwaLWM2M.git
AWA_VERSION?=0.2.5
AWA_DIR:=$(dir $(filter %/Makefile.awa-lwm2m,$(MAKEFILE_LIST)))AwaLWM2M

CFLAGS += -I"$(AWA_DIR)"/api/include

CLEAN += "$(AWA_DIR)"

ifneq ($(MAKECMDGOALS),clean)
-include $(AWA_DIR)/.git-cloned
$(AWA_DIR)/.git-cloned:
git clone "$(AWA_URL)" -b "$(AWA_VERSION)" "$(AWA_DIR)"
touch $@
endif

define AWAMODULE
-include $(1)/$(2)/Makefile.$(2)
awa-lwm2m_src += $$($(2)_src)
APPDS += $(1)/$(2)
endef

AWACORE=client common erbium
AWALIB=b64 hmac xml
$(foreach c,$(AWACORE),$(eval $(call AWAMODULE,$(AWA_DIR)/core/src,$(c))))
$(foreach c,$(AWALIB),$(eval $(call AWAMODULE,$(AWA_DIR)/lib,$(c))))
7 changes: 7 additions & 0 deletions examples/awa-lwm2m/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// See http://go.microsoft.com/fwlink/?LinkId=827846
{
"recommendations": [
"ms-vscode.cpptools",
"EditorConfig.EditorConfig"
]
}
20 changes: 20 additions & 0 deletions examples/awa-lwm2m/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb-mi",
"request": "launch",
"name": "Launch Program (SSH)",
"target": "./awa-lwm2m.minimal-net",
"cwd": "${workspaceRoot}",
"ssh": {
"forwardX11": false,
"host": "127.0.0.1",
"cwd": "/build/examples/awa-lwm2m",
"user": "root",
"password": "",
"port": 1022
}
}
]
}
11 changes: 11 additions & 0 deletions examples/awa-lwm2m/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM creatordev/docker-nat64-client

RUN curl -sL http://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add /dev/stdin
ADD docker/lldb.list /etc/apt/sources.list.d/
RUN apt-get update && \
apt-get install -yq openssh-server gdbserver pwgen lldb-4.0 && \
ln -s /usr/bin/lldb-mi-4.0 /usr/bin/lldb-mi
ADD docker/run.sh /
RUN chmod +x /run.sh

CMD ["/run.sh","bash"]
62 changes: 62 additions & 0 deletions examples/awa-lwm2m/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
CONTIKI_PROJECT=awa-lwm2m
CONTIKI=../..
TARGET?=mikro-e
PAN_ID=0xaaaa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not hardcode the pan ids!

VERSION?=0.2.5

ifeq ($(TARGET),micro-e)
PROJECT_CONF_H:=project-conf.h
all: $(CONTIKI_PROJECT).hex
else
PROJECT_CONF_H:=project-conf-$(TARGET).h
endif

ifeq ($(TARGET),minimal-net)
ifndef TAP_PREFIX
$(error Please define TAP_PREFIX. See HARD_CODED_ADDRESS at https://github.com/contiki-os/contiki/blob/master/platform/minimal-net/contiki-conf.h)
endif
UIP_CONF_RPL=0
CFLAGS += -DUIP_CONF_ND6_DEF_MAXDADNS=0
CFLAGS += '-DHARD_CODED_ADDRESS="$(TAP_PREFIX)"'
CFLAGS += -DDTLS_MAX_BUF=1000
#CFLAGS += -DVERBOSE_DEBUG=1 -DDEBUG=1
endif

CFLAGS += '-DPROJECT_CONF_H="$(PROJECT_CONF_H)"' '-DVERSION="$(VERSION)"'
CFLAGS += -Wall -Wno-pointer-sign
CFLAGS += -DLWM2M_CLIENT -g -DDTLS_PEERS_NOHASH=1
CFLAGS += -DUIP_CONF_BUFFER_SIZE=4096

ifeq ($(PSK_IDENTITY)x,x)
$(error Please define PSK_IDENTITY)
endif
ifeq ($(PSK_SECRET_KEY)x,x)
$(error Please define PSK_SECRET_KEY)
endif
PSK_BINARY_KEY:=$(shell echo $(PSK_SECRET_KEY) | sed -e 's.\([0-9A-F][0-9A-F]\).0x\1 .g' -e 's. 0x.,0x.g')

$(CONTIKI_PROJECT).co: CFLAGS += '-DIDENTITY="$(PSK_IDENTITY)"' '-DSECRET_KEY="$(PSK_SECRET_KEY)"' '-DBINARY_KEY=$(PSK_BINARY_KEY)'

APPS += awa-lwm2m
APPS += tinydtls/aes tinydtls/sha2 tinydtls/ecc tinydtls

CONTIKI_WITH_IPV6 = 1
CONTIKI_WITH_RPL = 0
USE_CA8210 = 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

USE_CA8210 has been dropped in 3f12666. Moreover being the example in generic directory it should work non Cascoda platforms.

RESOLV_CONF_SUPPORTS_MDNS = 0
UIP_CONF_TCP = 1
TINYDTLS = 1
USE_SERIAL_PADS = 0

CFLAGS += -I $(CONTIKI)/platform/$(TARGET)
CFLAGS += -fno-short-double
LDFLAGS += -Wl,--defsym,_min_heap_size=64000

SMALL=0

all: $(CONTIKI_PROJECT)

$(CONTIKI_PROJECT).hex: $(CONTIKI_PROJECT)
xc32-bin2hex $(CONTIKI_PROJECT).$(TARGET)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example app here should be TARGET independent. you cannot hardcode it only for xc32 cross compiler.


include $(CONTIKI)/Makefile.include
92 changes: 92 additions & 0 deletions examples/awa-lwm2m/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# AwaBootstrap

This app is an LWM2M client using Contiki with TinyDTLS.

By default it will build for a Mikro-Electronica Clicker board. To
build that, you'll need to ensure your build host has the relevant
tools installed. This is usually built from an ubuntu host.

## Running under Docker

The app can also be built to run on a linux host, and can be built
and run under Docker. The only requirement for this is to have

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whether we want to add dockerized environment, .vscode related files into generic contiki examples. Generally all these examples should be built on linux host machine, with all the supported TARGETS. if there is something TARGET specific example then it should be moved to platforms/$(TARGET)/apps.

CI or dockerized test setup may be sit in a different repo but not in contiki examples. It needs a design discussion if you want to push inside the contiki examples.

docker v1.12 (or better) and docker-compose v1.9.0 (or better) installed.
The included [`docker-compose.yml`](docker-compose.yml) has
NAT64 (tayga) and DNS64 (totd) pre-configured. See
[github.com/CreatorDev/docker-nat64](https://github.com/CreatorDev/docker-nat64)
for more details on this setup.

Edit [`docker-compose.yml`](docker-compose.yml) to set your `PSK_IDENTITY`
and `PSK_SECRET_KEY`. Then:

$ docker-compose up -d
$ docker exec -ti awabootstrap_contiki_1 bash

Inside container, first try pinging an IPv4 host by name. You'll get
back an IPv6 address and the pings should work.

# ping6 deviceserver.creatordev.io

Then build it:

# cd /build
# make
# ./awa-lwm2m.minimal-net

## Debugging

You can also debug this from your development workstation using vscode. The [`launch.json`](.vscode/launch.json)
file in this repo contains most of what you need, but you'll need to fill in the
following for your system:

| launch.json entry | description |
|---|---|
| `configurations.ssh.host` | a hostname or IP address for your docker host |
| `configurations.ssh.password` | the root password for the container - see below|

The root password is set to a random password on first boot. You can see this
from the docker host by checking the docker logs - run the following on your
docker host:

$ docker logs awalwm2m_contiki_1 | grep PASS

Also, make sure you've installed the ["recommended"](https://code.visualstudio.com/docs/editor/extension-gallery#_workspace-recommended-extensions)
vscode extensions.

Once that's all in place, you should be able to run this executable just by hitting
`F5` inside vscode. See also the [other default keyboard shortcuts](https://code.visualstudio.com/docs/customization/keybindings#_debug).

## IPv6 and Contiki for the uninitiated

- RPL is the IPv6 meshing protocol. It can be disabled in Contiki with

CFLAGS += -DUIP_CONF_IPV6_RPL=0

- Contiki uses [RFC4862](https://tools.ietf.org/search/rfc4862),
"IPv6 Stateless Address Autoconfiguration"

- To discover all IP addresses

ping6 [ -Ieth0 ] ff02::1

## Debug (**_More!_**)

- Uncomment the following line from [`Makefile`](Makefile):

#CFLAGS += -DVERBOSE_DEBUG=1 -DDEBUG=1

- To get debug from TinyDTLS, edit the end of [`Makefile.tinydtls`](tinydtls/tinydtls/Makefile.tinydtls)
as follows:

# This activates debugging support
#CFLAGS += -DNDEBUG
tinydtls_src += dtls_debug.c

- To get some more debug from the Contiki IP stack, you might want to set DEBUG
in the following source files:

//#define DEBUG DEBUG_NONE
#define DEBUG DEBUG_FULL

- [core/net/ipv6/uip-ds6.c](https://github.com/CreatorDev/contiki/blob/b0390e3/core/net/ipv6/uip-ds6.c#L53)
- [core/net/ipv6/uip-ds6-route.c](https://github.com/CreatorDev/contiki/blob/b0390e3/core/net/ipv6/uip-ds6-route.c#L76)
Loading