Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. Arduino disconnects from LAN Network?

Arduino disconnects from LAN Network?

Scheduled Pinned Locked Moved Development
6 Posts 4 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Carl Durr
    wrote on last edited by
    #1

    Hello all,

    Im having some issues with my code. It works great, but only for a few hours. Then device disconnects/unresponsive. Hope someone can give me some advice on my code. I created this device to control my TV. Thank you in advanced and appreciated any advice.

    #include <IRremote.h>
    #include <IRremoteInt.h>
    #include <SPI.h>
    #include <UIPEthernet.h>
    #include <PubSubClient.h>
    
    IRsend irsend;
    
    int irledPin = 3;
    int ledPin = 5;
    
    // Current input
    int currentimput = 1;
    
    // mgmt number
    int currentmgmtping = 0;
    
    // Settings for "Status of Device"
    byte bytebuffer[30];
    
    
    // Update these with values suitable for your network.
    byte mac[]    = {  0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
    IPAddress ip(192, 168, 1, 201);
    IPAddress server(192, 168, 1, 200);
    
    //
    // Callback function header
    //
    void callback(char* topic, byte* payload, unsigned int length);
    
    //
    // toString function header
    //
    String toString(byte* payload, unsigned int length);
    
    EthernetClient ethClient;
    PubSubClient client(ethClient);
    
    void reconnect() {
      // Loop until we're reconnected
      while (!client.connected()) {
        Serial.print("Attempting MQTT connection...");
             // Attempt to connect
        if (client.connect("arduinoClient")) {
               Serial.println("connected");
               // Once connected, publish an announcement...
                       client.publish("/home/master/tv","Connected");
                // ... and resubscribe
                        client.subscribe("/home/master/tv");         
        } else {
                 Serial.print("failed, rc=");
                 Serial.print(client.state());
                 Serial.println(" try again in 5 seconds");
          // Wait 5 seconds before retrying
               delay(5000);
        }
      }
    }
    
    void lightled(){
                 digitalWrite(5, HIGH);
                 delay(1000);
                 digitalWrite(5, LOW);
      
    }
    
    // Setup Stuff ~~~~~~~~~~
    void setup(){
      Serial.begin(9600);
      delay(500);//Delay to let system boot
      Serial.println("Master rooms TV remote\n\n");
      delay(1000);//Wait before accessing Sensor
    
    //MQTT Connect
      client.setServer(server, 1883);
      client.setCallback(callback);
       Ethernet.begin(mac, ip);
       // Allow the hardware to sort itself out
      delay(1500);
    
      // initialize the pushbutton pin as an input:
      pinMode(irledPin, OUTPUT);
      pinMode(ledPin, OUTPUT);
    
    
    } //END Setup
    
    
    //Loop Stuff ~~~~~~~
    void loop() {
      
      if (!client.connected()) {
                 reconnect();
        } 
      
       client.loop();
    
    } //END Loop
    
    //
    // MQTT Callback function
    //
    
    void callback(char* topic, byte* payload, unsigned int length) {
              
              if (strcmp(topic, "/home/master/tv") == 0) {
                  String msg = toString(payload, length);
                  
                  //
                  // Send TV IR code
                  //
                  Serial.println("Received Message MSG sending Code");
                     if (msg=="POWER"){
                          irsend.sendNEC(0x20DF10EF, 32); //  TV power code
                  
                          lightled();   
                     } else{
                        // Do nothing
                        
                     }
          }
    }
    
    //
    // toString function
    //
    String toString(byte* payload, unsigned int length) {
      int i = 0;
      char buff[length + 1];
      for (i = 0; i < length; i++) {
        buff[i] = payload[i];
      }
      buff[i] = '\0';
      String msg = String(buff);
      return msg;
    }
    
    1 Reply Last reply
    0
    • mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by mfalkvidd
      #2

      Hi Carl. Welcome to the MySensors forum. This forum is primarily about the MySensors library, so you might have better luck with generic Arduino questions at the Arduino forum. But we try to help anyway :)

      What lan module are you using?
      How are you powering the Arduino?
      What are the last few lines of serial output?

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Carl Durr
        wrote on last edited by
        #3

        Hi mfalkvidd,

        Thank you for the quick reply, appreciated the help.

        Arduino Uno3 with a generic ethernet shield on it, which i picked up at local computer store. I have the Arduino powered via a 5V 2A (2000mA) switching power supply which connects directly to wall outlet.

        I dont have the serial connected. As you know, i wanted the device to power via wall outlet. So I dont need to connect the USB Serial. But you are right, this would be a good step to troubleshoot issues. However i didnt want my computer plugged in for long time, as i have other projects im working on :-)

        But i can connect Serial and watch output. The only issues it i think it takes few hours before Arduino becomes unresponsive.

        1 Reply Last reply
        0
        • mfalkviddM Offline
          mfalkviddM Offline
          mfalkvidd
          Mod
          wrote on last edited by mfalkvidd
          #4

          You're welcome :-)

          That power supply should be sufficient. You're not doing anything that requires much power anyway.

          Yes, I think getting some debug output is the best way forward.
          You might want to add more Serial.prinln to better determine where it stops working. You could also add some Serial.println(millis()) to get information on when things happen, so you don't need to stare at the computer screen for hours.

          1 Reply Last reply
          0
          • rmtuckerR Offline
            rmtuckerR Offline
            rmtucker
            wrote on last edited by
            #5

            I have a one here Same shield etc that shuts down completely when i plug a DC jack into it.
            But it works perfect when plugged into a 5v USB charger kind of supply.
            Seems to me some of the copy UNO boards are not that good.

            YveauxY 1 Reply Last reply
            0
            • rmtuckerR rmtucker

              I have a one here Same shield etc that shuts down completely when i plug a DC jack into it.
              But it works perfect when plugged into a 5v USB charger kind of supply.
              Seems to me some of the copy UNO boards are not that good.

              YveauxY Offline
              YveauxY Offline
              Yveaux
              Mod
              wrote on last edited by
              #6

              @rmtucker I also blew the 5V converter on a cheap Chinese UNO clone, by just connecting a power supply. Still wondering why....
              The AMS1117 often found on these boards only allow 15V input max. I blew another one by connecting a cheap AC adapter which outputs a higher voltage unloaded.

              http://yveaux.blogspot.nl

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              15

              Online

              11.7k

              Users

              11.2k

              Topics

              113.1k

              Posts


              Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • MySensors
              • OpenHardware.io
              • Categories
              • Recent
              • Tags
              • Popular