Init commit with many years of arduino sketches and projects. I dont know if the esp8266 includes much, but there are also libraries. I hope they dont have crazy automatic versioning through the Arduino IDE.

This commit is contained in:
2019-05-30 23:41:53 +02:00
parent 2d047634f2
commit 6c84b31f2c
1480 changed files with 198581 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
#include <Ethernet.h>
#include <UdpBytewise.h>
/* UdpReceiveBytewise.pde: Example how to receive packets over UDP using UdpBytewise library
* prints received packet to serial port
* bjoern@cs.stanford.edu 12/30/2008
*/
/* ETHERNET SHIELD CONFIGURATION
* set MAC, IP address of Ethernet shield, its gateway,
* and local port to listen on for incoming packets
*/
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC address to use
byte ip[] = { 192, 168, 11, 200 }; // Arduino's IP address
byte gw[] = { 192, 168, 11, 1 }; // Gateway IP address
unsigned int localPort = 8888; // local port to listen on
#define MAX_SIZE 32 // maximum packet size
byte packetBuffer[MAX_SIZE]; //buffer to hold incoming packet
int packetSize; // holds received packet size
byte remoteIp[4]; // holds recieved packet's originating IP
unsigned int remotePort; // holds received packet's originating port
int i;
/* SETUP: init Ethernet shield, start UDP listening, open serial port */
void setup() {
Ethernet.begin(mac,ip,gw);
UdpBytewise.begin(localPort);
Serial.begin(38400);
}
/* LOOP: wait for incoming packets and print each packet to the serial port */
void loop() {
// if there's data available, read a packet
if(packetSize = UdpBytewise.available()) {
Serial.print("Received packet of size ");
Serial.println(packetSize);
UdpBytewise.getSenderIp(remoteIp);
Serial.print("From IP ");
for(i=0; i<4; i++) {
Serial.print(remoteIp[i],DEC);
if(i<3) Serial.print(".");
}
remotePort = UdpBytewise.getSenderPort();
Serial.print(" Port ");
Serial.println(remotePort);
Serial.println("Contents:");
while(UdpBytewise.available()) {
Serial.print(UdpBytewise.read(),BYTE);
}
}
//wait a bit
delay(10);
}

View File

@@ -0,0 +1,70 @@
#include <Ethernet.h>
#include <UdpRaw.h>
/* UdpReceiveRaw.pde: Example how to receive packets over UDP using UdpRaw library
* prints received packet to serial port
* bjoern@cs.stanford.edu 12/30/2008
*/
/* ETHERNET SHIELD CONFIGURATION
* set MAC, IP address of Ethernet shield, its gateway,
* and local port to listen on for incoming packets
*/
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC address to use
byte ip[] = { 192, 168, 11, 200 }; // Arduino's IP address
byte gw[] = { 192, 168, 11, 1 }; // Gateway IP address
int localPort = 8888; // local port to listen on
#define MAX_SIZE 32 // maximum packet size
byte packetBuffer[MAX_SIZE]; //buffer to hold incoming packet
int packetSize; // holds received packet size
byte remoteIp[4]; // holds recvieved packet's originating IP
unsigned int remotePort; // holds received packet's originating port
int i;
/* SETUP: init Ethernet shield, start UDP listening, open serial port */
void setup() {
Ethernet.begin(mac,ip,gw);
UdpRaw.begin(localPort);
Serial.begin(38400);
}
/* LOOP: wait for incoming packets and print each packet to the serial port */
void loop() {
// if there's data available, read a packet
if(UdpRaw.available()) {
packetSize = UdpRaw.readPacket(packetBuffer,MAX_SIZE,remoteIp,(uint16_t *)&remotePort);
Serial.print("Received packet of size ");
Serial.println(abs(packetSize));
Serial.print("From IP ");
for(i=0; i<3; i++) {
Serial.print(remoteIp[i],DEC);
Serial.print(".");
}
Serial.print(remoteIp[3],DEC);
Serial.print(" Port ");
Serial.println(remotePort);
if(packetSize < 0) {
// if return value <0 the packet was truncated to fit into our buffer
Serial.print("ERROR: Packet was truncated from ");
Serial.print(packetSize*-1);
Serial.print(" to ");
Serial.print(MAX_SIZE);
Serial.println(" bytes.");
}
Serial.println("Contents:");
for(i=0; i<min(MAX_SIZE,abs(packetSize)); i++) {
Serial.print(packetBuffer[i],BYTE);
}
Serial.println("");
}
//wait a bit
delay(10);
}

View File

@@ -0,0 +1,58 @@
#include <Ethernet.h>
#include <UdpString.h>
#include <WString.h>
/* UdpReceiveString.pde: Example how to receive packets over UDP using the UdpString library
* prints received packet to serial port
* bjoern@cs.stanford.edu 12/30/2008
*/
/* ETHERNET SHIELD CONFIGURATION
* set MAC, IP address of Ethernet shield, its gateway,
* and local port to listen on for incoming packets
*/
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC address to use
byte ip[] = { 192, 168, 11, 200 }; // Arduino's IP address
byte gw[] = { 192, 168, 11, 1 }; // Gateway IP address
int localPort = 8888; // local port to listen on
String packet(32); //packet can be max 32 bytes long
byte remoteIp[4]; // holds recvieved packet's originating IP
unsigned int remotePort[1]; // holds received packet's originating port
int i;
/* SETUP: init Ethernet shield, start UDP listening, open serial port */
void setup() {
Ethernet.begin(mac,ip,gw);
UdpString.begin(localPort);
Serial.begin(38400);
}
/* LOOP: wait for incoming packets and print each packet to the serial port */
void loop() {
// if there's data available, read a packet
if(UdpString.available()) {
int packetSize = UdpString.readPacket(packet,remoteIp,remotePort);
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From IP ");
for(i=0; i<3; i++) {
Serial.print(remoteIp[i],DEC);
Serial.print(".");
}
Serial.print(remoteIp[3],DEC);
Serial.print(" Port ");
Serial.println(remotePort[0]);
Serial.println("Contents:");
Serial.println(packet);
}
//wait a bit
delay(10);
}

