Transmit binary file to device using BLE - javascript

I am working on an app which can read device information via bluetooth BLE. So far I've been able to connect to the device and read certain properties like state of charge and firmware version number on iOS, Android, and within Chrome. However, now I'm at the point where I need to update the firmware and I am confused how to do so.
Little back story, the app is written in Ionic + Vue + Capacitor so everything is JavaScript/TypeScript. So the BLE plugin I'm using is the Capacitor Community Bluetooth LE. Within the documentation it has a write method which wants deviceId, service, characteristic, and value. I know what I need to use for the first 3, but value is suppose to be DataView. Somehow I need to take a binary bin file and transmit it via this write command. I noticed that DataView is an ArrayBuffer with byteLength and byteOffset. I don't really know how to get my file into this format.
Assuming I have deviceId, service, characteristic, how can I grab this file and transmit a DataView using this write method?
Thanks in advance.

The native SDKs offer a "Socked"-based communication directly over the L2CAP protocol. (GATT uses L2CAP internaly)
Android
Open a L2CAP Channel via BluetoothAdapter#listenUsingL2capChannel()
Connect to the L2CAP Channel via BluetoothDevice#createL2capChannel(int)
iOS
Open a L2CAP Channel via CBPeripheralManager#publishL2CAPChannel()
Connect to the L2CAP Channel via CBPeripheral#openL2CAPChannel(int)
When a L2CAP Channel is registered an PSM (the "Port") is allocated by the device. This number must be communicated to the other peers. This could be done by including the number in the BLE advertisement or by exposing it over a GATT Characteristic

Related

Connect and read data from a bluetooth device with NodeJs?

I have a small hygrometer/thermometer that is bluetooth and comes with a proprietary application that connects to it to read it's data. The device is meant to connect to your smartphone. But I suppose it could connect to my laptop like any other device, but the application it uses is mobile only, so I couldn't do anything with it if I did.
The issue I am really wanting to solve is that obviously I need to be in range of the bluetooth to be able to connect and read data from the device. But I want to be able to monitor it when I am not home. What I was thinking about was keeping a laptop connected to this device, and then running a node server locally that sends the data readings every few minutes to a hosted database, where I then could build a small application that can consume the data sent to the database.
In my limited research, I found this: https://www.npmjs.com/package/node-bluetooth
Which looks like it would help me immensely. And also this post from Google: https://developers.google.com/web/updates/2015/07/interact-with-ble-devices-on-the-web
I am a bit ignorant on how bluetooth works in terms of how something like your phone for example, actually connects to the BT device. Is it reading an address 'broadcasted' out from the BL device? Would I need a MAC address for the device or something along those lines? I guess I am struggling to understand how that even using the aforementioned library, I actually connect to the device. I think I would need some sort of address to even do that. Furthermore, is it possible this device doesn't allow connections from anywhere other than through it's proprietary application? Excuse my ignorance with this again, this is something I just started diving into this afternoon.
It's maybe not so practical, but I want to see if I can do something like this using just Javascript.

How to Receive Push Notification on website using Parse JS SDK?

I have configured push notifications on Parse-Server & in Android app. But I am not able receive push notifications in a website using Parse JS SDK. They don't provide any method to subscribe for push notifications in ther JS APIs. There Documentation (JS) only talks about subscribing to mobile devices not browsers.
SUBSCRIBING TO CHANNELS
The JavaScript SDK does not currently support subscribing iOS and Android devices for pushes. Take a look at the iOS, Android or REST Push guide using the platform toggle at the top.
So, I concluded that web browsers can't subscribe just by using Parse JS SDK? So, how should I subscribe & receive Push notifications on a web browser from Parse Backend?
Update:
I haven't test but If I use ServiceWorker to get subscription & subscribe user to some channel, can I use the default Parse Class Installation for saving subscription & then use that (web) Installation in Cloud Code to send Push?
Parse-Server only supports iOS and Android push notifications. It doesn't even handle web sessions conveniently. There are no Installations for web, because you don't install things for web. There are Sessions, but those don't do anything for Push.
I have tested it and got achieved desired results via following. As Jake said, for web there are no Installations in Parse. So, in order to receive push notifications on the web, you have to
Register a Service worker to get pushSubscription and hande push, click events etc.
Save pushSubscription to server. It will be used to send pushes to Web.
Integrate Push notifications on Parse-Server (FCM etc) or web-push if you want.
Send push via Client SDK or Cloud Code, it must be received.
Further, the Installation class cannot be used for web pushes.

parse.com REST API using build.phonegap Javascript Push Notifications Android and iOS

Currently using build.phonegap.com and parse.com to enable push notifications across two platforms (Android and iOS).
Using the PhoneGap PushPlugin and parse.com REST API I'm able to register an Android device and send the details to parse successfully.
Although I have problems and questions regarding sending the "Pushes".
1.1) When registering an "installation" (https://parse.com/docs/rest#installations-uploading) I'm dynamically creating a random UUID installationId. Is this correct? Or does parse.com have to do this?
1.2) For Android I'm registering pushType for GCM, as I'm not using the Android SDK. Which leads me to question 2.
2) When I setup my Android app settings for push, I'm given a server API Key... parse.com has a keys section, but only for Windows and iOS... does this mean they can't send push using GCM for Android? Even though you can select this when uploading an installation?
The short question. Is it possible to use just the parse.com REST API to register Android devices to send push via GCM (Androids native push service)? Apple devices are working using this method to register them and send notifications.
To answer your short question: Is it possible to use just the parse.com REST API to register Android devices to send push via GCM (Androids native push service)?
Yes
I did not have to set installationId and I set pushType to "gcm".
In Parse settings, there is a section "GCM Push Credentials" where you enter "Sender ID" and "API Key". You get both of these from Google. When you create the Parse Installation, you also have to set GCMSenderId to the same thing as "Sender ID".
Note: I'm using the cordova push notification plugin and had to make some changes to PushPlugin.java to get background push notifications to work with the way Parse sends them. That's another topic though.
If this helps anyone - I moved over to using PushWoosh with a PhoneGap Build plugin - very simple and integrates in minutes. PushWoosh also has easy integration with Apple to setup and generate certificates (which is great when working on a PC).
https://build.phonegap.com/plugins/1297

