Discover devices (esp8266/arduino) on same LAN subnet - ionic-framework

I am developing a product which uses ESP8266 (arduino firmware). I am developing an Ionic app as the main controller. The product is working perfectly fine through the server. But a major feature needed is to communicate with the devices through LAN. The devices host a server so I can communicate with them using GET requests through my app using their local IP.
But the problem is discovering these devices. Currently my approach is to send a get request on all IPs on my subnet and parse the response, if any, and store the active IPs in app; then use those stored IPs to communicate for subsequent requests.
The problem is the sending request to all IPs part. It is a slow process and slower with low end phones.
What I want is a way to receive communication from the devices initiated by them, maybe. Something like signalling all IPs (just my devices) at once to send their IPs to my phone.
Can this be done easily? And quickly? And accurately?

One option is to set up the ESP8266 to publish an mDNS service (also known as zeroconf, bonjour, etc..). Luckily, mDNS is built into the ESP8266 Arduino core. There is some basic setup info here: https://tttapa.github.io/ESP8266/Chap08%20-%20mDNS.html, as well as elsewhere on the web.
Then on the ionic side, you can then use a zeroconf/mDNS plugin to automatically discover the ESP8266. I've used this one in the past, with good results: https://ionicframework.com/docs/native/zeroconf/

Related

How to connect from Internet to a a lot of devices behind domestic routers

For an IoT related project I need an internet server to be able to interact with devices (they will be small PCs, probably raspberry pi) that will be behind the home router of each user. One of the requirements of the project is that these devices are self-installable by the user.
Therefore the server will not know the public IP of each home router and there is no possibility of NAT configuration in the router to reach each device within the home network.
In this scenario, what possibilities exist? At the moment I am studying the use of websockets initiated from each device to the server on the Internet (in fact, the devices know the server location); over this websocket should run all the communication (in a bidirectional way) simulating a REST interaction between both sides. Is there any other alternative? What do you think about the use of websockets to solve this need?
Websockets are used for interactive communication between a client and a server. By 'interactive' I understand near real-time. If this is your requirement, then you can use it.
If you only need non-interactive communication (request / response), you can use a classical REST API over HTTP, initiated from the devices. As long as they are connected to the router, the network stack takes care of everything.
You need to know the public IP of a router only when the server has to initiate the connection to a specific PC/workstation. In that case, a NAT rule has to be set up on the router which directs the traffic to the right workstation in the local network.

How to make Server and client sockets work on public ip on mobile?

