Last active
December 10, 2015 01:34
-
-
Save thomo/4359043 to your computer and use it in GitHub Desktop.
This is a demo of receiving udp packets with an avr-netio board, Arduino and avr-netino.
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.3, | |
// * avr-netino (https://code.google.com/p/avr-netino/) | |
// | |
// This is a demo of receiving udp packets | |
// | |
// 2012-12-22 <Thomas.Mohaupt@gmail.com> http://creativecommons.org/licenses/by-sa/3.0/ | |
// Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) | |
// | |
// Example to send udp packets to board: https://gist.github.com/4359006 | |
// | |
// Note: you need to specify the gateway | |
#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 ipGateway[] = {10, 0, 0, 254}; | |
word portMy = 7777; | |
byte Ethernet::buffer[220]; | |
void setup() { | |
ether.begin(sizeof Ethernet::buffer, macMy, NETIO_CSPIN_ENC28J60); | |
ether.hisport = portMy; | |
ether.staticSetup(ipMy, ipGateway); | |
while (ether.clientWaitingGw()) | |
ether.packetLoop(ether.packetReceive()); | |
Serial.begin(9600); | |
Serial.println("finish setup"); | |
} | |
void loop() { | |
word len = ether.packetReceive(); | |
word pos = ether.packetLoop(len); | |
if (pos) { | |
Serial.println((const char *) ðer.buffer[pos]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment