How to fix socket connection error in WatchOS 5? - swift

I am trying to implement send messages from the apple watch to an MQTT server using the MQTT Paho client library.
I am able to send messages from the emulator to the server but I am receiving errors when I try to run the app on an actual watch.
I am getting an error saying that it has attempted to connect to the server 3 times followed by "Socket: 5 Err: -1 Ernno: 1 Operation not permitted".

BSD sockets are not supported on watchOS (though I'm not sure why they work in the simulator). In watchOS 6 you'll be able to use Network.framework, but there aren't any MQTT libraries written using that yet. (I've started my own but it isn't usable yet.)

Related

Python & Flask Push Messages

I am developing a sort of IoT type system, where there is control software, a server, and client devices (which are embedded linux devices).
I have a flask server running a REST web service. Control software sends messages for a specific device to the flask web service running on the server. When these messages are received, they are stored in a database.
Client devices poll the sever to determine if there is a new message waiting for the device. This works well but becomes prohibitive as the number of devices grows.
I'd like to find a way to have the messages sent directly from the server to the device as they are received at the server. Is there a simple way to add this functionality to flask? This seems a bit like push notifications.
Is it possible to have each device open a socket like communication to the server and keep it open? Is this a bad idea if I just use TCP sockets for this?

Starscream WatchOS connection

Can I connect to a WebSocket server in 2021 using WatchOS and StarScream on a real device?
I found information that it is impossible to connect on a real device, but the information is old
Unfortunately, I can not check on a real device, but it works on a simulator!
You can connect to a websocket server with StarScream on real devices. The issue you mentioned is fixed.
But be aware, your watch should be connected with your paired iPhone which has active internet connection. Otherwise, your socket connection won't connect.

Is it possible for one device to subscribe to MQTT events or commands from another device on IBM IoTF?

I am building an iOS app to control my Raspberry Pi over MQTT. I want to be able to send control commands from my iPhone to the Pi and have the Pi respond with a status update.
The Pi is running Node-RED and can both send and receive both events and commands to IBM IoT Foundation (verified from a Bluemix Node-RED application).
The iPhone Swift app is using https://cocoapods.org/pods/MQTTClient (Note - does not specifically list IBM IoT as a tested platform).
From the Swift app, I have successfully connected to IBM IoTF and sent events which the Pi receives. I have also successfully subscribed to command topics in the form "iot-2/cmd/streamStarted/fmt/json", but never receive a message. If I try to publish a command in the form "iot-2/cmd/startStream/fmt/json" or subscribe to events in the form "iot-2/evt/streamStarted/fmt/json" or "iot-2/type/myPi/id/<myPiID>/evt/streamStarted/fmt/json", the connection immediately closes.
The bottom line is that I need to get a status message from the Pi to the iPhone in some way. I don't really care if it is an event, a command or something else. I have been successful doing this with test.mosquitto.org, events but not IoT Foundation.
Only applications can send commands to a device. You can't send a command from one device to another. Is the iphone swift app connecting to IoT Foundation as an application or trying to connect as a device?

Swift socket invalid HTTP upgrade

Good day,
I've established very simple Python server (Twisted framework) on localhost:80. It works ok with telnet - i can send and recieve simple messages. But i need to connect Swift iOS app client to this server. App running on simulator.
I'm using Socket_IO_Client_Swift framework. At this moment, i've just created socket object with "localhost:80" parameter and call connect() method on start of application.
Server can see the signal from client, but client disconnect immidietly after connection with this message:
Got event: disconnect, with items: Optional((
"Invalid HTTP upgrade"
What can i do to fix this, and what is HTTP upgrade?
Thanks

Sockets won't connect after Windows 8.1 update

I am currently working on a project that involves the use of sockets. The program was working just fine, but after a windows 8.1 update on my computer, either the client socket is sending out a signal to be accepted or the server socket isn't receiving the signal so it can accept. I tried to use it on my emulator and it worked just fine. In addition, I have updated my GPU drivers to see if this could be fixed, but they still won't connect. The program doesn't crash and give me an error; it just sits there and waits. Does anyone have any ideas? Perhaps the update is blocking my peer to peer connection? Any help is much appreciated. Thanks.