Adding the avr-rss2 platform based on AtMega256RFR2
This commit is contained in:
parent
d3980668ee
commit
ce8e87d60e
91 changed files with 9349 additions and 0 deletions
12
platform/avr-rss2/examples/ipv6/sensd_client/Makefile
Normal file
12
platform/avr-rss2/examples/ipv6/sensd_client/Makefile
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
|
||||
|
||||
all: sensd_client server
|
||||
CONTIKI=../../../../..
|
||||
|
||||
ifdef PERIOD
|
||||
CFLAGS+=-DPERIOD=$(PERIOD)
|
||||
endif
|
||||
|
||||
CONTIKI_WITH_IPV6 = 1
|
||||
include $(CONTIKI)/Makefile.include
|
222
platform/avr-rss2/examples/ipv6/sensd_client/README.md
Normal file
222
platform/avr-rss2/examples/ipv6/sensd_client/README.md
Normal file
|
@ -0,0 +1,222 @@
|
|||
Contiki client for sensd
|
||||
========================
|
||||
|
||||
Sensd README describes the concept. sensd code is on github.
|
||||
|
||||
|
||||
sensd - A WSN Internet GW, hub, agent, proxy & cloud
|
||||
====================================================
|
||||
|
||||
Authors
|
||||
--------
|
||||
Robert Olsson <robert@radio-sensors.com>
|
||||
Jens Laas <jens.laas@uadm.uu.se>
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
Abstract
|
||||
--------
|
||||
We've outlined, designed and implemented and very simple concept for WSN
|
||||
data sharing, including data collection, storage and retrieval using
|
||||
standard text tools. The concept restricts Internet access to WSN
|
||||
motes and acts agent not to expose motes directly for robustness and
|
||||
security reasons. Low level, physical or link WSN protocol can be used.
|
||||
including 6lowpan, RIME etc and any type of Radio Duty Cycling (RDC).
|
||||
sensd works on the application layer. A TCP connection initiates an
|
||||
implicit "subscribe". The M2P model is currently supported.
|
||||
|
||||
Key concepts
|
||||
------------
|
||||
|
||||
* Agent. sensd works as an agent and does not allow direct Internet
|
||||
access to motes. Recall motes are constrained in most aspects and
|
||||
can not support many connections, has weak security etc.
|
||||
|
||||
* Hub. Share the data from the root or sink node over TCP. In effect sensor
|
||||
data can be sent over Internet to be shared over among TCP active listeners.
|
||||
The TCP connection initiates an implicit "subscribe".
|
||||
|
||||
* Proxy. The support proxy functions over ipv4 and well as ipv6. Sensd can
|
||||
forward to a proxy on a public IP. The typical case is when GW is behind
|
||||
a NAT.
|
||||
|
||||
* WSN RP "rendez-vous point". A concepts where data from various WSN nets
|
||||
are merged. This models a "cloud service" functionality for WSN networks.
|
||||
sensd can be used both to forward data to RP. It can also work as the RP.
|
||||
RP receiving WSN data and allowing multiple TCP listeners.
|
||||
|
||||
* All programs are written C, script in Java and bash. Designed for small
|
||||
footprint and with minimal dependencies. sensd runs on Raspberry Pi and
|
||||
Openwrt.
|
||||
|
||||
* This work introduces a simple tag format for sensor data. The overall
|
||||
idea is that data tagging is an "agreement" between producers and consumer.
|
||||
Tags are simple are description of the data. Example T=25.2. where T=
|
||||
is the tag 25.2 the value. Most likely this a temperature. But we
|
||||
can't be sure since we don't know since this is an agreement between
|
||||
the producer and the consumer. Tags are also used for identification.
|
||||
Example tags, E64= Where globally unique ID can used. Another more
|
||||
relaxed example is TXT= a user description. See docs.
|
||||
|
||||
* Geotagging and timestamping is supported via tags.
|
||||
|
||||
* Ecosystem support. There are telphone apps to for data monitoring and
|
||||
and plotting. Android app can act as WSN-agent and forward to proxy/RP.
|
||||
|
||||
* The concept also includes a mapping to URI (Unified Resource Identifier)
|
||||
to form a WSN caching server similar to CoAP using http-proxy.
|
||||
|
||||
* Copyright. Open-Source via GPL. Projecet used github.com
|
||||
|
||||
|
||||
Introduction
|
||||
------------
|
||||
|
||||
This is collection of software to implement data monitoring and data collection
|
||||
from WSN Wireless Sensor Networks. The goal is to have a very simple,
|
||||
straight-forward and robust framework.
|
||||
|
||||
The scenario: One or several motes is connected to USB or serial port to gather
|
||||
received information from connected WSN motes. Data can be visualized in
|
||||
several ways.
|
||||
|
||||
* Sensor data report can be transmitted and propagated throughout the
|
||||
Internet. sensd acts as server and sends incoming report to active
|
||||
listeners.
|
||||
|
||||
* Data is kept in ASCII with tagging and ID information. Data is conveniently
|
||||
handled, copied and viewed with standard text utilities of your OS.
|
||||
|
||||
* Last mote report is cached into the file system suitable for URI use. The
|
||||
Format is SID/TAG. Typical tags are EUI64 and unique serial numbers. The
|
||||
different TAGS are left for mote user to define. Although the TAGS used in
|
||||
our example setup are included in this draft for example purposes.
|
||||
|
||||
|
||||
Both formats can easily be stored or linked directly in web tree to form a
|
||||
URI to format WSN logging/datafile or caching service.
|
||||
|
||||
A daemon that reads WSN mote reports from USB/serial and stores data in a ASCII
|
||||
data file. Default is located at _/var/log/sensors.dat_
|
||||
|
||||
Addtional components
|
||||
--------------------
|
||||
|
||||
* seltag [More info] (https://github.com/herjulf/sensd/blob/master/seltag/README.md)
|
||||
|
||||
* js A set of Java-scripts can plot, print and visualize sensor data from
|
||||
sensd directly in your web-browser.
|
||||
|
||||
* documentation and sample files. [More info] (https://github.com/herjulf/sensd/blob/master/seltag/README.md)
|
||||
|
||||
* Read Sensors Android app. [Source Code] (https://github.com/herjulf/Read-Sensors)
|
||||
|
||||
|
||||
Datafile logging
|
||||
----------------
|
||||
|
||||
Below is and example of the anatomy of a sensors.dat file we are currently using in our WSN
|
||||
data collection networks.
|
||||
|
||||
2012-05-22 14:07:46 UT=1337688466 ID=283c0cdd030000d7 PS=0 T=30.56 T_MCU=34.6 V_MCU=3.08 UP=2C15C V_IN=4.66
|
||||
|
||||
2012-05-22 14:11:41 UT=1337688701 ID=28a9d5dc030000af PS=0 T=36.00 V_MCU=2.92 UP=12C8A0 RH=42.0 V_IN=4.13 V_A1=3.43 [ADDR=0.175 SEQ=33 RSSI=21 LQI=255 DRP=1.00]
|
||||
|
||||
Each line is a mote report. They start with date and time and are followed by a set of
|
||||
tags. The tags is different for different motes. In other words they can
|
||||
send different data. Essential is the ID which should be unique for each mote.
|
||||
|
||||
The information with brackets is information generated by the receiving mote
|
||||
and is not a part the motes data. Typically RSSI (Receiver Signal Strength
|
||||
Indicator) and LQI (Link Quality Indicator)
|
||||
|
||||
|
||||
Internet sensor data
|
||||
--------------------
|
||||
|
||||
Start sensd with the `-report` option. This enables reports to be transmitted
|
||||
over IP to remote listeners. Default TCP port 1234.
|
||||
|
||||
Server side example:
|
||||
|
||||
sensd -report -p 1234 -D /dev/ttyUSB0
|
||||
|
||||
Client side. Example using netcat:
|
||||
|
||||
nc server-ip 1234
|
||||
|
||||
URI format
|
||||
----------
|
||||
|
||||
URI (Unified Resource Identifier) displays the node ID and the tags in a file tree.
|
||||
It is easy to export this into a web tree to form a URI similar to a CoAP gateway.
|
||||
|
||||
Example: In our case we have a unique sensor ID followed by the different data
|
||||
fields represented by "tags".
|
||||
|
||||
/tmp/WSN1-GW1/281a98d20200004a:
|
||||
DRP ID LQI PS RH RSSI SEQ T V_IN V_MCU ADDR
|
||||
|
||||
/tmp/WSN1-GW1/28be51ce02000031:
|
||||
DRP ID LQI PS RH RSSI SEQ T UP V_IN V_MCU ADDR
|
||||
|
||||
Read Temp from a sensor:
|
||||
|
||||
cat /tmp/WSN1-GW1/281a98d20200004a/T
|
||||
19.44
|
||||
|
||||
And it's very easy to link this tree into a web-server.
|
||||
|
||||
GPS support
|
||||
-----------
|
||||
|
||||
Positioning support has been added via GPS device connected to serial
|
||||
or USB port. Tags added when enabled GWGPS_LON & GWGPS_LAT.
|
||||
GPS code from. https://github.com/herjulf/gps_simple
|
||||
|
||||
Getting the source and building
|
||||
-------------------------------
|
||||
|
||||
Code is stored in github. Typically procedure below is the very straight-
|
||||
forward unix way:
|
||||
|
||||
git clone http://github.com/herjulf/sensd
|
||||
cd sensd
|
||||
make
|
||||
|
||||
Put your binaries after your preference:
|
||||
|
||||
Pre-built binary versions
|
||||
--------------------------
|
||||
|
||||
For x86:
|
||||
Sensd and friends are available in Bifrost/Linux packages. Those packages are
|
||||
statically linked and can be used on most x86 Linuxes. 32-bit compiled.
|
||||
|
||||
http://ftp.sunet.se/pub/Linux/distributions/bifrost/download/opt/opt-sensd-2.3-1.tar.gz
|
||||
|
||||
|
||||
Use
|
||||
---
|
||||
|
||||
The WSN data logging and caching concept is in actual use with Contiki, RIME
|
||||
broadcast application.
|
||||
|
||||
Tips
|
||||
----
|
||||
|
||||
One can use netcat to listen to reports:
|
||||
|
||||
Example:
|
||||
|
||||
nc radio-sensors.com 1235
|
||||
|
||||
To save in file use nohup:
|
||||
|
||||
nohup nc radio-sensors.com 1235 > /var/log/sensors.dat
|
||||
|
||||
As sensd used TCP and ASCII encoding. tetlnet and web-browsers can be used
|
||||
as well.
|
||||
|
||||
|
51
platform/avr-rss2/examples/ipv6/sensd_client/project-conf.h
Normal file
51
platform/avr-rss2/examples/ipv6/sensd_client/project-conf.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2015, RAdio Sensors AB, Uppsala Sweden
|
||||
* 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 Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Project specific configuration defines for example
|
||||
*
|
||||
* \author
|
||||
* Robert Olsson <robert@radio-sensors.com>
|
||||
*/
|
||||
|
||||
#ifndef PROJECT_CONF_H_
|
||||
#define PROJECT_CONF_H_
|
||||
|
||||
#define NETSTACK_CONF_RDC nullrdc_driver
|
||||
#define NETSTACK_CONF_MAC nullmac_driver
|
||||
|
||||
//#define NETSTACK_CONF_MAC csma_driver
|
||||
//#define NETSTACK_CONF_RDC contikimac_driver
|
||||
//#define NETSTACK_CONF_FRAMER framer_802154
|
||||
//#define NETSTACK_CONF_RADIO rf230_driver
|
||||
|
||||
#endif /* PROJECT_CONF_H_ */
|
188
platform/avr-rss2/examples/ipv6/sensd_client/sensd_client.c
Normal file
188
platform/avr-rss2/examples/ipv6/sensd_client/sensd_client.c
Normal file
|
@ -0,0 +1,188 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Copyright Robert Olsson / Radio Sensors AB
|
||||
* 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 Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*
|
||||
* Author : Robert Olsson robert@radio-sensors.com
|
||||
* Created : 2015-12-28
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* A simple application reporting sensor data. Can be sensd
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "contiki-net.h"
|
||||
#include "leds.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/battery-sensor.h"
|
||||
#include "dev/temp_mcu-sensor.h"
|
||||
#include "dev/light-sensor.h"
|
||||
#ifdef CO2
|
||||
#include "dev/co2_sa_kxx-sensor.h"
|
||||
#endif
|
||||
|
||||
#ifndef PERIOD
|
||||
#define PERIOD 10
|
||||
#endif
|
||||
|
||||
#define REPORT_INTERVAL (PERIOD * CLOCK_SECOND)
|
||||
|
||||
#define DEBUG DEBUG_PRINT
|
||||
#include "uip-debug.h"
|
||||
|
||||
#define PORT 1236
|
||||
#define MAX_PAYLOAD_LEN 80
|
||||
|
||||
static struct psock ps;
|
||||
static uint8_t out_buf[MAX_PAYLOAD_LEN];
|
||||
static char in_buffer[MAX_PAYLOAD_LEN];
|
||||
static int i;
|
||||
static int send_now;
|
||||
static clock_time_t report_interval = REPORT_INTERVAL;
|
||||
static uint8_t state;
|
||||
static uip_ipaddr_t addr;
|
||||
static struct timer t, t1;
|
||||
static struct etimer et, et1;
|
||||
|
||||
PROCESS(sensd_client_process, "sensd TCP client process");
|
||||
PROCESS(report_timer_process, "report pacemaker");
|
||||
AUTOSTART_PROCESSES
|
||||
(&sensd_client_process,&report_timer_process);
|
||||
|
||||
static int
|
||||
do_report(void)
|
||||
{
|
||||
static int seq_id;
|
||||
int len = 0;
|
||||
|
||||
seq_id++;
|
||||
len += snprintf((char *) &out_buf[len], sizeof(out_buf), "&: ");
|
||||
len += snprintf((char *) &out_buf[len], sizeof(out_buf), "TXT=6LOWPAN ");
|
||||
len += snprintf((char *) &out_buf[len], sizeof(out_buf), "TARGET=avr-rss2 ");
|
||||
len += snprintf((char *) &out_buf[len], sizeof(out_buf), "V_MCU=%-d ", battery_sensor.value(0));
|
||||
len += snprintf((char *) &out_buf[len], sizeof(out_buf), "T_MCU=%-d ", temp_mcu_sensor.value(0));
|
||||
len += snprintf((char *) &out_buf[len], sizeof(out_buf), "LIGHT=%-d ", light_sensor.value(0));
|
||||
#ifdef CO2
|
||||
len += snprintf((char *) &out_buf[len], sizeof(out_buf), "CO2=%-d ", co2_sa_kxx_sensor.value(value));
|
||||
#endif
|
||||
len += snprintf((char *) &out_buf[len], sizeof(out_buf), "\n\r");
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static void
|
||||
print_local_addresses(void)
|
||||
{
|
||||
PRINTF("Server IPv6 addresses:\n\r");
|
||||
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
|
||||
state = uip_ds6_if.addr_list[i].state;
|
||||
if(uip_ds6_if.addr_list[i].isused &&
|
||||
(state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
|
||||
PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
|
||||
PRINTF("\n\r");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_global_address(void)
|
||||
{
|
||||
uip_ipaddr_t ipaddr;
|
||||
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
|
||||
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
|
||||
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
|
||||
}
|
||||
|
||||
static int handle_connection(struct psock *p, long ts) {
|
||||
PSOCK_BEGIN(p);
|
||||
if(send_now) {
|
||||
do_report();
|
||||
leds_on(LEDS_YELLOW);
|
||||
PSOCK_SEND(p, (const uint8_t *) out_buf, strlen((const char *) out_buf));
|
||||
send_now = 0;
|
||||
}
|
||||
PSOCK_END(p);
|
||||
}
|
||||
|
||||
PROCESS_THREAD(report_timer_process, ev, data) {
|
||||
PROCESS_BEGIN();
|
||||
while(1) {
|
||||
timer_set(&t1, report_interval);
|
||||
etimer_set(&et1, timer_remaining(&t1));
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et1));
|
||||
send_now = 1;
|
||||
leds_on(LEDS_RED);
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
|
||||
PROCESS_THREAD(sensd_client_process, ev, data) {
|
||||
PROCESS_BEGIN();
|
||||
|
||||
set_global_address();
|
||||
leds_init();
|
||||
print_local_addresses();
|
||||
printf("Starting TCP client on port=%d\n", PORT);
|
||||
|
||||
/* Set server address. typically sensd */
|
||||
//uip_ip6addr(&addr, 0xfe80, 0, 0, 0, 0xfec2, 0x3d00, 1, 0x63ae);
|
||||
uip_ip6addr(&addr, 0x0000, 0, 0, 0, 0, 0xffff, 0xc0a8, 0x0201);
|
||||
//uip_ip6addr(&addr, 0x0000, 0, 0, 0, 0, 0xffff, 0xc0a8, 0x0255);
|
||||
|
||||
random_init(50);
|
||||
|
||||
while(1) {
|
||||
|
||||
/* Delay connection attempts */
|
||||
timer_set(&t, 2*CLOCK_SECOND);
|
||||
etimer_set(&et, timer_remaining(&t));
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||
|
||||
/* Time out teh actual connection attempt */
|
||||
timer_set(&t, 10*CLOCK_SECOND);
|
||||
printf("Connecting");
|
||||
tcp_connect(&addr, UIP_HTONS(PORT), NULL);
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
|
||||
|
||||
if(uip_aborted() || uip_timedout() || uip_closed()) {
|
||||
printf(" Failed\n");
|
||||
} else if(uip_connected()) {
|
||||
printf(" Success\n");
|
||||
PSOCK_INIT(&ps, (uint8_t *)in_buffer, sizeof(in_buffer));
|
||||
do {
|
||||
handle_connection(&ps, clock_seconds());
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
|
||||
} while(!(uip_closed() || uip_aborted() || uip_timedout()));
|
||||
printf("Disconnected\n");
|
||||
}
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
128
platform/avr-rss2/examples/ipv6/sensd_client/server.c
Normal file
128
platform/avr-rss2/examples/ipv6/sensd_client/server.c
Normal file
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Copyright Robert Olsson / Radio Sensors AB
|
||||
* 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 Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*
|
||||
* Author : Robert Olsson robert@radio-sensors.com
|
||||
* Created : 2015-12-28
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* A simple TCP server for client app.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "contiki-net.h"
|
||||
#include "leds.h"
|
||||
|
||||
#define DEBUG DEBUG_PRINT
|
||||
#include "uip-debug.h"
|
||||
|
||||
#define PORT 1236
|
||||
|
||||
static struct psock ps;
|
||||
static uint8_t buf[120];
|
||||
static int i;
|
||||
static uint8_t state;
|
||||
|
||||
static void
|
||||
print_local_addresses(void)
|
||||
{
|
||||
PRINTF("Server IPv6 addresses:\n\r");
|
||||
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
|
||||
state = uip_ds6_if.addr_list[i].state;
|
||||
if(uip_ds6_if.addr_list[i].isused &&
|
||||
(state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
|
||||
PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
|
||||
PRINTF("\n\r");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_global_address(void)
|
||||
{
|
||||
uip_ipaddr_t ipaddr;
|
||||
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
|
||||
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
|
||||
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
|
||||
}
|
||||
|
||||
static
|
||||
PT_THREAD(handle_connection(struct psock *p))
|
||||
{
|
||||
PSOCK_BEGIN(p);
|
||||
//PSOCK_SEND_STR(p, "Type something!\n");
|
||||
leds_on(LEDS_RED);
|
||||
PSOCK_READTO(p, '\n');
|
||||
printf("RX=%s", buf);
|
||||
//PSOCK_SEND_STR(p, "Got: ");
|
||||
//PSOCK_SEND(p, buf, PSOCK_DATALEN(p));
|
||||
//PSOCK_SEND_STR(p, "EOL\r\n");
|
||||
//PSOCK_CLOSE(p);
|
||||
PSOCK_END(p);
|
||||
}
|
||||
|
||||
PROCESS(server_process, "Server");
|
||||
AUTOSTART_PROCESSES(&server_process);
|
||||
|
||||
PROCESS_THREAD(server_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
set_global_address();
|
||||
leds_init();
|
||||
print_local_addresses();
|
||||
printf("Starting TCP server on port=%d\n", PORT);
|
||||
tcp_listen(UIP_HTONS(PORT));
|
||||
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
|
||||
|
||||
if(uip_aborted() )
|
||||
printf("TCP aborted\n");
|
||||
if(uip_timedout() )
|
||||
printf("TCP timeoutn\n");
|
||||
if(uip_closed() )
|
||||
printf("TCP closed\n");
|
||||
|
||||
if(uip_connected()) {
|
||||
printf("TCP Connected\n\r");
|
||||
PSOCK_INIT(&ps, buf, sizeof(buf));
|
||||
|
||||
while(!(uip_aborted() || uip_closed() || uip_timedout())) {
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
|
||||
handle_connection(&ps);
|
||||
}
|
||||
}
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue