new code base

This commit is contained in:
2023-03-22 19:36:34 +01:00
parent bd699cd238
commit 66c3d4db74
7 changed files with 160 additions and 210 deletions
+65 -48
View File
@@ -1,61 +1,78 @@
#include <Arduino.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <Ethernet2.h>
#include <SPI.h>
#include <shiftregister.h>
#include "config.h"
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
char ReplyBuffer[UDP_TX_PACKET_MAX_SIZE];
byte mac[] = { 0xC3, 0xF9, 0x7C, 0xB1, 0x8C, 0xF3 };
EthernetUDP Udp;
IPAddress ip(192, 168, 13, 0);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 128, 0);
EthernetServer server(80);
ShiftRegister reg()
void listenForEthernetClients(void);
void setup() {
Serial.begin(115200);
Serial.println("Irrigation Arduino");
Serial.println("Arduino Bewaesserung");
Ethernet.init(ETHERNET_CS);
IPAddress ip;
ip.fromString(IP_ADDRESS);
Ethernet.begin(mac, ip);
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true)
delay(1);
}
if (Ethernet.linkStatus() == LinkOFF)
Serial.println("Ethernet cable is not connected.");
Udp.begin(IP_PORT);
server.begin();
}
void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize) {
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = Udp.remoteIP();
for (int i=0; i < 4; i++) {
Serial.print(remote[i], DEC);
if (i < 3) {
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(Udp.remotePort());
// read the packet into packetBuffer
Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
Serial.println("Contents:");
Serial.println(packetBuffer);
// send a reply to the IP address and port that sent us the packet we received
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ReplyBuffer);
Udp.endPacket();
}
delay(10);
listenForEthernetClients();
}
void listenForEthernetClients() {
EthernetClient client = server.available();
if (!client) return;
Serial.println("Got a client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
char buffer[7];
client.readBytesUntil(' ', buffer, 7);
Serial.print(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// print the current readings, in HTML format:
client.print("Temperature: ");
client.print("temperature");
client.print(" degrees C");
client.println("<br />");
client.print("Pressure: lUl");
client.print(" Pa");
client.println("<br />");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
Serial.println();
delay(1);
client.stop();
}