0
J'ai écrit un croquis pour envoyer des données de capteur via UDP. Je reçois un simple transfert de 1 octet par paquet. Comment puis-je define
mon package
lenght
, ai-je besoin d'un buffer
?Définition de la taille de paquets UDP (Arduino)
Merci!
code ci-dessous:
//Version 1.05
//necessary libraries
#include <SPI.h>
#include <Ethernet2.h>
#include <EthernetUdp2.h>
//Pin settings
#define CTD 19
//Network Settings
byte mac[] = { 0x90, 0xA2, 0xDA, 0x10, 0xEC, 0xAB }; //set MAC Address Ethernet Shield (Backside)
byte ip[] = { XXX, XXX, X, X }; //set IP-Address
byte gateway[] = { XXX, XXX, X, X }; //set Gateway
byte subnet[] = { 255, 255, 255, 0 }; //set Subnetmask
//local UDP port to listen on
unsigned int localPort = 5568;
//Recipient IP
IPAddress RecipientIP(XXX, XXX, X, X);
//Recipient UDP port
unsigned int RecipientPort = 8888;
//Buffer for sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
//EthernetUDP instance
EthernetUDP Udp;
//CTD data
int incomingData = 0;
void setup()
{
//Start Ethernet
Ethernet.begin(mac, ip);
//Start UDP
Udp.begin(localPort);
//for debug only
Serial.begin(9600);
//Serial baud rate for CTD
Serial1.begin(1200);
//Version 1.05
Serial.print("Version 1.05");
//CTD
pinMode(CTD, INPUT);
}
void loop()
{
//If CTD is sending
if (Serial1.available())
{
//read incoming data
incomingData = Serial1.read();
//for debug only
Serial.print("Data: ");
Serial.println(incomingData, BIN);
}
//Send UDP packets
//Debug only
Serial.print("Packet");
// send to the IP address and port
Udp.beginPacket(RecipientIP, RecipientPort);
Udp.write(incomingData);
Udp.endPacket();
}
Je pense que vous pouvez utilisez-le pour vos références – Billa
Je l'ai essayé mais je ne reçois aucune donnée lorsque j'utilise le tampon. Comment puis-je obtenir mes données dans le parsePacket ou packetSize? – TheTris