micropython timers blocked by microwebsrv - esp32

I am using ESP32 and micropython to create electric blinds. I am also using MicroWebSrv with websockets to control the blinds from my phone using a web page.
I want to be able to control it using voice commands to Google Assistant.
I was able to make it work with IFTT and Adafruit.io feed. The problem is that after some time my ESP32 looses connection to the adafruit and I was not able to make it reconnect easily. It happends all the time, even when I only leave the mqtt library alone on the ESP32 and nothing else. I tried checking messages every 1sec up to 10sec (to avoid reaching the free Adafruit.io limit of 30 items per minute), made no difference.
I'd like to ask if there is some other way how can I control the ESP32, ideally without the Adafruit.io or any other third party (IFTT is fine), as this is causing me the troubles. I even have public IP address, so I can directly send for example HTTP requests to my ESP32 from the internet or something.
So is there some other way how Google Assistant can tell my ESP32 to OPEN or CLOSE the blinds?

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.

Stream real time video from local IP to browser in an external network using websocket/webRTC with raspberry pi 3b+

Anybody here with some experience in websockets and webRTC using TURN/STUN servers?
Requirement:
Send real-time video feed from local IP to browser in an external network and I need some help implementing via raspberry pi 3b+. My camera source is android device, and using 3rd party apps I am able to generate the video feed over local network. Using the same app I can stream via Youtube Live,but getting a latency of about 2 secs in ultra low latency mode and dvr enabled. And I am trying to reduce the latency of the stream.
Q1. Do the semi-public TURN server provide a one to one peer. Or anyone can just jump into the URL and view and override what I am streaming?Please provide few list of service providers.
Just for information there would be 1-2 users browser connected at max.
Q2. Do I need Janus gateway to send webRTC/websockets data into the TURN/STUN server? Since my raspberry is connected to a different network and I cannot port forward due to carrier constraints.
Q3. Do I need both STUN/TURN servers or do I even need webRTC instead of websockets to send my video stream over the internet. Is websockets not sufficient?
Q4. Since we are not implementing over local network do we need to install coTURN too on raspberry pi?
Q5. Is there any android app that can publish the data from camera to websocket/werRTC server with a public ws URL?
Any help would be really helpful.
Q1. TURN servers relay media. They do this by allocating for every connecting peer a relay port between 49152–65535. This relay port will then be used to transmit the media to the second peer. The peers will know which relay ports to use automatically since this is part of the ice gathering process. To get back to your question: Other Peers cannot write to that relay port, it is 1 to 1 with handshakes, there is no chance of someone else overwriting it.
Q2. You definitely do not need a Janus Gateway to use TURN. TURN and STUN will probably work fine for NAT-Traversal without port forwarding.
Q3. You need at least a TURN server (but you ideally want to use 1 STUN server and 1 TURN server). STUN will work in most cases, but will fail if there are firewalls or complicated NATs, which block inbound udp connections. TURN is just the fallback for those cases.
Needing WebRTC? For just streaming videos, it depends on the use case. A sequence of images can be transmitted over websockets, they can handle Blobs fine. But you won't have a very fluent, high fps AND high resolution video stream this way. And of course, I know of no usable way to transmit audio over websocket.
Q4. The raspberry pi is a Peer that transmits media? Peers do not need a local TURN server installation, you will only need 1 TURN server (which should not be behind a NAT, probably running on some web server). The TURN server is a separate instance.
EDIT
For your private testing and development purposes, you may use https://numb.viagenie.ca/ . I don't know much about commercial turn server hosters, except that some exist. For someone who owns a v-server or root server, installing coTURN may be an option, this Tutorial might be helpful. To check if the server is working, I also found this snippet to be very useful.
END EDIT
Q5. There is no android app that publishes webRTC streams to a ws URL since websocket
messages are used by webrtc only for signalling (that is, telling peers their host candidates, those are the IP adresses and ports learned by the ice gathering process, this includes the TURN and STUN ip and port combinations).

Windows does not answer BLE parameter update request

I have a custom embedded device with a Bluetooth low energy stack. The device is advertising itself until a connection is requested, I pair and connect to it via the Bluetooth menu in Windows 10, I can read/write to my custom GATT services using the following BLE GATT functions from the Win32 API.
For my application I need to receive high frequency data using notifications on a characteristic so I enable it using the same API as stated above and receive the correct data but too slow. The default connection parameters Windows is using is not enough and I want to update them so I can receive notification events at higher frequency, but Windows API does not provide such function. I had the same problem when connection to an Android phone, and I solved it by requesting connection parameters update from the device (the slave in the connection) and the Android phone accepted it and everything worked as expected.
The only problem is when I'm trying to ask for a connection parameter update from the device when connected to a Windows master, I don't receive any response (no accept nor reject), meanwhile I still receive notification events so I know the connection is still active. And the weird thing is that if I hold the device closer to the computer's Bluetooth antenna it does receive a response and update the connection parameters like intended.
Any idea what's going on? Is it a bug in Windows stack?
The fact that holding device closer to antenna helps should be verified. Try it multiple times in a different way.
You mentioned Android, does holding device further from Android also prevent connection parameters update?
If this proves true, I'd say the device is faulty. I would compare the behavior between different devices, better if they are from different manufacturers or at least models.

