2012-12-22

AVR NET-IO: Receive UDP packets

Some month ago I post an article about sending UDP - now it's time to write about receiving UDP.

Again my equipment is:
  • Pollin AVR NETIO Board
  • Arduino 1.0.3
  • avr-netino (Project)

Patch tcpip.cpp

To enable UDP receiving a patch of the tcpip.cpp file is needed. The patched file can be found here. You need to overwrite the original file libraries/EtherCard/tcpip.cpp with the patched one.

Arduino program

Arduino program to receive UDP packets:
//
// 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 *) &ether.buffer[pos]);
}
}

Example script to send UDP

Here is a small example how to send UDP packets to avr-netio board:
#!/usr/bin/env python
import socket
# Set the socket parameters
# avr-netio ip address
host = "10.0.0.52"
# avr-netio port
port = 7777
addr = (host,port)
# Create socket
UDPSock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
def_msg = "===Enter message to send ===";
print "\n",def_msg
# Send messages
while (1):
data = raw_input('>> ')
if not data:
break
else:
if(UDPSock.sendto(data,addr)):
print "Sending message '",data,"'....."
# Close socket
UDPSock.close()
view raw sendudp.py hosted with ❤ by GitHub

2012-12-16

Stabiler Vogelhausständer

Die "dunklen" Jahreszeiten sind immer auch eine Zeit, in der ich verstärkt zum Heimwerken komme. Dieses Jahr wünschte sich meine Frau ein Vogelhaus und das brauchte natürlich auch einen entsprechenden Ständer.
Beim Vogelhausdesign habe ich mich an Anregungen aus dem Baumarkt orientiert - da mag jeder selber schauen. Fehlte noch der Ständer - der sollte entsprechend stabil sein und wegen der hiesigen Katzenpopulation eine gewisse Höhe haben.

Zum Aufbau:
  • Basismaterial: 4 Kantholz (54mm x 54mm) - in Summe ca. 4m Länge
  • daraus dann 
    • 6x Fuß bzw. Stabilisierungsstrebe (Länge ca 43cm)
    • 1x zentraler Pfosten (Länge nach Bedarf)
  • Für das Stabilisierungskreuz dann entsprechende Aussparungen einarbeiten.
  • Alles verschrauben und verkleben.

  • Schließlich noch das Holz imprägnieren.
Zeitaufwand (ohne Streichen): 2-3h

Jetzt müssen nur noch die Vögel kommen ...