I am working on the ESP32 BLE. I am using Arduino IDE for my programming.
In my project I want to use BLE in continuous advertising mode. But actually what it happen means, the BLE advertise is stopped once the device is connected to BLE app for one time. After that the BLE advertise is stopped. I can't able to connect to that BLE device after that. I can't even see its advertising in BLE mobile app (used open source mobile app: nRF connect, BLE scanner..). Then it starts its advertising process after only the Hard reset was happened in the ESP32 board.
I faced this issue when the BLE code is compiled in my Laptop. I have checked 3 or more system, in that the base example BLE_server (in-build ESP32 Arduino IDE example)code which was compiled in one system was worked perfectly. The the code which was compiled in the remaining 3 systems causes the issue which I have mentioned above.I have attached the Arduino IDE configuration details- image here. kindly do find the attachment.
Here I have used Arduino IDE version 1.8.13.
In my laptop I have used Java(TM) SE development kit 18.0.1.1(64 bit) & python version 2.7.15.
I have updated the Arduino IDE version And ESP32 board version to.
What is the reason for this issue? is there any configuration missing in my Arduino IDE?
Is there may be any issue in compilation process?
Kindly help me to over come this issue?
Waiting for your positive reply.
Thanks in advance!!!
Advertising stops once the device is connected, you need to restart it once that happens
/*
Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleServer.cpp
Ported to Arduino ESP32 by Evandro Copercini
updates by chegewara
*/
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
// See the following for generating UUIDs:
// https://www.uuidgenerator.net/
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
class MyServerCallbacks: public BLEServerCallbacks {
void onConnect(BLEServer* pServer) {
pServer->startAdvertising(); // restart advertising
};
void onDisconnect(BLEServer* pServer) {
pServer->startAdvertising(); // restart advertising
}
};
void setup() {
Serial.begin(115200);
Serial.println("Starting BLE work!");
BLEDevice::init("Long name works now");
BLEServer *pServer = BLEDevice::createServer();
pServer->setCallbacks(new MyServerCallbacks()); //set the callback function
BLEService *pService = pServer->createService(SERVICE_UUID);
BLECharacteristic *pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE
);
pCharacteristic->setValue("Hello World says Neil");
pService->start();
// BLEAdvertising *pAdvertising = pServer->getAdvertising(); // this still is working for backward compatibility
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
pAdvertising->addServiceUUID(SERVICE_UUID);
pAdvertising->setScanResponse(true);
pAdvertising->setMinPreferred(0x06); // functions that help with iPhone connections issue
pAdvertising->setMinPreferred(0x12);
BLEDevice::startAdvertising();
Serial.println("Characteristic defined! Now you can read it in your phone!");
}
void loop() {
// put your main code here, to run repeatedly:
delay(2000);
}
Related
I am trying to integrate an RFID1356MIFARE, which uses NXP PN532, with an ESP32-EVB using their UART capabilities.
The NXP docs states that the PN532 is able to communicate on High Speed UART.
I am trying to use 38400 because that's the baud rate fixed by the reader that I'm using.
I've found a modified Adafruit PN532 library that added HSU support. This library states that HSU uses 115200 baud rate.
Now, I've modified PN532_HSU.cpp, where we can find:
void PN532_HSU::begin()
{
_serial->begin(115200);
}
into
void PN532_HSU::begin()
{
_serial->begin(38400, SERIAL_8N1, 36, 4);
}
Unfortunately, I haven't been able to establish communication between the reader and the ESP using this method.
I am able to get a readable output using normal Serial.read(), so UART communication works, but that's not how you read MIFARE cards.
I don't know what the problem is.
What do you think ?
[EDIT]
I went through the documentation and here is what i suggest: If you have a USB to serial device use it to directly connect reader module to computer else connect it directly using mini USB port in module. the follow following steps:
Put device in UART/ USB CDC mode depending on how you connected device to computer. Exact method to do this is provided in operation section of documentation
Use picoterm / screen or other serial terminal (if you are using Linux) or just use Arduino serial monitor with correct baud rate to connect device.(115200 for USB and 38400 for UART)
Type in commands listed in COMMAND SET FOR CDC AND UART MODE section in documentation to check if module is working or not.
Place some cards over reader to check what response does module sends when card is detected.
Use this information to develop your own library for reader.
It will not work with regular PN532 libraries. Instead you'll need to use regular Serial read and write to communicate.
[Original]
PN532 datasheet says host interface is selected by pulling up/down I0, I1 pins of device. For HSU both pins must be pulled down. This is implemented in hardware so you need to verify if the mode you want to use is set.
Looking into the link you posted for module, it says that it uses another micro-controller on board to extend communication capabilities, so maybe you need to use driver for that specific controller firmware? The link seems to have document explaining how to setup different communication system in Document section, please have a look there and check if it works.
Link: https://www.olimex.com/wiki/MOD-RFID1356MIFARE
I have a Xamarin application that requires to connect to a device from the LAN side and also the WAN side. The device (an ESP8266) is connected via WiFi to an internal network and can be accessed from the WAN side via DDNS.
When the user makes a request (via the Xamarin app), whilst using mobile data (i.e. they are not connected to the WiFi network), the request reaches the IoT device (the IoT device makes a UPNP mapping on the router).
The IoT device uses mDNS to make itself known on the local network, and if I try to connect via Chrome on Windows 10 on a machine connected to the same network, the connection is successful (using 'domain.local'). Doing the same on on Chrome on Android gets a DNS error.
If the user now connects the phone to the same network as the IoT device, the Xamarin app request will no longer reach the IoT device. I have some code which distinguishes between a local request and a remote request which makes either a 'domain.local' request or a 'domain.ddns.net' request.
I understand the Apple Bonjour aspect of this on my desktop machine and the lack thereof on the Android platform.
Does anyone know how to resolve this?
So I have solved this and have posted the answer in case it's useful to someone in future.
Using the library Zeroconf https://github.com/novotnyllc/Zeroconf in Xamarin
private const string deviceHostName = "yourhostname"
public static async void GetDeviceIPAddress()
{
IReadOnlyList<IZeroconfHost> responses = null;
responses = await ZeroconfResolver.ResolveAsync("_http._tcp.local.");
foreach (var resp in responses)
{
if (resp.DisplayName == deviceHostName)
{
Debug.Print(resp.IPAddress);
}
}
}
Now making a http request to resp.IPAddress reaches the device advertising it's hostname as 'yourhostname'.
I am using an ESP8266 and it was important to start MDNS on the device BEFORE connecting the WiFi otherwise the device reports it's hostname as ESP_xxxx rather that 'yourhostname' which was the real root of the problem.
Over the past 18 months I have successfully developed an air quality monitoring system that controls an air purifier in my home, I am also using the Blynk platform to monitor and control remotely. Now, I want to migrate this project over to my own website, I have my own website and using standard HTTP commands I now log all the data into a database and graph the data over time.
I want full bi-directional data transfer i.e log data from remote sensors to website and control air purifier settings from website to air purifier. It would appear that one way to do this is by using a webSocket, I have a shared hosting plan with BlueHost so I have now purchased a dedicated ip address and an opened port for both incoming and outgoing connections.
After many hours of trawling the internet and many forums I am struggling to find an example of how to implement this webSocket system. All the examples seem to be for local servers and I cannot find anything that shows what needs to be included in the website end to get a successful connection.
If anyone has any experience with webSockets and BlueHost I would appreciate your help.
Richard
It is relying on what language are you going to use for backend to implement websocket connection no matter what hosting you choosed.
If you want to use PHP, it is pretty straightforward because there is no specific overlay ontop of websocket protocol in this case unlike socketio for NodeJS and others. This example may help you to start which I found in 5 minutes of searching. If you are confused about websocket implementation at all it's a good idea to try websocket for web at first by simple example.
If you want to use NodeJS you may probably want to use existing library something like this.
In case of Java there is SockJS usually used out of the box as standard library for client. So you have to find or make something similar but for C++ if you have enough skills or try to configure simple websocket connection as for PHP.
I have used Firebase library for bidirectional communication with ESP8266, because it is pretty simple and free for small projects. The main benefit of this approach that you don't need to maintain your backend, it just works 24/7 since you've configured connection and business logic. Probably this is what are you looking for. Also you can host static pages on Firebase cloud as well if you need kind of admin interface. Heroku hosting is also free for tiny projects.
#mr.boris
Many thanks for your quick reply and help.
I have been using several examples like your first suggested example, the problem always is that I cannot get passed the "handshake" routine.
Arduino IDE serial monitor output
Connecting to XXXXXXXX
.
WiFi connected
IP address:
192.168.0.110
Connected
Waiting...
Waiting...
Waiting...
Waiting...
Waiting...
Waiting...
Waiting...
Handshake failed.
The port that BlueHost have opened is 1025 could this be the problem?
I have cut done the esp8266 program to the bare minimum
#include <ESP8266WiFi.h>
#include <WebSocketClient.h>
char* WEBSOCKET_PATH = "/webSocket_02.php";
char* WEBSOCKET_HOST = "xxx.com";
char* WIFI_SSID = "xxxxxxxxx";
char* WIFI_PASSWORD = "xxxxxxxxxx";
WebSocketClient webSocketClient;
WiFiClient client;
void setup() {
Serial.begin(115200);
delay(10);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(WIFI_SSID);
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
delay(5000);
if (client.connect(WEBSOCKET_HOST,80)) {
Serial.println("Connected");
}
else {
Serial.println("Connection failed.");
}
webSocketClient.path = WEBSOCKET_PATH;
webSocketClient.host = WEBSOCKET_HOST;
if (webSocketClient.handshake(client)) {
Serial.println("Handshake successful");
}
else {
Serial.println("Handshake failed.");
}
}
void loop() {
}
The port number here is 80 (WEBSOCKET_HOST,80), if I change it to 1025 I get no result at all.
I have an arduino Uno which collect data from sensor, i want to send this data to the cloud using wifi esp8266 who support SSL using the library WifiClientSecure, is there an alternative to send data from arduino to the esp card and esp8266 read this data and send it after that to the cloud, i'm able to work with mqtt but i want to know if there is a way to have a directly connection between the arduino uno and esp8266 without having a third part, any help will be gratefull.
According to my research, the ESP8266 AT Command API does not support SSL. This means you will need to use the Arduino (as an FTDI converter) to program the ESP8266 with custom firmware. This will enable you to use WiFiClientSecure and pubsubclient.
To use the Arduino as an FTDI:
load a sketch that does not use Serial, such as the "Blink" example
connect the Arduino's TX pin to the ESP8266 RX pin
connect the Arduino's RX pin to the ESP8266 TX pin
Now you need to setup Arduino IDE so it can program an ESP8266
In Arduino IDE -> File -> Preferences, paste this into the Additional Boards Manager URLs: http://arduino.esp8266.com/stable/package_esp8266com_index.json (just copy the link as it is instead of clicking)
go to Tools -> Boards -> Boards Manager. Find "esp8266" in the list of boards and click "Install"
Set your board to "Generic ESP8266 Module" in Tools -> Boards
Arduino IDE is ready! But before you caan program an ESP8266 with it you need to connect a reset button and a program button to the ESP8266.
connect a push-button between GND and the ESP8266 GPIO_0 pin
connect a push-button between GND and the ESP8266 RESET pin
add a 10K-ohm pull-up resistor between 3.3V and ESP8266 pin (defaults the reset pin to HIGH)
When you are ready to upload a sketch to the ESP8266, use those buttons like this:
press both buttons
release RESET button
release GPIO_0 button
This puts the ESP8266 in program mode! You should now be able to click the "Upload" button in Arduino IDE. I would suggest using one of the provided ESP826a6 example sketches (like this one) to test everything out.
Here's an overview of the project:
. Arduino Uno sketch: read sensor data, send via Serial to ESP8266
. ESP8266 sketch: connect to WiFi network, receive sensor data from Serial, send via WiFiClientSecure to the cloud.
I will leave the actual code of these two programs up to you, but if you get stuck just leave a comment. Hope this helps!
I am using the 32feet bluetooth library to connect to a device that supports Serial Port Profile (SPP). I try to connect like this:
using (BluetoothClient client = new BluetoothClient())
{
var address = new BluetoothAddress(0xecfe7e11c3af);
BluetoothEndPoint endPoint = new BluetoothEndPoint(address, BluetoothService.SerialPort);
client.Connect(endPoint);
var stream = client.GetStream();
System.Threading.Thread.Sleep(10000);
}
Everything is great until the Connect method is called. At this point, Windows interrupts the program flow with a bubble alert that says
"A bluetooth device is trying to connect -- click to allow this"
At which point the user is led through a wizard that ends up installing drivers and a Bluetooth virtual COM port shows up in Device Manager. I don't want this to happen -- I want to simply access the stream and communicate directly with the device without windows intervening. Is this possible? What can be done to tell Windows to keep out of my business?
I'm attempting to connect to a Bluetooth 4.0 device. I've done something similar in the past with a 2.0 device and Windows does not interfere in this case.
Have a look at http://SimpleBluetooth4Win.SourceForge.net
It's a small wrapper library that uses the windows bluetooth networking API that could help you.
https://msdn.microsoft.com/en-us/library/windows/desktop/aa362932%28v=vs.85%29.aspx
In particular if your bluetooth USB dongle or bluetooth device has been correctly recognized by the appropriate drivers and the remote bluetooth device is already paired with the PC, you don't need to install a bluetooth virtual COM port that shows up in Device Manager but you simply use the write or read calls to access directly the stream for communicating with the paired device.