Hello there,
I am developing a project using ESP32U(16MB) . In my project, I need both Serial Bluetooth and AWS mqtt code.
But I am facing problem like only one functionality is works. When I first initialized Bluetooth, aws mqtt doesn't work or vise versa.
Here is my code.
#include <WiFiClientSecure.h>
#include "BluetoothSerial.h"
#include "PubSubClient.h"
#include "root.h"
char* ssid = "KEENTECHNO";
char* password = "keen$2019$";
const char* mqttServer = "a19u2z2shoq5px-ats.iot.us-east-1.amazonaws.com";
#define mqttPort 8883
WiFiClientSecure secureClient = WiFiClientSecure();
PubSubClient client(secureClient);
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
BluetoothSerial SerialBT;
char msg[50];
void callback(char* topic, byte* payload, unsigned int length)
{
int i;
Serial.println("A");
for (i = 0; i < length; i++)
{
msg = (payload);
payload = 0;
}
}
void setup()
{
unsigned char k = 0, t = 0;
Serial.begin(9600);
SerialBT.begin();
WiFi.begin(ssid, password);
Serial.println(ssid);
Serial.println(password);
while (WiFi.status() != WL_CONNECTED)
{
vTaskDelay(500);
Serial.print(".");
k++;
if (k > 20)
{
k = 0;
break;
}
}
if (WiFi.status() == WL_CONNECTED)
{
Serial.println("connected");
client.setServer(mqttServer, mqttPort);
secureClient.setCACert(rootCA);
secureClient.setCertificate(certificate);
secureClient.setPrivateKey(privateKey);
client.setCallback(callback);
while (!client.connected())
{
Serial.println("Connecting to MQTT...");
if(client.connect("espClient"))
{
Serial.println("connected");
client.publish("12312312345","Hello");
}
else
{
//Serial.print("failed with state ");
Serial.print(client.state());
//Serial.println(ESP.getFreeHeap());
delay(2000);
}
/*if (client.connect("espClient"))
{
Serial.println("connected");
client.subscribe(topic);
client.publish(topic1, "hello");
}
else
{
Serial.print("failed with state ");
Serial.print(client.state());
vTaskDelay(500);
k++;
if (k > 7)
{
break;
}
}*/
}
}
else
{
Serial.println("NOt connected");
}
}
void loop()
{
client.publish("12312312345","Hello");
delay(2000);
}
ESP32U with bluetooth and AWS mqtt code
Return to “General Discussion”
Jump to
- English Forum
- Explore
- News
- General Discussion
- FAQ
- Documentation
- Documentation
- Sample Code
- Discussion Forum
- Hardware
- ESP-IDF
- ESP-BOX
- ESP-ADF
- ESP-MDF
- ESP-WHO
- ESP-SkaiNet
- ESP32 Arduino
- IDEs for ESP-IDF
- ESP-AT
- ESP IoT Solution
- ESP RainMaker
- Rust
- ESP8266
- Report Bugs
- Showcase
- Chinese Forum 中文社区
- 活动区
- 乐鑫活动专区
- 讨论区
- 全国大学生物联网设计竞赛乐鑫答疑专区
- ESP-IDF 中文讨论版
- 《ESP32-C3 物联网工程开发实战》书籍讨论版
- 中文文档讨论版
- ESP-AT 中文讨论版
- ESP-BOX 中文讨论版
- ESP IoT Solution 中文讨论版
- ESP-ADF 中文讨论版
- ESP Mesh 中文讨论版
- ESP Cloud 中文讨论版
- ESP-WHO 中文讨论版
- ESP-SkaiNet 中文讨论版
- ESP 生产支持讨论版
- 硬件问题讨论
- 项目展示
Who is online
Users browsing this forum: aliabhatt and 89 guests
- All times are UTC
- Top
- Delete cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. ESP8266EX and ESP32 are some of our products.