Connect and read data from a bluetooth device with NodeJs? - javascript

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.

Related

peer to peer (p2p) connection between smart tv and smartphone

So, I program for a couple of years now and I only programmed websites. However, I wanted to make a Web App for my LG TV and already downloaded the SDK, ide, emulator, etc.. And it was pretty easy to get a basic App that works fine. I also used PhoneGap (used to make mobile apps with HTML, CSS, js, node js) to do the same App for my android phone.
So my problem is that I need a way to get p2p (peer to peer) connections between my tv and my smartphone. I want to do a simple game, where the tv is used as a monitor and the phone as a controller. However, I don't want to use a web server. You should be able to play it, without an internet connection, but with a wifi network.
I already looked for WebRTC, but I didn't understand how it works, to be honest. I also read something about socket io. From what I have understood is, that the tv needs to run an HTTP-server and then the phone needs to connect to it? But then, the smartphone somehow needs to know the IP of the HTTP-server. Otherwise, you would have to type the IP every time you want to play.
I don't need a finished code, just a point where I can start and an explanation.
Thanks!
Turns out, there is something called ConnectSDK which solves my problem (It works not only with LG TV's but also with 7 different platforms). The SDK is made by LG, however it took me 8 months to find it.
Why? Because LG is not telling you about this SDK on their own page for TV developers... Even though creating a websocket server on the phone and make the TV join this server by manually typing the ip works, however ConnectSDK provides a much better user experience.
It feels like they don't want that people programm good apps for their TV's.
LG communication skills: 1/10
Given the specifics of the project (small lan), to bypass the necessity of inputing an ip adress, i usually do :
1- Retrieve the phone ip address and subnet with phonegap js api;
2- Scan the subnet range for http server with a predefined route to identify the smart tv app(at most 255*255 adress to scan for big lan; with js its easy to parallelise hundreds/thousands of simultaneous requests);
----> this route should output something readable identifying the appliance, in case of multiple results.
3- Display the list of results on the phone; retrieve user input; then connect.
You need to use websockets (hence, why not socketio implementation) to be able to do real time interaction with small delay given the parameters of your project.
Enjoy !

Capture device name

I would like to capture the "computer name"/"device name" of the user. (Ex: Joes-iPhone) It seems like a nice touch to be able to see what devices have connected with the users login so they can see if there is unauthorized access to their account.
Over and over I see people say this is impossible from a web page for JavaScript, HTML, PHP, etc. Yet when I log into my bank, Facebook, Google. Low and behold, there is every device I've connected with. This means it is most definitely possible.
There was one instance where one of my accounts was logged into by someone and this was a big help in identifying what was going on and I love this feature now. I would like to implement this but am stuck in a city full of dead end roads!
Does anyone have any knowledge of how they are accessing this? Or even theories? I don't care what language or technique.
I'm very curious to see what people come up with. I do have an app for Facebook, so I could see the app accessing it and storing it for the browser site, but I have no app for the bank or Google and I have devices listed in Facebook that were not used within an app, only through the browser. To my knowledge I have never authorized any access to anything beyond what the browser is capable of, so there must be something I'm missing.
Short answer: It's true, it can't be done.
But why not??
Your device name is used when your device connects to your router -- but that's where it stops. Your router doesn't allow that information to be broadcast any further. When your computer/tablet/phone requests a web page, your router is the one actually asking for the page -- and he refers to himself by his public IP, which is shared by all the devices on your LAN.
Second-Best
What can be seen by external Internet entities is your user-agent (the type of browser you're using), which can give someone a pretty good idea of what operating system you're using, and therefore what sort of device you're on (mobile vs. desktop/laptop, Windows vs. Mac, etc.). The user-agent info is available as a string, and can be accessed by PHP via the $_SERVER['HTTP_USER_AGENT'] variable.
The PC name is only accessible through LAN (another PC connected to the same modem/router), if such a request hasn't been blocked on your PC. It is not distributed by browsers.
What browsers transmit is the browser info and operating system as well as the IP address. That's all. Some sites allow you to give a nickname to each machine so you can identify them, and they can then use cookies to remember which is which.
EDIT: The only thing I can see is that they could be using Java or Flash to do it.

Offline symfony2 application

Situation
I'm building a little chat using Symfony2. I'm wondering if there are possibilities to make the chat usable in offline mode. I'm not expecting to actively chat with connected user. I'm planning to make the user able to write message in offline mode (in the metro for instance), and then send it when connection is back again. Important: I would like to compute in the fact that connection can be gone for a long time. I remember beeing with people working in the Eurostar (Paris - London) and using their computers/phone while in a submarine tunnel for an hour or so. There was no connection at all. So in this case, how can you store a message for such a long time before sending it?
Problem
I found some interesting tutorial defining the HTML 5 offline mode. They define the capabilities of this offline mode with sending message but doesn't give example. Moreover, it seems that the only stuff we can put in the manifest are static files (css, javascript, html, pictures...)
My question is then, how do you store the written message from the user after she/he pressed the "send" button and is offline? Is it a javascript variable? Or is there html 5 features that exist?
Cheers!
You can do this via HTML5 local storage:
http://www.redrobotzoo.com/posts/html5-local-storage-and-local-databases-tutorial/
This example has very nice examples so it should not be a problem for you to make it work.

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