Sending an SMS from mobile via HTML5/JavaScript

I'm creating a web application for mobile devices that will be downloaded in one of the markets with a mini web server and run on any OS ( iOS , android , Windows8 , etc. ) .
I want an application to be as independent as possible of the OS. I only wanted to use HTML5 and JavaScript .
The application allows a user to make a number of orders just by clicking buttons. Example : [List contacts ]
I need to click [List contacts ] and is sent a text message automatically to other mobile device with an android application that receives the request and sends the response via sms . The response has to be read by my web application . The application can be able to work without network / Wifi .
I've been searching and I only found ways to open the native application for sending sms.
I see that question, but I want to create my own way to send sms without dependencies of other applications.
Is there any way to make this submission automatically?
Or can I use/create some plugin to use on JavaScript to do that?
[EDIT] Can this might be a possibility? Can someone explain me?
I believe the essential information was already mentioned in the comments, but my 2c here anyway.
As already commented, with current modern mobile operating systems apps don't get unlimited access to SMS functionality. From the user point of view allowing this would be potentially quite a hazard, since SMS's usually cost money and user should be in control of such activity, instead of having a random app sending and receiving SMS's freely (without user knowing it). Android is a bit more flexible regarding this kind of functionality, but as mentioned, iOS and also Windows 8/Windows Phone 8 only allows you to integrate to the SMS sending application and for SMS reception, there's no proper way to get access to incoming SMS's.
So, with a native container (such as PhoneGap) you could get one step forward with Android, but for other platforms the possibilities are limited to using the native SMS application. If you need to use SMS for some reason in the backend side, services such as Twilio are probably your best shot, but using SMS locally on the device is pretty much a no-go, unfortunately.

Offline Web Apps and database sync

I need to ask for some advice regarding offline web applications and database sync.
Offline Scenario
We have a web site (HTML5) that needs to operate in an offline mode for extended periods of time with complex data, the product owner does not want the data put into local storage.
We have two options as I see it;
Use javascript to detect if we are offlline and if so point the urls to a local web server that replicates the stack at the data center and writes to an offline db
◦Biggest stumbling block is how, on the first load if you are offline do you get the location (URL) of the local web server? i.e. user goes to www.xyz.com, but you are offline so
Question 1: how to redirect him to localhost.xyz.com via javascript for that first call
Point all calls at the client , offline or not to a wcf service that checks offline status at the NIC and redirects every web and service call to the correct place
◦seems like a big job,
Question 2: is there any product/ opensource project you guys know off that does this?
Sync Scenario
•They want to use MS sync framework
◦But they have many clients syncing to different database, so you either need 1 sync service per client or some way to identify who the client syncing is and point them to the correct place
◦Need to minimize locking during sync as other clients are using the same tables during sync
Question 3: can the sync framework be extended to even do this
Question 4: What other options exist for database sync on MS platform?
Thanks
If the user puts the URL into their browser, they are going to go that URL. There is no javascript at that point. You would only have Javascript once a page is loaded. You will have to search for a better solution.
Here is an idea: Users ALWAYS go to the local website, and if the remote site is up, then you redirect them.
In terms of MS sync I do not know what it is, so I cannot help you there.
Re What other options exist for database sync on MS platform: there is also SQL Azure Data Sync, a windows azure web service. It is actually built upon the Microsoft Sync Framework you refer to.
There is an example in the book "Programming Microsoft SQL Server 2012" by Leonard Lobel & Andrew Brust (MS Press) - chapter 13 covers building occasionally connected systems that incorporate SQL Azure Data Sync, Windows Azure and the Windows Phone 7 development platform. In the sample solution, on the back end, an on-premise SQL Server database is kept synchronized with a public facing SQL Azure database in the cloud using SQL Azure Data Sync. The cloud database is exposed using WCF Data Services (also hosted in the cloud by deploying to Windows Azure) and consumed via OData by a mobile client application running on a Windows Phone 7 device. The sample solution detailed in the chapter demonstrates how these technologies work to keep data in sync across on-premise SQL Server, SQL Azure databases in the cloud, and local storage on Windows Phone 7 devices.
Sync Framework do not lock tables when synching.
depending on what client database you want to use on the client, you can either use Sync Framework itself which works with MS databases (SQL CE, SQL Express,LocalDB,SQL Server, SQL Azure) or you can use the Sync Framework Toolkit
whichever platform you choose, i would suggest simply writing to the local store and synching it rather than dynamically choosing which store to use when.
for example, if you went offline and you wrote to the local store. then your network monitor detects you are back online and redirects you to the online service, what would you do with the data you stored locally? or you transacted online and you suddenly went offline, how recent/updated is the local store for you to actually starting working agaisnt it?
You could use Service-Workers to make the website work while users are offline. see: Making PWAs work offline with Service workers. This allows your website to work for the users if they are offline (they need to have internet at least once every 24 hours).
Service-Workers also allows you to detect when your user is offline or online, and you can for example use the IndexedDB to store your offline changes and then synchronize them when the user is online again.
I don't know about MS Sync.

Categories

Resources