EM2011WSP04

Aus Verteilte Systeme - Wiki
Wechseln zu: Navigation, Suche

Erste Schritte

Entwicklungsumgebung

Nach langem hin und her probieren wurde ich auf folgenden Blog Eintrag aufmerksam, der erklärt warum der Build immer Fehlschlägt. Nachdem die Pakete installiert wurden, ließen sich die Beispiele ohne Fehler compilieren.

Flashen

Raven USB-Stick

Datei:Http://www.cs.hs-rm.de/~freic001/image01.jpg Die Software in contiki-2.x/examples/ravenusbstick mit einem make übersetzen und folgender maßen flashen: Verbindung testen:

sudo avrdude -p usb1287 -c dragon_jtag -P usb
löschen:
sudo avrdude -p usb1287 -c dragon_jtag -P usb -e       
Flashen:
sudo avrdude -p usb1287 -c dragon_jtag -P usb -U flash:w:ravenusbstick.hex -U eeprom:w:ravenusbstick.eep

NAchdem der Stick geflasht wurde kann man auf eine serielle Schnittstelle zugreifen:

sudo screen /dev/ttyACM0
“h” für Menü

Raven Board

[[Datei:http://www.cs.hs-rm.de/~freic001/image00.jpg]|200px] 3290lcd: contiki-2.x/platform/avr-ravenlcd

make TARGET=avr-ravenlcd
avr-objcopy -R .eeprom -R .fuse -R .signature -O ihex avr-ravenlcd ravenlcd_3290.hex
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex avr-ravenlcd ravenlcd_3290.eep
sudo avrdude -p usb1287 -c dragon_jtag -P usb
sudo avrdude -p m3290p -c dragon_jtag -P usb -e
sudo avrdude -p m3290p -c dragon_jtag -P usb -U flash:w:ravenlcd_3290.hex -U eeprom:w:ravenlcd_3290.eep

m1284p: contiki-2.x/examples/webserver-ipv6-raven

make TARGET=avr-raven
avr-objcopy -R .eeprom -R .fuse -R .signature -O ihex webserver6.elf raven_1284.hex
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex webserver6.elf raven_1284.eep
sudo avrdude -p m1284p -c dragon_jtag -P usb
sudo avrdude -p m1284p -c dragon_jtag -P usb -e
sudo avrdude -p m1284p -c dragon_jtag -P usb -U flash:w:raven_1284.hex -U eeprom:w:raven_1284.eep

Nach dem erfolgreichen Flashen kann man testen ob man das Raven-Board mit einem Ping erreichen kann.

Die Adresse kann man für das Webserver bsp in /contiki-2.x/platform/avr-raven/apps/raven-webserver/httpd-fs/makefsdata.h nachlesen. Für normale Programme die mit TARGET=avr-raven kompiliert wurden steht die Adresse in /contiki-2.x/platform/avr-raven/contiki-raven-main.c

ping6 fe80::11:22ff:fe33:4455%usb0


sudo apt-get install radvd

/etc/radvd.conf

interface usb0
{
   AdvSendAdvert on;
   AdvLinkMTU 1280;
   AdvCurHopLimit 128;
   AdvReachableTime 360000;
   MinRtrAdvInterval 100;
   MaxRtrAdvInterval 150;
   AdvDefaultLifetime 200;
   prefix AAAA::/64
   {
       AdvOnLink on;
       AdvAutonomous on;
       AdvPreferredLifetime 4294967295; 
       AdvValidLifetime 4294967295; 
   };
};
ip -6 address add aaaa::1/64 dev usb0
echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
/etc/init.d/radvd restart
ping6 aaaa::0011:22ff:fe33:4455
wget http://[aaaa::0011:22ff:fe33:4455]/

Anleitung

Client entwickeln

Contiki Programm Aufbau:

#include "contiki.h"
 
/* The PROCESS() statement defines the process' name. */
PROCESS(my_example_process, "My example process");
 
/* The AUTOSTART_PROCESS() statement selects what process(es)
   to start when the module is loaded. */
AUTOSTART_PROCESSES(&my_example_process);
 
/* The PROCESS_THREAD() contains the code of the process. */
PROCESS_THREAD(my_example_process, ev, data)
{
  /* Do not put code before the PROCESS_BEGIN() statement -
     such code is executed every time the process is invoked. */
  PROCESS_BEGIN();
  /* Initialize stuff here. */
  while(1) {
    PROCESS_WAIT_EVENT();
    /* Do the rest of the stuff here. */
  }
  /* The PROCESS_END() statement must come at the end of the
     PROCESS_THREAD(). */
  PROCESS_END();
}

Contiki Netzwerk Beispiel: Contiki Netzwerk-Stack

#include <stdio.h>
#include <string.h>
#include "contiki.h"
#include "contiki-net.h"

static struct psock ps;
static struct uip_conn *client_conn;
#define SEND_INTERVAL        15 * CLOCK_SECOND

static uint8_t buffer[10];
static uint8_t connected = 0;
static void set_connection_address(uip_ipaddr_t *ipaddr)
{
  // change this IP address depending on the node that runs the server!
  uip_ip6addr(ipaddr,0xaaaa,0,0,0,0,0,0,0x0001);
}
/*---------------------------------------------------------------------------*/
static
PT_THREAD(handle_connection(struct psock *p))
{
 PSOCK_BEGIN(p);

 PSOCK_SEND_STR(p, "Welcome, please type something and press return.\n");
 
 PSOCK_READTO(p, '\n');
 
 PSOCK_SEND_STR(p, "Got the following data: ");
 PSOCK_SEND(p, buffer, PSOCK_DATALEN(p));
 PSOCK_SEND_STR(p, "Good bye!\r\n");

 PSOCK_CLOSE(p);
 PSOCK_END(p);
}
/*---------------------------------------------------------------------------*/

PROCESS(example_psock_server_process, "Example protosocket server");
AUTOSTART_PROCESSES(&example_psock_server_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(example_psock_server_process, ev, data)
{
 uip_ipaddr_t ipaddr;
 static struct etimer et;
 set_connection_address(&ipaddr);
 PROCESS_BEGIN();

   while(1) {
     etimer_set(&et, CLOCK_CONF_SECOND*10);
     PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);
     client_conn = tcp_connect(&ipaddr, UIP_HTONS(3000), NULL);
     
     PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);

     if(uip_connected()) {
       PSOCK_INIT(&ps, buffer, sizeof(buffer));
       while(!(uip_aborted() || uip_closed() || uip_timedout())) 
       {
         PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
         handle_connection(&ps);
       }
     }
   }
 PROCESS_END();
}
/*---------------------------------------------------------------------------*/

Paython Server auf dem PC mit USB-Stick

#/usr/bin/python
# Echo server program
import socket
import time

HOST = 
PORT = 3000
while 1:
	s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
	s.bind((HOST, PORT))
	s.listen(1)
	print 'listen...'
	conn, addr = s.accept()
	print 'Connected by', addr
	while 1:
	    data = conn.recv(50)
	    print data
	    if not data: break
	    conn.sendall('testsendpython\n')
	conn.close()
	time.sleep(5)

Ausgabe:

Connected by ('aaaa::11:22ff:fe33:4455', 1033, 0, 0)
Welcome, please type something and press return.

Got the following data: 
testsendpy
Good bye!

listen...
Connected by ('aaaa::11:22ff:fe33:4455', 1034, 0, 0)
Welcome, please type something and press return.

Got the following data: 
testsendpy
Good bye!

listen...