Skip to content

Commit

Permalink
Added Zolertia Orion ethernet router with active POE support
Browse files Browse the repository at this point in the history
  • Loading branch information
alignan committed Dec 29, 2016
1 parent 9bb6286 commit 579620c
Show file tree
Hide file tree
Showing 23 changed files with 1,870 additions and 1 deletion.
56 changes: 56 additions & 0 deletions examples/zolertia/zoul/orion/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
RE-Mote IP64 README file
========================

This example shows how to use the Zolertia's Orion Ethernet router, based on the Zoul and ENC28J60 modules, with active POE support.

IP64 router
-----------------
The router packs a built-in webserver and optionally can run on 2.4GHz or with the Sub-1GHz radio interface. In the `project-conf.h` file you can alternatively enable one or another as follows:

* RF 2.4GHz (cc2538 built-in)

````
#define NETSTACK_CONF_RADIO cc2538_rf_driver
#define ANTENNA_SW_SELECT_DEF_CONF ANTENNA_SW_SELECT_2_4GHZ
````

* RF Sub-1GHz (CC1200)

````
#define NETSTACK_CONF_RADIO cc1200_driver
#define ANTENNA_SW_SELECT_DEF_CONF ANTENNA_SW_SELECT_SUBGHZ
````

To compile and flash run:

````
cd ip64-router
make TARGET=zoul BOARD=router ip64-router.upload
````

As default we enable the `DHCP` support for autoconfiguration. Just connect to a DHCP-enabled device to obtain an IPv4 IP address and that's it!.

HTTP client examples
-----------------

There are available 2 examples ready to use using the `http-socket` library:

* The `client` example just makes a HTTP `GET` request to a know page and retrieves
the result.

