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

42 lines
1.3 KiB
Arduino
Raw Normal View History

2019-12-23 13:13:13 +00:00
#include "coppino.h"
#include "ipv6.h"
#include "slip.h"
2019-12-24 15:54:16 +00:00
#include "udp.h"
2019-12-24 22:41:31 +00:00
/* 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";
2019-12-24 15:54:16 +00:00
digitalWrite(13, !digitalRead(13));
memcpy(output_buffer, msg, strlen(msg));
return strlen(msg);
2019-12-24 15:54:16 +00:00
}
2019-12-23 13:13:13 +00:00
void setup() {
pinMode(13, OUTPUT);
2019-12-24 22:41:31 +00:00
/* Customize coppino library configuration settings by editing settings.h */
2019-12-24 22:41:31 +00:00
/* 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);
2019-12-24 15:54:16 +00:00
2019-12-24 22:41:31 +00:00
/* 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");
/* 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 */
2019-12-24 15:54:16 +00:00
udp::set_handler(80, udp_server);
2019-12-23 13:13:13 +00:00
}
void loop() {
/* network service routing */
2019-12-23 13:13:13 +00:00
coppino::handler();
}