Skip to content

add support for ESP32 #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# ubidots-mqtt-esp

MQTT library for connecting to Ubidots using MQTT protocol and an ESP8266 chip.
MQTT library for connecting to Ubidots using MQTT protocol with the ESP8266/ESP32.

## Setup
## Setup ESP8266

1. Go to the Arduino IDE, click on Files -> Preferences and enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into Additional Board Manager URLs field. You can add multiple URLs, separating them with commas
2. Open Boards Manager from Tools -> Board menu and install esp8266 platform (and don’t forget to select your ESP8266 board from Tools > Board menu after installation)
@@ -13,6 +13,16 @@ MQTT library for connecting to Ubidots using MQTT protocol and an ESP8266 chip.
7. Close the Arduino IDE and open it again.
8. If you are using windows, please install the appropiate driver for your ESP board (CH340G if you are using a LoLin board or CP2102 if you are using an AMICA board)

## Setup ESP32
1. Go to the Arduino IDE, click on Files -> Preferences and enter https://dl.espressif.com/dl/package_esp32_index.json into Additional Board Manager URLs field. You can add multiple URLs, separating them with commas
2. Open Boards Manager from Tools -> Board menu and install esp32 platform (and don’t forget to select your ESP32 board from Tools > Board menu after installation)
3. Download this library as .zip
4. Now, click on Sketch -> Include Library -> Add .ZIP Library
5. Select the .ZIP file that you have just downloaded and then “Accept” or “Choose”
6. Go to Sketch/Program -> Include Library -> Library Manager and install the PubSubClient library
7. Close the Arduino IDE and open it again.
8. If you are using windows, please install the appropiate driver for your ESP board (CH340G if you are using a LoLin board)

# Documentation

## Constructor
8 changes: 4 additions & 4 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=Ubidots MQTT for ESP8266
version=1.1
name=Ubidots MQTT for ESP8266/ESP32
version=1.2
author=Jose García <jose.reyes@ubidots.com>, Mateo Velez
maintainer=Jose García <jose.reyes@ubidots.com>
sentence=Library for sending data to the Ubidots cloud using ESP8266 based systems
paragraph=Library for sending data to the Ubidots cloud using ESP8266 based systems
sentence=Library for sending data to the Ubidots cloud using ESP8266/ESP32 based systems
paragraph=Library for sending data to the Ubidots cloud using ESP8266/ESP32 based systems
category=Other
url=https://github.com/ubidots/ubidots-mqtt-esp
architectures=*
13 changes: 12 additions & 1 deletion src/UbidotsESPMQTT.cpp
Original file line number Diff line number Diff line change
@@ -78,7 +78,7 @@ char* Ubidots::getMac(){
// Obtains the MAC of the device
Serial.println("entra");
byte mac[6];
WiFi.macAddress(mac);
WiFi.macAddress(mac);
char macAddr[18];
sprintf(macAddr, "%2X%2X%2X%2X%2X%2X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
return macAddr;
@@ -191,7 +191,18 @@ bool Ubidots::wifiConnection(char* ssid, char* pass) {
Serial.println(F("IP address: "));
Serial.println(WiFi.localIP());
if(_clientName==NULL){
#ifdef ESP8266
_clientName = getMac();
#endif

#ifdef ESP32
char macAddr[24];
uint64_t chipid = 0LL;
chipid = ESP.getEfuseMac(); //The chip ID is essentially its MAC address for esp32
uint16_t chip = (uint16_t)(chipid >> 32);
snprintf(macAddr, 24, "%04X%08X",chip, (uint32_t)chipid);
_clientName = macAddr;
#endif
}
}

11 changes: 9 additions & 2 deletions src/UbidotsESPMQTT.h
Original file line number Diff line number Diff line change
@@ -28,14 +28,21 @@ Modified by: Jose Garcia
#ifndef UbidotsESPMQTT_H
#define UbidotsESPMQTT_H
#include "PubSubClient.h"

#ifdef ESP8266
#include <ESP8266WiFi.h>
#define DEFAULT_DEVICE_LABEL "ESP8266"
#endif

#ifdef ESP32
#include <WiFi.h>
#define DEFAULT_DEVICE_LABEL "ESP32"
#endif

#define MQTT_PORT 1883
#define SERVER "things.ubidots.com"
#define MAX_VALUES 5
#define FIRST_PART_TOPIC "/v1.6/devices/"
#define DEFAULT_DEVICE_LABEL "ESP8266"


#define META_DEBUG Serial