coppino/examples/simple-udp-server/simple-udp-server.ino

42 lines
1.4 KiB
C++

#include "coppino.h"
#include "ipv6.h"
#include "slip.h"
#include "udp.h"
/* an UDP application, which simply replies HELLO-WORLD-UDP */
int udp_server(char* output_buffer, const char* input_buffer, int len) {
const char msg[] = "HELLO-WORLD-UDP\n";
digitalWrite(13, !digitalRead(13));
memcpy(output_buffer, msg, strlen(msg));
return strlen(msg);
}
void setup() {
pinMode(13, OUTPUT);
/* setup serial for Internet connectivity
* attach a SLIP daemon on the other endpoint; a good one is `tunslip6` by Contiki
* $ tunslip6 -s /dev/ttyUSB0 -L -v5 -B 19200 2001:db8:1324::1/64
* Note: the address given is the one on the host it is running on
*/
Serial.begin(19200);
/* set unique identifier of network hardware. It MUST be unique!
* For example, this could be your microcontroller serial number
* Note: pay attention to enter exactly 64 bits / 8 bytes
*/
ipv6::setEUI("\xde\xad\xbe\xef\x12\x34\x56\x78");
/* enable or disable IPv6 Stateless Auto-Configuration (SLAAC) */
ipv6::SLAAC(false);
/* set global address -- will be overwritten if SLAAC is enabled and a Router Advertisement is received */
ipv6::setGlobalAddress("\x20\x01\x04\x70\xc8\x44\x00\x31\x00\x00\x00\x00\x00\x00\xca\xfe");
/* start a server un UDP port 80 */
udp::set_handler(80, udp_server);
}
void loop() {
/* network service routing */
coppino::handler();
}