Created
July 8, 2012 12:59
-
-
Save thomo/3070842 to your computer and use it in GitHub Desktop.
A demo of sending udp packets, using Pollin AVR NETIO board, Arduino 1.0.1, avr-netino project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Environment: Pollin AVR NETIO board, Arduino 1.0.1, avr-netino (https://code.google.com/p/avr-netino/) | |
// | |
// This is a demo of sending udp packets | |
// 2012-07-08 <Thomas.Mohaupt@gmail.com> http://creativecommons.org/licenses/by-sa/3.0/ | |
// Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) | |
// | |
// On destination site you can receive the packets e.g. with | |
// nc -4ul 7777 | |
// | |
// Note: The udp packets are always send via the gateway (see below) | |
#include <EtherCard.h> | |
static unsigned int NETIO_CSPIN_ENC28J60 = 28; | |
byte macMy[] = {0x00, 0x22, 0xF9, 0x01, 0x30, 0xDA }; | |
byte ipMy[] = {10, 0, 0, 52}; | |
byte ipDestination[] = {10, 0, 0, 2}; | |
byte ipGateway[] = {10, 0, 0, 254}; | |
unsigned int portMy = 8888; | |
unsigned int portDestination = 7777; | |
byte Ethernet::buffer[220]; | |
char msg[] = {"Hello World"}; | |
void setup() { | |
ether.begin(sizeof Ethernet::buffer, macMy, NETIO_CSPIN_ENC28J60); | |
// In the udp packet a destination mac must be inserted. But the EtherCard library | |
// will only insert the gateway mac in the udp packet. | |
// So the gateway needs to be specified here even if destination is in same subnet. | |
ether.staticSetup(ipMy, ipGateway); | |
// wait until arp request to gateway is finished | |
while (ether.clientWaitingGw()) | |
ether.packetLoop(ether.packetReceive()); | |
} | |
void loop() { | |
ether.sendUdp(msg, sizeof msg, portMy, ipDestination, portDestination); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment