I was trying to understand if it is possible(if yes how) to continue the OTA process after downloading the bin file hosted in a remote IP (within the network) ? The code is to be running on ESP32. (Edit) i am trying to introduce a method of self OTA update..which can also be triggered by hitting an end point of the esp webserver (either through mqtt, http etc etc)
I am referring to How to enable the server to automatically download files using arduino for ESP32 WebServer without using SPIFFS and instead using SDcard file but it focusses on downloading from sd card but not network.
Currently, I am following the code mentioned in https://randomnerdtutorials.com/esp32-over-the-air-ota-programming/ which currently deals in uploading the bin file through browser, which I am trying to automate.
If somehow I can trigger this part of the code with the data programmatically then I think my question will still be solved.
server.on("/update", HTTP_POST, []() {
server.sendHeader("Connection", "close");
server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
ESP.restart();
}, []() {
HTTPUpload& upload = server.upload();
if (upload.status == UPLOAD_FILE_START) {
Serial.printf("Update: %s\n", upload.filename.c_str());
if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { //start with max available size
Update.printError(Serial);
}
} else if (upload.status == UPLOAD_FILE_WRITE) {
/* flashing firmware to ESP*/
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
Update.printError(Serial);
}
} else if (upload.status == UPLOAD_FILE_END) {
if (Update.end(true)) { //true to set the size to the current progress
Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
} else {
Update.printError(Serial);
}
}
});
Regards,
Shariq
I am looking for a way to play the encrypted HLS streams in UWP MediaElement , I am able to play the url that has key url given but I need to pass the key from app, not from the key url.
#EXT-X-KEY:METHOD=AES-128,URI="stream.m3u8.key",IV=0x00000000000000000000000000000000
IF the key file is present the below code works fine.
async private void InitializeAdaptiveMediaSource(System.Uri uri)
{
AdaptiveMediaSourceCreationResult result = await AdaptiveMediaSource.CreateFromUriAsync(uri);
if (result.Status == AdaptiveMediaSourceCreationStatus.Success)
{
ams = result.MediaSource;
mediaPlayerElement.SetMediaPlayer(new Windows.Media.Playback.MediaPlayer());
mediaPlayerElement.MediaPlayer.Source = MediaSource.CreateFromAdaptiveMediaSource(ams);
mediaPlayerElement.MediaPlayer.AutoPlay = true;
mediaPlayerElement.Stretch = Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT.Stretch.Uniform;
ams.InitialBitrate = ams.AvailableBitrates.Max<uint>();
//Register for download requests
ams.DownloadRequested += DownloadRequested;
////Register for download failure and completion events
//ams.DownloadCompleted += DownloadCompleted;
//ams.DownloadFailed += DownloadFailed;
////Register for bitrate change events
//ams.DownloadBitrateChanged += DownloadBitrateChanged;
//ams.PlaybackBitrateChanged += PlaybackBitrateChanged;
////Register for diagnostic event
//ams.Diagnostics.DiagnosticAvailable += DiagnosticAvailable;
}
else
{
//// Handle failure to create the adaptive media source
//MyLogMessageFunction($"Adaptive source creation failed: {uri} - {result.ExtendedError}");
}
}
But I want to pass the key from my app to decrypt the video and play in the MediaElement.Any help regarding this is greatly appriciated.
So I have this code on my web app:
const connectedRef = firebase.database().ref('.info/connected')
connectedRef.on('value', function(snap) {
if (snap.val() === true) {
console.log('CONNECT')
connected = true
} else {
console.log('DISCONNECT')
connected = false
}
})
When I go offline using the "offline" checkbox in the Developer tools, I expect to see a single DISCONNECT message. What I see instead is:
-- app starts
DISCONNECT
CONNECT
-- here I go "Offline"
DISCONNECT
CONNECT -- What ?
I don't undestand why I see my application getting immediately "connected" again while I'm still offline. Bug? Or I'm doing something wrong?
How one forces Windows to disconnect from BLE device being used in UWP app? I receive notifications from some characteristics but at some point I want to stop receiving them and make sure I disconnect from the BLE device to save BLE device's battery?
Assuming your application is running as a gatt client and you have the following instances your are working with in your code:
GattCharacteristic myGattchar; // The gatt characteristic you are reading or writing on your BLE peripheral
GattDeviceService myGattServ; // The BLE peripheral' gatt service on which you are connecting from your application
BluetoothLEDevice myBleDev; // The BLE peripheral device your are connecting to from your application
When you are already connected to your BLE peripheral, if you call the Dispose() methods like this :
myBleDev.Dispose(); and/or myGattServ.Dispose(); and/or myGattchar.Service.Dispose()
you surely will free resources in your app but will not cleanly close the BLE connection: The application looses access to control resources for the connection. Nevertheless, connection remains established on the lower levels of the stack (On my peripheral device the Bluetooth connection active LED remains ON after calling any of Dispose() methods).
Forcing disconnection is done by first disabling notifications and indications on the concerned characteristic (i.e. myGattchar in my example above) by writing a 0 (zero) to the Client Characteristic Configuration descriptor for that characteristic through call to method WriteClientCharacteristicConfigurationDescriptorAsync with parameter GattClientCharacteristicConfigurationDescriptorValue.None :
GattCommunicationStatus status =
await myGattchar.WriteClientCharacteristicConfigurationDescriptorAsync(
GattClientCharacteristicConfigurationDescriptorValue.None);
Just dispose all objects related to the device. That will disconnect the device, unless there are other apps connected to it.
For my UWP app, even though I've used Dispose() methods, I still received notifications. What helped me was setting my device and characteristics to null. Example:
device.Dispose();
device = null;
Not all to certain of how "correct" this programming is, but it's been working fine for me so far.
The UWP Bluetooth BLE sample code from Microsoft (dispose the BLE device) didn't work for me. I had to add code (dispose the service) to disconnect the device.
private async Task<bool> ClearBluetoothLEDeviceAsync()
{
if (subscribedForNotifications)
{
// Need to clear the CCCD from the remote device so we stop receiving notifications
var result = await registeredCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.None);
if (result != GattCommunicationStatus.Success)
{
return false;
}
else
{
selectedCharacteristic.ValueChanged -= Characteristic_ValueChanged;
subscribedForNotifications = false;
}
}
selectedService?.Dispose(); //added code
selectedService = null; //added code
bluetoothLeDevice?.Dispose();
bluetoothLeDevice = null;
return true;
}
Remember you must call -= for events you have called += or Dispose() will never really garbage collect correctly. It's a little more code, I know. But it's the way it is.
Not just with bluetooth stuff, I will remind you - with everything. You can't have hard referenced event handlers and get garbage collection to work as expected.
Doing all the disposing and null references suggested didn't achieve the Windows (Windows Settings) disconnection I was looking for.
But dealing with IOCTL through DeviceIoControl did the job.
I found that after calling GattDeviceService.GetCharacteristicsAsync(), BluetoothLeDevice.Dispose() does not work. So I dispose the Service I don't need.
GattCharacteristicsResult characteristicsResult = await service.GetCharacteristicsAsync();
if (characteristicsResult.Status == GattCommunicationStatus.Success)
{
foreach (GattCharacteristic characteristic in characteristicsResult.Characteristics)
{
if (characteristic.Uuid.Equals(writeGuid))
{
write = characteristic;
}
if (characteristic.Uuid.Equals(notifyGuid))
{
notify = characteristic;
}
}
if (write == null && notify == null)
{
service.Dispose();
Log($"Dispose service: {service.Uuid}");
}
else
{
break;
}
}
Finally, when I want to disconnect the Bluetooth connection
write.Service.Dispose();
device.Dispose();
device = null;
I'm using OpenPop DLL and it's working great for my project but i'm getting on issue when i'm using with Gmail Account. I'm not able delete the Email from Gmail after reading. I'm using following code and latest OpenPop DLL :
using (OpenPop.Pop3.Pop3Client pop3Client = new OpenPop.Pop3.Pop3Client())
{
// Connect to the server
pop3Client.Connect(
ConfigurationManager.AppSettings["host"],
Convert.ToInt32(ConfigurationManager.AppSettings["port"]),
Convert.ToBoolean(ConfigurationManager.AppSettings["useSsl"]));
// Authenticate ourselves towards the server
pop3Client.Authenticate(
ConfigurationManager.AppSettings["username"],
ConfigurationManager.AppSettings["password"],
AuthenticationMethod.UsernameAndPassword);
// Get the number of messages in the inbox
int messageCount = pop3Client.GetMessageCount();
if (messageCount > 0)
{
// We want to download all messages
allMessages = new List<Message>(messageCount);
// Messages are numbered in the interval: [1, messageCount]
// Ergo: message numbers are 1-based.
// Most servers give the latest message the highest number
for (int i = messageCount; i > 0; i--)
{
allMessages.Add(pop3Client.GetMessage(i));
}
// Process all the messages and save in database
}
// On successful insert in database, delete the same message from email server
pop3Client.DeleteAllMessages();
pop3Client.Disconnect();
pop3Client.Dispose();
}
Can you please let me know if there's anything wrong i'm doing in code? You help will be appreciable.