How can I implement actions based on my rest API - java

I have a plan of automating a process via REST api and multiple smart devices. What I am trying to do is the following. I have 4 devices that each do a series of actions to complete their task. (practicaly Im gonna be lighting 4 leds in a particular series based on the device). Im currently emulating this in Java (since I dont have the devices at hand)
So for example lets say device no.1 lights up the red led first for 10 seconds, after that device no.2 needs to light up for 10 seconds etc. That's the task. This is done automatically and forever till I shutdown the program.
I have developed a REST API using JAVA and the JAX-RS library where I state the devices and their info (so device name, current state ex. Yellow Led ON/OFF etc.).
What I dont understand is how I am gonna make the program I have now respond to the info from the API. How can I make my program get notified when a value is changed on the API info?
How can I make device 2 poll the API till it gets the response to start its action? Or make it so it starts the action if i manually change the value on the server data? Example if the yellow led is on, and i go in the server database and put it on off, how will my application get notified and change the state of the simulated led?

Since you are using HTTP, most suitable solution is to use web sockets. You can use them for full duplex communication. When you receive input from one device, you can process it and inform other devices. Note that this is not suitable for a large client base.

Related

Is there a way to issue the * commands to the mobile provider to query things like balance, minutes remaining etc from within android app?

The cellphone network provider in my area has a few functions you can do by dialing what I am calling the "star commands", that is you type and asterix(*) followed by the code of your command and press send and you are able to query account balances and a whole slew of other functions that the cell network has made available. I think this is common place among all cell networks.
I want to be able to make these commands and read the responses, issue other commands based on those responses and so on, all from within my android app.
Does anyone has experience doing this?
Those commands are known as USSD commands. You can use TelephonyManager.sendUssdRequest to send a USSD command, providing a callback to receive the result form the mobile network.
Bear in mind Android only introduced support for invoking them programmatically in API 26 (Android 8.0). If you need that functionality on any earlier Android, you'll need to do something hacky, writing some code that automates pressing buttons of the system UI

Structure of Android app (java) continuously scanning for Bluetooth devices

I want to create an application that will continuously scan for other BT devices while the process is active (not killed).
The main idea is to scan for devices that are within the custom range (signal strength that I hope I can get from RSSI) and to log those occurances to a database in cloud.
I want to use a tabbedActivity:
1 tab - Current visible devices (needs to be refreshed every x seconds)
2 tab - history of ocurrances that has been sent to the database during current session (I have to implement some methods to eleminate duplicates etc.)
The question is how the structure of my application should look like?
Where should I put whole BT thing? As I suppose it shouldn't be in the MainActivity, because it can lagg the whole application. Should I use a service class? Another thread? The same question applies to the part of the program, which sends info to database.
Any sugestions regarding the internal structure would be great.
Any tips regarding energy consumption also.

Click on an x and y position in another android application

I have a Bluetooth led bulb that will only work with one specific app. I want to create an app that will open the bulb app (iHomentLight) and gradually increase the brightness slider to wake me up in the morning. I want to know if it is possible to do this, and if so how?
Apps are sandboxed so that someone can't use this kind of thing to take advantage of you (and steal your bank info for example). Some apps work around this via accessibility service.
How to perform Other app list item click using accessibility service like Voice Access app?
However, you are probably better off just figuring out what the bluetooth API for your bulb is and teaching your app to work with it. You'll have your app connect directly to the bulb and do it yourself. Search Google for the bulb name and see if anyone has reverse-engineered the API.
Here is an amazing writeup on how to reverse engineer a bluetooth API:
https://medium.com/#urish/reverse-engineering-a-bluetooth-lightbulb-56580fcb7546
Spend some time trying this out, I think it'll be a more useful skill than messing with the accessibility service.
There are around three approaches you can take:
1 - If you have access to iHomentLight's API, you could potentially send a series of intents to the app and have it gradually adjust the light over time.
2 - If that is elusive, I'd recommend trying to sending touch commands via the terminal. For example 'input tap x y android'.
How to run terminal command in Android application?
3 - Or you can use Tasker App to make commands that will adjust the light just as well

How to create immediate Notification System in website

I am implementing a small social networking website, and I am trying to implement notifications.
Notifications have the following requirements
All users will receive notifications whenever users they follow do
certain events (like a post, create a post,leave a comment, etc...
When a set of notifications for a user is unread, just like on facebook, the user will
continue to see a read notification icon on their navbar.
Problem : I am taking an example to describe my problem for better understanding for everyone.
Suppose there are two users A and B. A & B are friends and A post something, suddenly B like the post of A then A should have to receive the notification immediately.
So how can i achieve this immediately receiving of notification process?
Should i send a call to server on each millisecond to check whether there is any unread notification is available for A user ? In this case thousand millions of call creating for multiple user. It is feasible solution ?
(I think it create unnecessary load on my website. As i think facebook and stackoverflow do not use this way).
Provide me a suitable solution just like fb and other webiste using.
Technology Using in my project: Java and MYSQL
You should use JavaScript (client side) along with Java - MySql (Server side), and more specifically Ajax. You will need some time to understand the concept and the usage but it does exactly what you want.
To give more details, what you need is to create a partial view where the notifications will appear, and update this partial view async (with AJAX).
Dont reinvent the wheel.
Use ajax call to server at each interval and check your server and update nav acc.
1.So how can i achieve this immediately receiving of notification process?
2) Should i send a call to server on each millisecond to check whether there is any unread notification is available for A user ?
Your above both questions answers solve through GWTEventService implementation.
Through it you can write code that will avoid client to server round trip.
GWTEventService is an event-based client-server communication framework. It uses GWT-RPC and the Comet / server-push technique. The client side offers a high-level API with opportunities to register listeners to the server like to a GUI component. Events can be added to a context/domain on the server side and the listeners on the client side get informed about the incoming events. The server side is completely independent of the client implementation and is highly configurable. Domains can be defined to decide which events are important for the different contexts.
Refer link: https://code.google.com/p/gwteventservice/

What is the best practice for implementing smack into an android app?

I'm writing an android game that requires push notification. I've got the aSmack library imported and working, but I don't know how to implement it efficiently to achieve the following:
1.) Each player should be notified when the other player makes a move.
2.) The server should be notified each time either player makes a move, in order to avoid any cheating (such as one player making two moves in a row, etc.)
I've got openfire and aSmack connecting with each other. I need to write a server side program to handle the server-side. Should I put the two users and the server in a group chat? Would it better to have three individual chat sessions?
I think you want to take a look at XMPP Pubsub.
For C2DM: IIRC it won't suit your use case, as it provides no back channel (only push TO the devices are possible)

Categories

Resources