Hardwire RGB MQTT Controller with arduino

Guys/Gals hope you can help me out.

I am struggling to find what I need with enough code to put it together and get it working.

Hardware:
Arduino Nano
ENC28J60 Ethernet Shield
MQTT Client for Arduino

Setup:
MQTT Server : 192.168.3.3
Arduino IP : 192.168.3.4
MQTT Subcriber /HOME/LIGHTING/ACCENT1

I have figured out that I need an ethercard.h library and have that loaded. I also have the MQTT Pub/Sub Client loaded.

But from there I am struggling. Everyone seems to be running the ESP2866.

I wanted to build these using hardwire because I was planning on injecting the 12V on the RJ45 to power the unit then allowing me to place these anywhere after running the cable.

Have any of you gotten a MQTT controller working with an arduino Nano and the ENC28J60 Ethernet Shield?

I am designing a circuit board to put the nano, ENC28j60 & mosfets on to drive the Ribbon cable.

Thanks Guys! Hope someone can help me.

Hi! So I started my MQTT wall control panel project off with a Nano and the ENC28J60, in the hope that I could take power down the ethernet cable, power the whole thing remotely, and have the whole lot in a lovely dinky package. How wrong I was.

Firstly I’m guessing you want to go down this route because you have a healthy mistrust of wireless for home automation. Hats off to you… I am the same. The answer to everything is NOT an ESP2866!

The two issues I faced were:

  • I hit the SRAM limit of the Arduino nano pretty quick, and once I added more functions (driving a graphic oled display) I could no longer load sketches into the nano for this reason

  • the ENC28J60 was not stable, or rather the combination of arduino and ENC28J60 was unstable. I could go into finer detail here - very many late nights, head banging, posting on forums, etc… but there were very many unresolved issues with stability (random crashing after an hour, overheating, etc.) and in short I don’t recommend wasting your time here.

Like me, I’m guessing you want to keep the project small, hence using the ENC28J60. The down side is that it doesn’t undertake the full workings of the TCP/IP stack, and so this needs handling by the Arduino, and that’s where our problems start.

I’ll skip to the end: I ended up using a small little thing based on the W5100 which I came to call the “W5100 Red”. I found them for under £5 a few years ago, I think you still can? Check out pics and my blog post here: http://hazymat.co.uk/2015/01/home-automation-poe-with-arduino-in-praise-of-diy-poe/

The post above is unrelated, but might cover some interesting things.

Since switching to this mini W5100 I’ve had my project running for over a year at a time without a reboot, no overheating, and things have been dandy.

Sorry for not going into much detail or for not sharing code, it has been a long time since I’ve had stuff working. I’m more than happy to send over some code snippets to show you how I did it. But I built a lot of abstraction into my code in the end, meaning it’s not so easy to understand. I probably have early versions.

Basic format of code for combining the ethernet library and MQTT is as below. (Sorry I tried to format this properly and failed towards the end.)

#include <Ethernet.h>
#include <PubSubClient.h>
...
byte mac[]    = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
byte server[] = { 192, 168, 0, 2 };
byte ip[]     = { 192, 168, 0, 100 };
...
EthernetClient ethClient;
PubSubClient client(server, 1883, callback, ethClient);


void setup()
{

Ethernet.begin(mac, ip);
delay(120); // this was 720 and stable

client.connect("arduinoClient");
delay(50);
client.subscribe("audio/home/bedroom/#");
delay(50);
}
....
void loop()
{
  Serial.println("Volume UP");
  client.publish("audio/home/bedroom/arduinovector", "up");

}

void callback(char* topic, byte* payload, unsigned int length) {
  payload[length] = '\0';

if(strcmp(topic, "audio/home/bedroom/title") == 0)
  {
    // found a title

    for (int i=0; i<120; ++i)
  writetitle[i] = payload[i];

titlelength = u8g.getStrWidth(writetitle);

Serial.print("Title length: ");
Serial.println(titlelength);
Serial.print("Title width: ");

Serial.println(titlelength);
scrollcounter = 200;
x_pos = 3;

}

if(strcmp(topic, “audio/home/bedroom/vol”) == 0)
{
// found a volume
for (int i=0; i<4; ++i)
writevol[i] = payload[i];
}

}