Is there any way to list the services published through a CBPeripheralManager instance? - core-bluetooth

The macOS/iOS Bluetooth LE API class CBPeripheralManager has the method add(CBMutableService) for publishing a service, remove(CBMutableService) for stopping publishing a service, and removeAllServices() for stopping publication of all published services. The class CBService has a peripheral property for identifying the peripheral through which it is offered. But I am darned if I can see any way to find out what services are published, given a CBPeripheralManager instance. Is there really no way to do this?

Related

Sonos control api: polling rate & subscription

We are controlling the sonos via a small IOT device. This device will be placed at the homes of our customers.
In our home automation system we need to know the playbackstate + volume of the players/groups.
At which polling rate can we ask these parameters ?
We cannot use a cloud server to handle the subscription events.
I tried to put a https webservice in the IOT device with a self signed certificate but this doesn't work.
After I have posted the subscription I get a request in my webservice but the cloud sonos server disconnects immediately.
Probably because of the certificate is self signed - Or can there be another reason ?
Is there another way to recieve status events ?
During discovery In the players Json object there is a key 'websocketUrl'.
The documentation says "The secure WebSocket URL for the device. See Connect for details".
But I cannot find more info about this.
Can this be used ?
At which polling rate can we ask these parameters?
Consider using subscriptions instead of polling. See this answer for more: https://stackoverflow.com/a/60893119/4902948
We cannot use a cloud server to handle the subscription events...
Or can there be another reason?
Is there another way to [receive] status events?
You must host a service that satisfies a set of requirements to receive events. See this answer for more: https://stackoverflow.com/a/57189717/4902948
Also see Details on API credentials and events in New features in versions 11.1, 11.2 (S1), & 12.0 (S2).
Can [the 'websocketUrl'] be used?
This is not publicly available for use.
It would be a lot easier to use the (undocumented but more useful) UPnP APIs. You could simply Subscribe to the UPnP RenderingControl endpoint, then you will get an event every time the volume changes. To find when the track changes, subscribe to AVTransport endpoint.
You can do this with a local server (this is how every Sonos app works after all) and no special cert requirements either.
UPnP events are described in the UPnP spec.
Your question doesn't provide details about the language you're using, but if the device is powerfull enough to run node, you have a good change with my sonos library.
You can just pull the required information from the device as often as you like. Or use the build-in event subscriptions. If you use the events, it will automatically setup an http listener and automatically subscribe to all the events you're listening for.
Events are instant (as in 50ms-100ms after the event took place on the device).
If you request information it is send directly to the device and the device will respond with the answer. Pulling multiple data points per second has never been a problem to me.
Warning as stated above, this uses the undocumented local UPNP api, but since their own app also uses it, I'm guessing that won't change soon.

How can I listen in my client service to a newly registered service in the Eureka server?Listen to Eureka Server events

I have a service 'A' which is being registered with the Eureka server, and I would like the Eureka server to notify that service every time a new service is registered within Eureka.
Is there any way of doing it?
Why don't you poll the registry regularly from the app that needs to know?
Failing that I don't believe there's a built in feature with Eureka to push this kind of alert. You could achieve it though by customising the Eureka project and reacting to the registration. According to similar discussions elsewhere, EurekaInstanceRenewedEvent that is fired when a new instance first heartbeats is a reliable event to work around. I'm not sure how quickly you need to be notified.

Spring boot applications with realtime communication

I have a core application and a provider application.
The provider application is added dynamically. It needs to register itself to the core. Originally I assumed the providers will have a public IP and would register there IP to the core and the core would call them when it needs some service. (Or connect to a VPN and the IP would be accessible)
This approach became hard to manage and there was overhead when checking the status of the provider.
I thought of some alternatives and don't know which one to use
Websockets. The providers would subscribe to some topics. I haven't figured out how to publish to a single one yet, but I'm thinking the providers will register their uuid when subscribing and we publish to just one uuid which only one provider will subscribe to.
Use Apache MQ or Kafka or something similar.
Implement a TCP communication (Spring integration might help, but I'm not sure )
Those are the ideas I have and I'm not sure on how to structure them for best performance and cleaner code.
What other option do I have?
Edit
#cool suggested that I use a discovery server and it makes more sense. The providers themselves contain a list of devices. Does it make sense to publish them separately? They all would have the same IP but device Id will be associated with the metadata (perhaps the id would be part of the url).
It sounds like what you need is a discovery service like eureka.
What it does basically discovering/providing services as you need in your case. You can check out the details from spring-eureka

How to subscribe a specific instance within an elastic beanstalk application to an SNS topic?

Ok, so I have an elastic beanstalk application with a scalable web tier, served behind an ELB. Long story short, I need to be able to subscribe a specific instance within my web tier to an SNS topic. Is it safe for me to use a standard method to get the instance ip address (as detailed in python here How can I get the IP address of eth0 in Python?) and then simply subscribe to an SNS topic using that ip as an http subscriber?
Why? Good question...
My datamodel is made up of lots of objects many of which can have an attached set of users which may want to be able to observe those objects. This web tier in my application is responsible for handling the socket interface (using socket.io) for client applications.
When a user is created in the system, so too is an SNS topic for the user, allowing notifications to be pushed to that user when an object it is interested in changes. The way I am planning to set this up, a client application will connect to EB via socket.io at which point the server instance it connected to will subscribe to that user's SNS topic. Then when an interesting object changes, notifications will be posted to the associated user's topics, thus notifying the server instance that the client application has an open connection to, which can then send a message down the socket.
I believe it is important that the specific instance is subscribed rather than the web tier's external CNAME or ip, as the client application is connected to a specific instance and so only that instance can send messages over it's socket. Subscribing the load balancer would be no good as the notification may be delivered to an instance that the user is not connected to.
I believe the question at the top is all I need, but I'm open to creative solutions if my reasoning seems flawed??
Just incase anyone gets stuck down this same rabbit hole... The solution was to use Redis pub/sub rather than SNS and SQS.

How to hook the service control handler from a Topshelf service

I have an existing Windows service that uses Topshelf very successfully.
I now need to have the service receive notifications when specific USB devices are connected / disconnected to / from the machine.
I can't see anything in Topshelf that would allow me to do this. But I believe that there is a way to do it using Win32 APIs like ServiceControlHandlerEx and RegisterDeviceNotification with the DEVICE_NOTIFY_SERVICE_HANDLE option.
Will using these Win32 APIs interfere with Topshelf? As I understand it, Topshelf wraps the service control handler itself so my service also trying to do the same thing may cause it some problems?
Update:
It is possible to hook device notifications from the service control handler within a Topshelf based service. See sample project for details. Many thanks to Chris Patterson for his help.
Topshelf won't interfere with you calling these Win32 APIs.

Resources