Using an Arduino via LAN

We might need a bit more detail!

Do you have a sketch loaded on the “arduino”?

How are you expecting Home assistant to see the arduino? MQTT, aRest, something else? (the sketch should help us understand)

Can you share the sketch you used?

Can you troubleshoot via serial connection?

Is the arduino connecting to your network?

Does anyone know about if the following hardware HHC-N8I8OP (cheap 8 relays with lan board) is compute by arduino ?
If it is the case I found this link that could possibly help with Mqqt.


If anyone could try, please report here

hello,i have this sketch on my arduino uno:

//zoomkat 3-17-12
//simple button GET server code to control servo and arduino pin 5
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html
//address will look like http://xxx.xxx.x.xx:xxxx when submited
//for use with W5100 based ethernet shields

#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>

// Configuração do acesso ao Broker MQTT
#define MQTT_AUTH false
#define MQTT_USERNAME “nxxxxxxxxxx”
#define MQTT_PASSWORD “2xxxxxxxxxxxxxa”
#define RELAY D2

//#include <Servo.h>
//Servo myservo; // create servo object to control a servo

byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = {
192, 168, 1, 151 }; // ip in lan
byte MQTT_SERVER[] = { 192, 168, 1, 235 };
byte gateway[] = {
192, 168, 1, 1 }; // internet access via router
byte subnet[] = {
255, 255, 255, 0 }; //subnet mask
EthernetServer server(8761); //server port

String readString;

EthernetClient ethClient;
PubSubClient client(ethClient);

//////////////////////

void setup(){

pinMode(4, OUTPUT); //pin selected to control
pinMode(5, OUTPUT); //pin selected to control
pinMode(6, OUTPUT); //pin selected to control
pinMode(7, OUTPUT); //pin selected to control
//start Ethernet
Ethernet.begin(mac, ip, gateway, gateway, subnet);
server.begin();

//enable serial data print
Serial.begin(9600);
Serial.println(“server LED test 1.0”); // so I can keep track of what is loaded
}

void loop(){
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();

   //read char by char HTTP request
   if (readString.length() < 100) {

     //store characters to string
     readString += c;
     //Serial.print(c);
   }

   //if HTTP request has ended
   if (c == '\n') {

     ///////////////
     Serial.println(readString); //print to serial monitor for debuging

       client.println("HTTP/1.1 200 OK"); //send new page
     client.println("Content-Type: text/html");
     client.println();

     client.println("<HTML>");
     client.println("<HEAD>");
     client.println("<TITLE>Arduino GET test page</TITLE>");
     client.println("</HEAD>");
     client.println("<BODY>");

     client.println("<H1>NEOS HOME</H1>");

     
     
     // DIY buttons
    
     // mousedown buttons
     client.println("<br><input type=\"button1\" value=\"ON\" onmousedown=\"location.href = '/?off0';\"/>");
        client.println("<input type=\"button1\" value=\"OFF\" onmousedown=\"location.href = '/?on0';\"/>");        
     client.println("<br><input type=\"button2\" value=\"ON\" onmousedown=\"location.href = '/?off1';\"/>");
        client.println("<input type=\"button2\" value=\"OFF\" onmousedown=\"location.href = '/?on1';\"/>"); 
     client.println("<br><input type=\"button3\" value=\"ON\" onmousedown=\"location.href = '/?off2';\"/>");
        client.println("<input type=\"button3\" value=\"OFF\" onmousedown=\"location.href = '/?on2';\"/>"); 
     client.println("<br><input type=\"button4\" value=\"ON\" onmousedown=\"location.href = '/?off3';\"/>");
        client.println("<input type=\"button4\" value=\"OFF\" onmousedown=\"location.href = '/?on3';\"/>");  
 
     client.println("</BODY>");
     client.println("</HTML>");

     delay(1);
     //stopping client
     client.stop();

     ///////////////////// control arduino pin
     if(readString.indexOf("on0") >0) {
       digitalWrite(4, HIGH);
       Serial.println("Led on0");
     }
     
     if(readString.indexOf("off0") >0) {
       digitalWrite(4, LOW);
       Serial.println("Led off0");
     }

     
     if(readString.indexOf("on1") >0) {
       digitalWrite(5, HIGH);
       Serial.println("Led on1");
     }
     if(readString.indexOf("off1") >0) {
       digitalWrite(5, LOW);
       Serial.println("Led off1");
     }

     if(readString.indexOf("on2") >0) {
       digitalWrite(6, HIGH);
       Serial.println("Led on2");
     }
     if(readString.indexOf("off2") >0) {
       digitalWrite(6, LOW);
       Serial.println("Led off2");
     }

     if(readString.indexOf("on3") >0) {
       digitalWrite(7, HIGH);
       Serial.println("Led on3");
     }
     if(readString.indexOf("off3") >0) {
       digitalWrite(7, LOW);
       Serial.println("Led off3");
     }
     //clearing string for next read
     readString="";          
   }
 }

}
}
}

i have this arduino on my home lan,with a ethernet shield, and i can connect to him throug the internet any where i want…but i want to add this arduino on my home assistant!!!
i think the mqtt is the way!? i have read similar projects but they use esp…devices!!!no ethernet shields!? is there code to add mqtt to my sketch???i try to same things on the code but i don´t really understand nothing of this!!

1 Like

use follow this project

Hi, I’m trying your sketch with my arduino mega and ethernet board…
In arduino serial monitor I see “MQTT CONNECTED”… but how can I see the switch in HA?

Many thanks

Can you write an MQTT code example? How do we do the open-close operations with a code?

Witam
Mam kilka czujników ściągniętych w jedno miejsce gdzie kiedyś działały pod Arduino. Teraz chce to przywrócić i podłączyć pod HA. I tu występuje szereg problemów:

  • HA i Arduino są w dwóch różnych pomieszczeniach więc nie ma możliwości po USB
  • mam arduino i Ethernet W5100 i nie potrafię zrobić by się te urządzenia widziały
  • nie jestem obryty w pisaniu kodów, pobieram wiedzę po Internetach

Czy jest ktoś w stanie pomóc przynajmniej w kodzie na złapanie komunikacji między HA a Arduino?
W miejscu gdzie ma być Arduino mam skrętkę z LAN