STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1#include <Arduino.h>
2#include <ETH.h>
3#include <Ethernet.h>
4#include <EthernetUdp.h>
5#include <SPI.h>
6#include <WiFi.h>
7
8#define ETH_CLK_PIN 7
9#define ETH_MISO_PIN 41
10#define ETH_MOSI_PIN 13
11#define ETH_CS_PIN 6
12#define ETH_PHY_ADDR 0
13
14IPAddress staticIP(192, 168, 2, 100);
15IPAddress gateway(192, 168, 2, 1);
16IPAddress subnet(255, 255, 255, 0);
17IPAddress dns(192, 168, 2, 1);
18IPAddress receiverIP(192, 168, 2, 1);
19const int receiverPort = 5006;
20EthernetUDP udp;
21
22byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
23
24void setup() {
25 Serial.begin(115200);
26 Serial.println("Minimal UDP Sender");
28 delay(1000);
29 // Ethernet.config(staticIP, gateway, subnet, dns);
30 Ethernet.init(ETH_CS_PIN);
31 delay(1000);
32
34 delay(1000);
35
36 Serial.println("ESP32 IP: ");
37 Serial.println(Ethernet.localIP());
38 udp.begin(5005); // Local port for sending
39}
40
41void loop() {
42 String sensorValue = "Example data: " + String(random(0, 100));
43 unsigned long timestamp = millis();
44 String dataToSend =
45 sensorValue + ", Timestamp: " + String(timestamp) + "\n";
46 int dataLength = dataToSend.length();
47 char dataBuffer[dataLength + 1];
48 dataToSend.toCharArray(dataBuffer, dataLength + 1);
49
50 udp.beginPacket(receiverIP, receiverPort);
51 udp.write(dataBuffer, dataLength);
52 udp.endPacket();
53
54 Serial.print("Sent (UDP): ");
55 Serial.print(dataToSend);
56 delay(1000); // Adjust streaming rate
57}
static SerialStub Serial
Definition Arduino.h:128
unsigned long millis()
Definition Arduino.h:29
static EthernetClass Ethernet
Definition Ethernet.h:116
void delay(int ms)
const int receiverPort
Definition main.cpp:26
IPAddress receiverIP(192, 168, 2, 20)
void setup()
Definition main.cpp:142
void loop()
Definition main.cpp:201
IPAddress dns(192, 168, 2, 1)
byte mac[6]
Definition main.cpp:31
IPAddress subnet(255, 255, 255, 0)
IPAddress staticIP(192, 168, 2, BOARD_ID_DEFAULT)
EthernetUDP udp
Definition main.cpp:40
IPAddress gateway(0, 0, 0, 0)
static IPAddress subnet(255, 255, 255, 0)
static IPAddress gateway(192, 168, 2, 1)
IPAddress dns(192, 168, 2, 1)
IPAddress staticIP(192, 168, 2, 101)
#define ETH_MOSI_PIN
Definition main.cpp:10
#define ETH_CS_PIN
Definition main.cpp:11
#define ETH_MISO_PIN
Definition main.cpp:9
#define ETH_CLK_PIN
Definition main.cpp:8
IPAddress receiverIP(192, 168, 2, 1)