Arduino Forum

Topics => Home Automation and Networked Objects => Topic started by: tuanpm on Jan 07, 2015, 02:56 pm

Title: espduino: MQTT client for Arduino over ESP8266 (AT Command)
Post by: tuanpm on Jan 07, 2015, 02:56 pm
UPDATE: 5 March 2015, Using SLIP Command replace AT COMMAND with custom firmware for ESP8266
Add module: RESTful
Please see update here: https://github.com/tuanpmt/espduino (https://github.com/tuanpmt/espduino)


This is MQTT client for arduino connect to broker via ESP8266 AT command 0.2, port from MQTT client library for Contiki

Features


Repository:
https://github.com/tuanpmt/espduino (https://github.com/tuanpmt/espduino)

Warning
you have to change the SERIAL_BUFFER_SIZE minimum is 64 bytes in
Quote
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\HardwareSerial.cpp
Usage:
Code: [Select]

#include <espduino.h>
#include <SoftwareSerial.h>

SoftwareSerial debugPort(2, 3); // RX, TX

ESP esp(&Serial, &debugPort, 13);


void wifiCb(uint8_t status)
{
  debugPort.println("WIFI: Connected");
  esp.mqttConnect("mqtt.domain.io", 1880);
}

void mqttConnected(uint32_t* args)
{
  debugPort.println("MQTT:Connected");
  esp.subscribe("/topic");
}

void mqttDisconnected(uint32_t* args)
{
  debugPort.println("MQTT:Disconnected");
}

void mqttPublished(uint32_t* args)
{
  debugPort.println("MQTT:Published");
}

void mqttData(uint32_t* args)
{
  mqtt_event_data_t *event_data = (mqtt_event_data_t *)args;
  char topic[16];
  char data[32];

  memcpy(topic, event_data->topic, event_data->topic_length);
  memcpy(data, event_data->data, event_data->data_length);
  topic[event_data->topic_length] = 0;
  data[event_data->data_length] = 0;
  debugPort.print("Received, topic:");
  debugPort.print(topic);
  debugPort.print(", data:");
  debugPort.println(data);
}

const char clientId[] = "clientId";
const char user[] = "user";
const char pass[] = "pass";


void setup() {
  delay(200);
  Serial.begin(115200);
  debugPort.begin(9600);

  /* setup event */
  esp.wifiCb.attach(&wifiCb);
  esp.mqttConnected.attach(&mqttConnected);
  esp.mqttDisconnected.attach(&mqttDisconnected);
  esp.mqttPublished.attach(&mqttPublished);
  esp.mqttData.attach(&mqttData);

  /* Init data */
  esp.initMqttClient(clientId, user, pass, 30);

  /* wifi connect */
  esp.wifiConnect("DVES_HOME", "yourpassword");
}

void loop() {
  esp.process();
}


This code still much to do, however the functions of  MQTT client is doing a great job

Test working with Adruino Nano

Best regards
Title: Re: espduino: MQTT client for Arduino over ESP8266 (AT Command)
Post by: nirajbhatt7 on Jan 18, 2015, 10:53 am
Has anyone else got this successfully working with Arduino Uno and IDE 1.5.8?
Looks like the path to HardwareSerial.cpp is changed and I cannot find SERIAL_BUFFER_SIZE in that file so wondering if I am looking at the right path. The sample sketch (with required changes) compiles and uploads for me. The sketch also run successfully and ESP8266 connects to WiFi and MQTT server but nothing happens when someone publish the data on the topic.

Can someone using this post some comments please.
Title: Re: espduino: MQTT client for Arduino over ESP8266 (AT Command)
Post by: nirajbhatt7 on Jan 18, 2015, 10:51 pm
Few more things to report.

Title: Re: espduino: MQTT client for Arduino over ESP8266 (AT Command)
Post by: wesselah on Jan 22, 2015, 07:18 pm
You mentioned at command version 0.2 but can not find it or do you mean 0.92?
Great job bye the way
Title: Re: espduino: MQTT client for Arduino over ESP8266 (AT Command)
Post by: tushamanking on Feb 25, 2015, 07:51 am
i have testing on arduino uno with MQTT broker on linux .
everything is OK , but i can subscribe only one topic and publish only one topic .
how to subscribe multiple topic and publish multiple topic ?  :smiley-eek:
Title: Re: espduino: MQTT client for Arduino over ESP8266 (AT Command)
Post by: tuanpm on Mar 06, 2015, 03:33 pm
UPDATE: 5 March 2015, Using SLIP Command replace AT COMMAND with custom firmware for ESP8266
Add module: RESTful
Please see update here: https://github.com/tuanpmt/espduino (https://github.com/tuanpmt/espduino)
Title: Re: espduino: MQTT client for Arduino over ESP8266 (AT Command)
Post by: jeny on Mar 17, 2015, 03:35 pm
Hi everyone,  (Kind attention : tuanpm)

Query on using Espduino:-

1.Do i have to do any change in ESP8266 (ESP-12) module? i have purchased new one ,getting version no. 0018000902-AI03 after sending command AT+GMR.

2.Can you guide me for writing an arduino code just to publish and subscribe topic using espduino library?

Well i am bit novice in Mqtt , but i have used and tested Pubnub  publish and subscribe channel concept.
Title: Re: espduino: MQTT client for Arduino over ESP8266 (AT Command)
Post by: PinoDuino on Mar 24, 2015, 07:56 pm
Could anyone help me get started ? I'm not getting anywhere at the moment. I've used ESP modules before with arduinos but not with this firmware. Here's what I do ;
1. i flash the newest AT commands firmware using esptool from https://github.com/espressif/esp8266_at
           at this point i can still connect to the modules using AT commands
2 I flash the 2 bin files from https://github.com/tuanpmt/espduino/tree/master/esp8266/release
           I'm no longer able to get anything back from the esp with a terminal program
3 running the example code doesn't work :S

some questions; what bautrate does the module use after flashing the espduino firmware ? Is it normal that i'm unable to commuicate with the esp
Does it react to AT commands after flashing the espduino firmware ?

Thanks
Title: Re: espduino: MQTT client for Arduino over ESP8266 (AT Command)
Post by: arusr on Apr 10, 2015, 02:10 pm
Thanks for putting this firmware out there.  I'm having trouble loading it onto an ESP8266.

The first step uses a python script to load the firmware.


esp8266/tools/esptool.py -p COM1 write_flash 0x00000 esp8266/release/0x00000.bin 0x40000 esp8266/release/0x40000.bin


I'm a newbie, so please excuse the newbie question.  I couldn't figure out what I should replace "COM1" with.  If I'm using this on a Raspberry Pi, should it be something like "/dev/ttyUSB0" instead of "COM1"?

What's an easy way to load this?  On a Windows machine?  I tried installing Python on a Win7 machine and running that command, replacing "COM1" with the comm port of the FTDI adapter.  But I get a bunch of "print" command errors.

Thanks for any help.