MQTT to fixed ip address for

I’m trying to send to via MQTT. I’m programming an arduino to use an ENC28J60 based ethernet adaptor to publish MQTT from a fixed ip address. The easiest way I think would be to send MQTT directly to the fixed IP address, would this be possible?

Any thoughts?


#include <NanodeUNIO.h>
#include <NanodeUIP.h>
#include <NanodeMQTT.h>

NanodeMQTT mqtt(&uip);
struct timer my_timer;

void setup() {
  byte macaddr[6];

  Serial.println("MQTT Publish test");, NANODE_MAC_ADDRESS, 6);

  // FIXME: use DHCP instead
  uip.set_ip_addr(192, 168, 2, 10);
  uip.set_netmask(255, 255, 255, 0);

  Serial.println("Link is up");

  // Setup a timer - publish every 20 seconds
  timer_set(&my_timer, CLOCK_SECOND * 20);

  // FIXME: resolve using DNS instead
  mqtt.set_server_addr(10, 100, 10, 1);

  Serial.println("setup() done");

void loop() {

  if(timer_expired(&my_timer)) {
    if (mqtt.connected()) {
      mqtt.publish("test", "Hello World!");

Why MQTT? I’d have thought the HTTP API would be simpler (but I am no Arduino programmer). A fixed IP is always a danger as domains do change their IP address from time to time.

Good to know about changing IP addresses.

I’m connecting to a router station in the middle of a public park with potentially hundreds of WiFi connections. I’ll have the ethernet cable advantage but thought to make doubly sure I’m using a quick and efficient protocol :slight_smile:

If MQTT isn’t working I’ll fallback on a HTTP webclient arduino example I just found, it does look simpler to do that…

Do you really mean emoncms.ORG ?

There is no MQTT implementation at (that I’m aware of) so I assume you mean self hosted emoncms.

The current emoncms MQTT implementation has some unresolved issues, it is not reliable yet and is most likely (or perhaps just hopefully) going to change in the not too distant future. Plus the MQTT input script is hardcoded for one user only (userid: 1). I would expect a HTTP SSL connection to be both more reliable and more secure.

I’m glad I hadn’t spend too long on this :slight_smile:

emonhub has MQTT support, I assumed could receive MQTT messages.

There is a ‘right tool for the job’ issue here. You can knock a nail in with a spanner, but a hammer is nearly always the better tool.

You know what they say, Brian…
If it doesn’t fit, don’t force it. Get a bigger hammer! :grin:

1 Like