I am working on an application that uses socket to transfer data from one device to other without the server interference and it is important that no one can get a copy of the data only the sender and the receiver. The server will be only for certificate authority and ip addresses collection and distribution. The main issue was opening a connection between to devices and it was solved by configuring the router to accept outside connection and port for warding and so on .. yet i am building the application for users that wont bother themselves to configure there owb routers .. I am asking for a solution to the problem or a better way to set the communication between the devices.
I search the internet for more details on the subject and i found other solution is to use P2P. There are few P2P platform like jxta or sip2peer. that can reach the client even if the client is behind a fire wall and this solve the problem. instead of using java for android or swift for ios, i will use xamarin (C#) to do that, since xamarin is native cross platform IDE .. thanks to every body in this greet community.

iPhone chat application

I have try to make chat application with socket programing and I am using Chatty source code and its working perfect on same network. But not work for different network.
Is chatty work for different network iPhone?
I have tried chatty for different network in iPhone but no success.
Any idea about chatty for different network for iPhone?
From looking at the source code for Chatty, it seems that it just uses an IP and port number to connect to a different device, and that's the reason why you can't connect when users are in a different network. Being able to connect or not will depend a lot on the network configuration you both of your devices have.
For example: it works if you're in the same wifi, because there's no firewall between the devices, and the IP is reachable (192.168.x.x, for example). If you take one of the phones to a 3G network, it won't be able to reach the other one in the wifi, but the one in the wifi might still be able to reach the one on the 3G, depending on your career and port number, and if the network stack is on in the phone. So, conclusion is: this will be highly unreliable.
Usually, for this kind of communication, apps rely on a third party, so both of your phones connect first to a webserver, that is always available on the internet, and the web server sends the messages to each of the apps. This also solves the problem of one app going off the network (when you take an elevator, for example).

How can an iPhone communicate with a computer?

How do apps like Apple's "Remote" app control mac applications and send data?
is this via php with exec() commands or some other method? and how would I do it in c?
Also, how fast is this rate of transfer (can I use it to send real-time data like streaming video or audio?)
thanks to anyone who cares to enlighten me on this issue :-)
Apps generally communicate using a TCP/IP based protocol and the wireless LAN connection (the iPhone also has Bluetooth). In the case of the Remote app the communication is via with the Digital Audio Control Protocol. iTunes implements DACP so the Remote app can control it. Other common protocols are HTTP and FTP. There are classes in the iPhone SDK to connect to noth HTTP and FTP servers. There is also the Cocoa HTTP Server project which allows the iPhone to act as a HTTP server.
iPhone apps can also use Bonjour/mDNS/zeroconfig (they're different names for the same technology) so that the user doesn't have to be concerned with configuring IP address'.
The data transfer rate of the wireless connection is faster enough to stream video.
many of these remote applications work by installing client software on the computer and establishing a network connection. In the case of Apple's remote software, the client software is built into the networking capabilities of iTunes. You must authenticate using your iTunes sign in and be on local wifi.
The third party app "intelliremote" works very similarly only has it's own client software to install and can work across a WAN with proper port forwarding enabled on your network.
I haven't encountered any realtime streaming options as most of these utilities are designed to pass control messages and meta-info on media files.

Is it possible to connect a socket between two mobile devices (iPhones) over the internet?

Is it possible to connect a socket between two mobile devices (iPhones) over the internet?
I am trying to discover the IP of each device and connect directly. I know it can be done with Bonjour but that only works on local networks. I need a high speed connection between two devices over the internet.
Thanks.
If you had both the IP's and they were both routable, it should be possible. I'm not sure though if the IP's given out by the 3G network are routable. If you are using WIFI, the IP you get is almost certainly not routable. Assuming you have a routable IP though, it should be possible.
The trick is just discovering the IP of the other device. The best way to do that would probably be to have each device register its IP with a web service when your app starts up, then query that service to find the IPs of other devices.
It might get a bit tricky managing "unregistering" IPs when the app is closed or when an IP changes though, but it should be doable.
ETA:
If you have a server that they can both connect to, you should be able to implement a solution using that server (i.e. without the phones actually directly connecting to each other). This would avoid the issue of having routable IPs for the phones.
As for how to bridge the sockets together - your server program would basicly work like an old-school phone switchboard operator. You'd have some kind of registration & discovery protocol built into the server software that would allow a phone to register itself with the server, query a list of the other phones currently connected to the server, indicate which phone it wants to talk to, and accept connections from other phones.
Once it knows who wants to talk to whom, your server software would connect the two together by reading from one phone's socket and writing that data to the other phone's socket.
Only a suggestion, but if you can get each of them to connect to a third site, you'll then know the address of each. Send the address of phone A to phone B (and/or phone B to phone A) and then have them connect as you see fit.
Have you looked through all the 3.0 features? Specifically peer networking (the existence of which is public).
WiFi routers often have a feature called "Port Triggering" which allows internal hosts (in this case an iPhone) to inform the router that they would like to have a connections on particular port forwarded to them. I have no idea if the iPhone supports this protocol.
For IP lookup you may consider using DynamicDNS if the two hosts are known ahead of time OR as stated above a custom web service if they are not (i.e. friends exchanging hostnames vs. strangers discovering each other)
This is an old thread, but I just came across it. You could use a STUN server (or NAT-PMP) to get the public IP address/port combo and then SMS it over to the other phone. So long as you open a listening port on the first device, then your second device can just connect directly using the publi IP address/port you sent to it in the SMS (SMS push registry can automatically wake up your app on the second device to do this)
I have run into this issue with an app I was developing. I was trying to connect to a PC cell card from an iPhone. The problem is that AT&T doesn't enable mobile termination for iPhones so it is physically impossible for two phones on an AT&T network to connect to one another. This is straight from an AT&T antenna engineer.
I was able to get this to work by having the iPhone VPN into a server and then connect to the PC cell card but other than that, it wouldn't work.
I have a very strong feeling (but no evidence) that the iPhone address is going to be non-routable. Of course it actually depends on the operator but AT&T give out 10.x.x.x addresses.
Apple have sample (desktop) code that uses Bonjour to implement portmapping on a WiFi router that supports UnPnP.