Creating a Server for phone or sms

This is my newest project which consists of making a Server for phone and sms. I would like to do something like google talk where one would be able to make calls and receive calls or even text through the internet.
I would than be able to connect a land line phone or even just a microphone and call my cellular and talk. Otherwise just sending a sms message through the internet to my cell would be awesome as well.
Any Reference or guides would be much appreciated.
Notes:
Yes I know there are websites that do these things. Not what I am asking.
I got a Windows Server 2008 r2 setup at home.
I think I am a decent programmer, enough to be able to program this if I have some clue what I should be searching for.
Do not tell me it is impossible, as not too long ago I saw usb hardware that allowed to make calls over the internet (I know it's more complicated than that but I want to have this knowledge)
Okay, as others have already suggested, Asterisk is one the most obvious ways to go. Some time ago we created an online solution which allows most of the things that you have described, voip calling, dial plan generation, pbx, connection with landlines, sms sending, payments.
Tools used:
- LAMP (linux, apache, mysql, php)
- Asterisk
- OpenSer (http://en.wikipedia.org/wiki/OpenSER)
- 3rd party for SMS sending
- 3rd party for billing.
For phone you have two options:
not buying hardware and use voip. You can use some voip to land line gateways. There are many ways for achieving that. The most "professional" would be buying did number: http://www.voip-info.org/wiki/view/DID+Service+Providers. But there are other ways for example using skype api.
second option is connecting server to landline using special hardware - http://www.voip-info.org/wiki/view/FXO
Probably the funniest part would be writing webgui since writing PBX part could be little tricky. You should consider using Asterisk (free, Open Source) - Linux or 3CX (non-free) - Windows.
Regarding sms:
You can use sms gateway i.e.: http://www.clickatell.com/
You can buy gsm modem to your server
For the SMS part there is the SMSLib (http://smslib.org/), where you can use an attached phone to send and receive SMS.
You could provide a webinterface to write and read the SMS then of course, that would be the easier part.
For the calling I don't know, but it should be possible too. I know there are GSM chips for e.g. arduino but I guess it is very hard to reroute them to the application on the server. It could be possible with a short delay though.
Another option is to look into a VOIP library, e.g. Asterisk (http://www.asterisk.org).

connecting computer to a mobile phone - reading sms and use it?

I've absolutely no idea if this is possible and how it would work.
is it possible to give users a phonenumber where they should send an sms to.
e.g. the sms contains
name
some code
i want to track how many sms are sent to this number.
i want to read the sms text and use both nodes
they weird way i imagine this: i buy a prepaid simcard from any phone provider, i plug the simcard into any device (sim-reader :) ) connected to my computer. my computer is ONLINE. so my computer is kind of transformed to a mobile phone. some software is able to retrieve those sms and i can use the data in it.
is that even possible, if yes HOW?
You can use e.g. gammu to send and receive SMS from a cellphone connected to your computer - essentially creating a SMS gateway. I've succesfully used it in the past in this setup (newer phones have serial port emulation through USB, for older ones you need a model-specific serial-to-phone cable):
my program <-> database/textfiles <-> gammu <-> serial port <-> cellphone
The operation was as follows:
gammu ran in the command line/daemon mode, with a watchdog script restarting it (and the cellphone) if the cellphone became unresponsive (this was a really old phone; a watchdog is probably not necessary with anything > 2006)
gammu polled the cellphone for new messages, those were store into a "received" table in the database.
gammu also polled an "outgoing" table in the database for messages I wanted to send, and sent them through the cellphone.
my program was a web frontend for reading the incoming messages or inserting the outgoing ones.
(Gammu has an API to interface with the cellphone directly, without the database; I decided to keep the backend and frontend parts separate, and since the frontend was using the database for other things anyway, it was easiest to go that way; also, I was using an old phone for this, and needed the frontend to run even if the cellphone wasn't responding)
There are several possibilities listed here. But it depends on the phone you are using. Symbian, iOS, Android, Windows Mobile. But basically it is possible using a GSM Modem.

Resources