* The `ifttt-client` example sends a HTTP `POST` request to [IFTTT](https://ifttt.com/recipes) whenever the user button is pressed, building an Internet button to connect to several channels and applications, such as `Drive`, `Evernote` and many others.

To configure the `IFTTT` demo just edit the `project-conf.h` file and change the name of the event and write your API key:

````
#define IFTTT_EVENT "button"
#define IFTTT_KEY "XXXXXX"
````

To compile and flash:

````
cd client
make TARGET=zoul ifttt-client.upload
````

12 changes: 12 additions & 0 deletions examples/zolertia/zoul/orion/client/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CFLAGS+=-DPROJECT_CONF_H=\"project-conf.h\"
CONTIKI_PROJECT = client ifttt_client
all: $(CONTIKI_PROJECT)

BOARD = orion

MODULES += core/net/http-socket

WITH_IP64 = 1

CONTIKI = ../../../../..
include $(CONTIKI)/Makefile.include
139 changes: 139 additions & 0 deletions examples/zolertia/zoul/orion/client/client.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* Copyright (c) 2016, Zolertia - http://www.zolertia.com
* 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.
*/
/*---------------------------------------------------------------------------*/
#include "contiki-net.h"
#include "http-socket.h"
#include "ip64-addr.h"
#include "dev/leds.h"
#include "rpl.h"
#include <stdio.h>
/*---------------------------------------------------------------------------*/
static struct http_socket s;
static char data_received[HTTP_CLIENT_BUFFER_LEN];
static int bytes_received = 0;
static int restarts;
static struct ctimer reconnect_timer;
static const char *url = "http://httpbin.org/ip";
/*---------------------------------------------------------------------------*/
static void callback(struct http_socket *s, void *ptr,
http_socket_event_t e,
const uint8_t *data, uint16_t datalen);
/*---------------------------------------------------------------------------*/
PROCESS(http_example_process, "HTTP Example");
AUTOSTART_PROCESSES(&http_example_process);
/*---------------------------------------------------------------------------*/
static void
reconnect(void *dummy)
{
rpl_set_mode(RPL_MODE_MESH);
http_socket_get(&s, url, 0, 0, callback, NULL);
}
/*---------------------------------------------------------------------------*/
static void
restart(void)
{
int scale;
restarts++;
printf("Number of restarts %d\n", restarts);

scale = restarts;
if(scale > 5) {
scale = 5;
}
ctimer_set(&reconnect_timer, random_rand() % ((CLOCK_SECOND * 10) << scale),
reconnect, NULL);
}
/*---------------------------------------------------------------------------*/
static void
callback(struct http_socket *s, void *ptr,
http_socket_event_t e,
const uint8_t *data, uint16_t datalen)
{
uint8_t i;

if(e == HTTP_SOCKET_ERR) {
printf("HTTP socket error\n");
} else if(e == HTTP_SOCKET_TIMEDOUT) {
printf("HTTP socket error: timed out\n");
restart();
} else if(e == HTTP_SOCKET_ABORTED) {
printf("HTTP socket error: aborted\n");
restart();
} else if(e == HTTP_SOCKET_HOSTNAME_NOT_FOUND) {
printf("HTTP socket error: hostname not found\n");
restart();
} else if(e == HTTP_SOCKET_CLOSED) {

if(bytes_received) {
printf("HTTP socket received data:\n\n");
for(i=0; i<bytes_received; i++) {
printf("%c", data_received[i]);
}
printf("\n");
bytes_received = 0;
}

} else if(e == HTTP_SOCKET_DATA) {
strcat(data_received, (const char *)data);
bytes_received += datalen;
printf("HTTP socket received %d bytes of data\n", datalen);
}
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(http_example_process, ev, data)
{
static struct etimer et;
uip_ip4addr_t ip4addr;
uip_ip6addr_t ip6addr;

PROCESS_BEGIN();

uip_ipaddr(&ip4addr, 8, 8, 8, 8);
ip64_addr_4to6(&ip4addr, &ip6addr);
uip_nameserver_update(&ip6addr, UIP_NAMESERVER_INFINITE_LIFETIME);

etimer_set(&et, CLOCK_SECOND * 20);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

http_socket_init(&s);
http_socket_get(&s, url, 0, 0, callback, NULL);
leds_on(LEDS_RED);
restarts = 0;
etimer_set(&et, CLOCK_SECOND);

while(1) {
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
etimer_reset(&et);
}

PROCESS_END();
}
/*---------------------------------------------------------------------------*/
154 changes: 154 additions & 0 deletions examples/zolertia/zoul/orion/client/ifttt-client.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*
* Copyright (c) 2016, Zolertia - http://www.zolertia.com
* 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.
*/
/*---------------------------------------------------------------------------*/
#include "contiki-net.h"
#include "http-socket.h"
#include "ip64-addr.h"
#include "dev/leds.h"
#include "rpl.h"
#include "dev/button-sensor.h"
#include <stdio.h>
/*---------------------------------------------------------------------------*/
static struct http_socket s;
static char data_received[HTTP_CLIENT_BUFFER_LEN];
static char url_buffer[HTTP_CLIENT_BUFFER_LEN];
static int bytes_received = 0;
static int restarts;
static struct ctimer reconnect_timer;
/*---------------------------------------------------------------------------*/
static void callback(struct http_socket *s, void *ptr,
http_socket_event_t e,
const uint8_t *data, uint16_t datalen);
/*---------------------------------------------------------------------------*/
PROCESS(http_example_process, "IFTTT HTTP Example");
AUTOSTART_PROCESSES(&http_example_process);
/*---------------------------------------------------------------------------*/
static void
reconnect(void *dummy)
{
rpl_set_mode(RPL_MODE_MESH);
leds_on(LEDS_GREEN);
http_socket_post(&s, url_buffer, NULL, 0, NULL, callback, NULL);
}
/*---------------------------------------------------------------------------*/
static void
restart(void)
{
int scale;
restarts++;
printf("Number of restarts %d\n", restarts);
leds_off(LEDS_GREEN);

scale = restarts;
if(scale > 5) {
scale = 5;
}

ctimer_set(&reconnect_timer, random_rand() % ((CLOCK_SECOND * 10) << scale),
reconnect, NULL);
}
/*---------------------------------------------------------------------------*/
static void
callback(struct http_socket *s, void *ptr,
http_socket_event_t e,
const uint8_t *data, uint16_t datalen)
{
uint8_t i;

if(e == HTTP_SOCKET_ERR) {
printf("HTTP socket error\n");
} else if(e == HTTP_SOCKET_TIMEDOUT) {
printf("HTTP socket error: timed out\n");
restart();
} else if(e == HTTP_SOCKET_ABORTED) {
printf("HTTP socket error: aborted\n");
restart();
} else if(e == HTTP_SOCKET_HOSTNAME_NOT_FOUND) {
printf("HTTP socket error: hostname not found\n");
restart();
} else if(e == HTTP_SOCKET_CLOSED) {

if(bytes_received) {
printf("HTTP socket received data:\n\n");
for(i=0; i<bytes_received; i++) {
printf("%c", data_received[i]);
}
printf("\n");
bytes_received = 0;
leds_off(LEDS_GREEN);
}

} else if(e == HTTP_SOCKET_DATA) {
strcat(data_received, (const char *)data);
bytes_received += datalen;
printf("HTTP socket received %d bytes of data\n", datalen);
}
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(http_example_process, ev, data)
{
static struct etimer et;
uip_ip4addr_t ip4addr;
uip_ip6addr_t ip6addr;

PROCESS_BEGIN();

uip_ipaddr(&ip4addr, 8, 8, 8, 8);
ip64_addr_4to6(&ip4addr, &ip6addr);
uip_nameserver_update(&ip6addr, UIP_NAMESERVER_INFINITE_LIFETIME);

etimer_set(&et, CLOCK_SECOND * 20);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

memset(url_buffer, 0, HTTP_CLIENT_BUFFER_LEN);
snprintf(url_buffer, HTTP_CLIENT_BUFFER_LEN,
"http://maker.ifttt.com/trigger/%s/with/key/%s",
IFTTT_EVENT, IFTTT_KEY);

http_socket_init(&s);

restarts = 0;

while(1) {
PROCESS_YIELD();
if((ev == sensors_event) && (data == &button_sensor)) {
if(button_sensor.value(BUTTON_SENSOR_VALUE_TYPE_LEVEL) ==
BUTTON_SENSOR_PRESSED_LEVEL) {
leds_on(LEDS_GREEN);
printf("Button pressed! sending a POST to IFTTT\n");
http_socket_post(&s, url_buffer, NULL, 0, NULL, callback, NULL);
}
}
}

PROCESS_END();
}
/*---------------------------------------------------------------------------*/
Loading

0 comments on commit 579620c

Please sign in to comment.