View File

@@ -0,0 +1,36 @@
#include <Ethernet.h>
#include <UdpBytewise.h>
/* UdpSendBytewise.pde: Example how to send packets over UDP using the UdpBytewise library
* by assembling packets byte-by-byte
* to check for received packets on Unix-ish setup, execute:
* sudo tcpdump -A -ien0 "udp port 8000"
* bjoern@cs.stanford.edu 12/29/2008 */
/* ETHERNET CONFIGURATION
* ARDUINO: set MAC, IP address of Ethernet shield, its gateway,
* and local port to listen on for incoming packets */
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //MAC address to use
byte ip[] = { 192, 168, 11, 200 }; // Arduino's IP address
byte gw[] = { 192, 168, 11, 1 }; // Gateway IP address
int localPort = 8888; //local port to listen on
/* TARGET: set this to IP/Port of computer that will receive
* UDP messages from Arduino */
byte targetIp[] = { 192, 168, 11, 15};
int targetPort = 8000;
int i=0;
void setup() {
Ethernet.begin(mac,ip,gw);
UdpBytewise.begin(localPort);
}
void loop() {
// this version of sendPacket sends a zero-terminated string.
UdpBytewise.beginPacket(targetIp,targetPort);
UdpBytewise.print("Hello, World! ");
UdpBytewise.print(i++);
UdpBytewise.endPacket();
delay(1000);
}

View File

@@ -0,0 +1,40 @@
#include <Ethernet.h>
#include <UdpRaw.h>
/* UdpSendRaw.pde: Example how to send packets over UDP using the UdpRaw library
* to check for received packets on Unix-ish setup, execute:
* sudo tcpdump -ien0 "udp port 8000"
* bjoern@cs.stanford.edu 12/30/2008 */
/* ETHERNET CONFIGURATION
* ARDUINO: set MAC, IP address of Ethernet shield, its gateway,
* and local port to listen on for incoming packets */
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //MAC address to use
byte ip[] = { 192, 168, 11, 200 }; // Arduino's IP address
byte gw[] = { 192, 168, 11, 1 }; // Gateway IP address
int localPort = 8888; //local port to listen on
/* TARGET: set this to IP/Port of computer that will receive
* UDP messages from Arduino */
byte targetIp[] = { 192, 168, 11, 15};
int targetPort = 8000;
/* A binary packet we'll send to our target - can contain 0x00 */
byte packet[] = { 'h','e','l','l','o','\0','w','o','r','l','d','\0' };
int packetLen = 12;
void setup() {
Ethernet.begin(mac,ip,gw);
UdpRaw.begin(localPort);
}
void loop() {
// this version of sendPacket sends a zero-terminated string.
UdpRaw.sendPacket("hello, world.",targetIp,targetPort);
delay(1000);
// this version sends an arbitrary buffer with specified length;
// buffer can contain '\0'
UdpRaw.sendPacket(packet,packetLen,targetIp,targetPort);
delay(1000);
}

View File

@@ -0,0 +1,48 @@
#include <Ethernet.h>
#include <UdpString.h>
#include <WString.h>
/* UdpSendString.pde: Example how to send packets over UDP using the String library
* to check for received packets on Unix-ish setup, execute:
* sudo tcpdump -A -ien0 "udp port 8000"
* bjoern@cs.stanford.edu 12/30/2008 */
/* ETHERNET CONFIGURATION
* ARDUINO: set MAC, IP address of Ethernet shield, its gateway,
* and local port to listen on for incoming packets */
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //MAC address to use
byte ip[] = { 192, 168, 11, 200 }; // Arduino's IP address
byte gw[] = { 192, 168, 11, 1 }; // Gateway IP address
int localPort = 8888; //local port to listen on
/* TARGET: set this to IP/Port of computer that will receive
* UDP messages from Arduino */
byte targetIp[] = { 192, 168, 11, 15};
int targetPort = 8000;
/* Strings hold the packets we want to send */
String asciiString;
String binaryString(4); // if we want to send non-ASCII, we have to provide a capacity for the String
void setup() {
Ethernet.begin(mac,ip,gw);
UdpString.begin(localPort);
asciiString = "Hello, World";
binaryString.getBytes()[0]=0x00;
binaryString.getBytes()[1]=0x01;
binaryString.getBytes()[2]=0x02;
binaryString.getBytes()[3]=0x03;
}
void loop() {
// send a normal, zero-terminated string.
UdpString.sendPacket(asciiString,targetIp,targetPort);
delay(1000);
// sends a binary string that can contain 0x00 in the middle
// you have to specify the length;
UdpString.sendPacket(binaryString,binaryString.capacity(),targetIp,targetPort);
delay(1000);
}