Всем привет. Ищу того кто оптимизирует код чтобы он работал на Arduino UNO или NANO. Оригинал кода взят с
https://randomnerdtutorials.com/arduino-ethernet-web-server-with-relay/
Сам методом копипаста модифицировал скетч на 7 реле, но не хватает памяти для 8.
Весь софт что я заказываю выкладываю на своём канале так что если нужно прорекламирую канал или группу исполнителя и софт будет доступен всем бесплатно. Но я не прошу сделать задаром просто нужен тот кто сделает за разумную цену.
из железа Arduino UNO и NANO CH340 и FTDI модуль W5500 маленький без карты памяти.
https://randomnerdtutorials.com/arduino-ethernet-web-server-with-relay/
Сам методом копипаста модифицировал скетч на 7 реле, но не хватает памяти для 8.
C++:
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 30);
EthernetServer server(80);
String relay1State = "Off";
String relay2State = "Off";
String relay3State = "Off";
String relay4State = "Off";
String relay5State = "Off";
String relay6State = "Off";
String relay7State = "Off";
String relay8State = "Off";
const int relay1 = 2;
const int relay2 = 3;
const int relay3 = 4;
const int relay4 = 5;
const int relay5 = 6;
const int relay6 = 7;
const int relay7 = 8;
const int relay8 = 9;
char linebuf[10];
int charcount=0;
void setup() {
pinMode(relay1, OUTPUT);
digitalWrite(relay1, HIGH);
pinMode(relay2, OUTPUT);
digitalWrite(relay2, HIGH);
pinMode(relay3, OUTPUT);
digitalWrite(relay3, HIGH);
pinMode(relay4, OUTPUT);
digitalWrite(relay4, HIGH);
pinMode(relay5, OUTPUT);
digitalWrite(relay5, HIGH);
pinMode(relay6, OUTPUT);
digitalWrite(relay6, HIGH);
pinMode(relay7, OUTPUT);
digitalWrite(relay7, HIGH);
pinMode(relay8, OUTPUT);
digitalWrite(relay8, HIGH);
Serial.begin(9600);
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void dashboardPage(EthernetClient &client) {
client.println("<!DOCTYPE HTML><html><head>");
client.println("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"></head><body>");
client.println("<h3>Arduino Web Server - <a href=\"/\">Refresh</a></h3>");
client.println("<h4>Relay 1 - State: " + relay1State + "</h4>");
if(relay1State == "Off"){
client.println("<a href=\"/relay1on\"><button>ON</button></a>");
}
else if(relay1State == "On"){
client.println("<a href=\"/relay1off\"><button>OFF</button></a>");
}
client.println("<h4>Relay 2 - State: " + relay2State + "</h4>");
if(relay2State == "Off"){
client.println("<a href=\"/relay2on\"><button>ON</button></a>");
}
else if(relay2State == "On"){
client.println("<a href=\"/relay2off\"><button>OFF</button></a>");
}
client.println("<h4>Relay 3 - State: " + relay3State + "</h4>");
if(relay3State == "Off"){
client.println("<a href=\"/relay3on\"><button>ON</button></a>");
}
else if(relay3State == "On"){
client.println("<a href=\"/relay3off\"><button>OFF</button></a>");
}
client.println("<h4>Relay 4 - State: " + relay4State + "</h4>");
if(relay4State == "Off"){
client.println("<a href=\"/relay4on\"><button>ON</button></a>");
}
else if(relay4State == "On"){
client.println("<a href=\"/relay4off\"><button>OFF</button></a>");
}
client.println("<h4>Relay 5 - State: " + relay5State + "</h4>");
if(relay5State == "Off"){
client.println("<a href=\"/relay5on\"><button>ON</button></a>");
}
else if(relay5State == "On"){
client.println("<a href=\"/relay5off\"><button>OFF</button></a>");
}
client.println("<h4>Relay 6 - State: " + relay6State + "</h4>");
if(relay6State == "Off"){
client.println("<a href=\"/relay6on\"><button>ON</button></a>");
}
else if(relay6State == "On"){
client.println("<a href=\"/relay6off\"><button>OFF</button></a>");
}
client.println("<h4>Relay 7 - State: " + relay7State + "</h4>");
if(relay7State == "Off"){
client.println("<a href=\"/relay7on\"><button>ON</button></a>");
}
else if(relay7State == "On"){
client.println("<a href=\"/relay7off\"><button>OFF</button></a>");
}
client.println("<h4>Relay 8 - State: " + relay8State + "</h4>");
if(relay8State == "Off"){
client.println("<a href=\"/relay8on\"><button>ON</button></a>");
}
else if(relay8State == "On"){
client.println("<a href=\"/relay8off\"><button>OFF</button></a>");
}
client.println("</body></html>");
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
memset(linebuf,0,sizeof(linebuf));
charcount=0;
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
linebuf[charcount]=c;
if (charcount<sizeof(linebuf)-1) charcount++;
// 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) {
dashboardPage(client);
break;
}
if (c == '\n') {
if (strstr(linebuf,"GET /relay1off") > 0){
digitalWrite(relay1, HIGH);
relay1State = "Off";
}
else if (strstr(linebuf,"GET /relay1on") > 0){
digitalWrite(relay1, LOW);
relay1State = "On";
}
if (strstr(linebuf,"GET /relay2off") > 0){
digitalWrite(relay2, HIGH);
relay2State = "Off";
}
else if (strstr(linebuf,"GET /relay2on") > 0){
digitalWrite(relay2, LOW);
relay2State = "On";
}
if (strstr(linebuf,"GET /relay3off") > 0){
digitalWrite(relay3, HIGH);
relay3State = "Off";
}
else if (strstr(linebuf,"GET /relay3on") > 0){
digitalWrite(relay3, LOW);
relay3State = "On";
}
if (strstr(linebuf,"GET /relay4off") > 0){
digitalWrite(relay4, HIGH);
relay4State = "Off";
}
else if (strstr(linebuf,"GET /relay4on") > 0){
digitalWrite(relay4, LOW);
relay4State = "On";
}
if (strstr(linebuf,"GET /relay5off") > 0){
digitalWrite(relay5, HIGH);
relay5State = "Off";
}
else if (strstr(linebuf,"GET /relay5on") > 0){
digitalWrite(relay5, LOW);
relay5State = "On";
}
if (strstr(linebuf,"GET /relay6off") > 0){
digitalWrite(relay6, HIGH);
relay6State = "Off";
}
else if (strstr(linebuf,"GET /relay6on") > 0){
digitalWrite(relay6, LOW);
relay6State = "On";
}
if (strstr(linebuf,"GET /relay7off") > 0){
digitalWrite(relay7, HIGH);
relay7State = "Off";
}
else if (strstr(linebuf,"GET /relay7on") > 0){
digitalWrite(relay7, LOW);
relay7State = "On";
}
if (strstr(linebuf,"GET /relay8off") > 0){
digitalWrite(relay8, HIGH);
relay8State = "Off";
}
else if (strstr(linebuf,"GET /relay8on") > 0){
digitalWrite(relay8, LOW);
relay8State = "On";
}
// you're starting a new line
currentLineIsBlank = true;
memset(linebuf,0,sizeof(linebuf));
charcount=0;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
}
}
из железа Arduino UNO и NANO CH340 и FTDI модуль W5500 маленький без карты памяти.