Forcing communication of an IOT client to a server - node.js

I have an IoT client that is connected to a server via wifi. I want to force all communication of the IoT client to go to the server first. Right now, I am connecting the 2 via socket io but when i run a http request code on the IoT to google, the device does not communicate through the server but straight to google. How do I prevent this. Do i change the wifi connection between the IoT and server to something else?

In Raspbian for general browsing, you can add following command in /etc/environment.
export http_proxy="http://username:password#host:port/"
For apt-get, you can add commands in /etc/apt/apt.conf.d/10proxy.
Acquire::http::Proxy "http://username:password#host:port";
But if there are other communications except http protocol, you need to config the proxy in your app and implement all the service in the proxy.

Related

Webserver hosted on an ESP32 using p2p

I was thinking about how could i host a webserver from an esp32 that is accessible from outside of it's network.
The first thing i did was i port forwarded my esp32 private ip on my router and configured a dns server to my router's public ip ( no-ip , ddns.net )
That was good. I could reach my webserver hosted on my esp32 but if i want to create a product, this is not a good solution because i can not force the users to configure their routers and configure a dns provider for themselfs.
So the next thing in my mind was, i needed a server. I could have used mqtt or any other service to exchange data with the client but i wanted to do it myself.
So i set up a node js server on my PC. The esp32 can connect to this server because it is on a public network and port forwarded already. The esp32 can use websockets as a client or http requests to send data to the server. This is ok, but the web app that the client sees is not hosted on the esp32, but on the server. This makes it hard to update the web app files ( html and js files ) both on the server and on the esp32. Because what if the client want to reach the web app from within it's local network without internet. The esp32 should have the exact same web app hosted like on the server.
I was using socket io to communicate the esp32's data with the web app client. The node js server served the static html and js files to the client, and forwarded the esp's messages coming on websocket throught socket io to the client.
Okay so the problem in here as i said that i had to update the files on both the node server and on the esp32. This is not a good way.
So i need some kind of a p2p connection. At this point i read about hole punching and webrtc and things like that.
What i tried to establish p2p connection:
Esp32 connects to node js server every 100ms, sending it's router's
public IP, it's own private Ip and things like that.
Server stores the esp data.
Client connects to server, fetching esp's router public ip, trying to
connect to it.
Server sends a message back to esp32 as a response with the client's
ip address.
Esp get's the message, trying to send data to client's IP address.
Client trying the same...
aaand nothing happens. The router's don't want to open their ports.
I tried this with raw udp, http requests and websockets. These were unsecured connections.
I found literally no low level explanation about web rtc's data channel. If i would want to write this "open source" protocoll using the C language there is just the explanation about this webrtc with high level languages like *built in options on browsers in JS and things like that.
ESP32 microcontroller LINK.
The question is, how could i estabilish a p2p connection between a microcontroller ( like esp32 using esp idf or arduino framework ) and a browser client? Is it even possible?
Have you considered mDNS/DNS-SD? You can advertise your service from esp32 and discover it with your client via arbitrary network

beginner webrtc/nodejs issue connecting remote clients

I'm trying to develop a web application in nodejs. I'm using an npm package called "simple-peer" but i don't think this issue is related to that. I was able to use this package and get it working when integrating it with a laravel application using an apache server as the back end. I could access the host machine through it's IP:PORT on the network and connect a separate client to the host successfully with a peer-to-peer connection. However, I'm now trying to develop this specifically in node without an apache back end. I have my express server up and running on port 3000, I can access the index page from a remote client on the same network through IP:3000. But when I try to connect through webrtc, I get a "Connection failed" error. If I connect two different browser instances on the same localhost device, the connection succeeds.
For reference: i'm just using the copy/pasted code from this usage demo. I have the "simplepeer.min.js" included and referenced in the correct directory.
So my main questions are: is there a setting or some webRTC protocol that could be blocking the remote clients from connecting? What would I need to change to meet this requirement? Why would it work in a laravel/webpack app with apache and not with express?
If your remote clients can not get icecandidates, you need TURN server.
When WebRTC Peer behind NAT, firewall or using Cellular Network(like smartphone), P2P Connection will fail.
At that time, for fallback, TURN server will work as a relay server.
I recommend coTURN.
Here is an simple implementation of simple-peer with nodejs backend for multi-user video/audio chat. You can find the client code in /public/js/main.js. Github Project and the Demo.
And just like #JinhoJang said. You do need a turn server to pass the information. Here is a list of public stun/turn servers.

Send request from Webserver to Local server

I have a nodejs webserver running on a vserver (rented by me) and a local Raspberry Pi node server.
I dont want to open any ports for beeing accesable from the webserver.
My problem is that I want to create a web application you can interact with and the rpi should do things when any button is pressed on the webserver.
I thought it would be smart to create a json file on the webserver and my local server would listen on the json file.
Is there any better Idea?
Thx for your advice!
your problem can be solved using reverse proxy softwares that establishes secure tunnels from a public endpoint such as internet to a locally running network service.
ngrok is one of the best that I prefer to use.
To establish a communication between the raspberry and the webserver you need to open a port on the webserver.
However, you can restrict it to allow connections from the raspberry pi IP address only. Or do the connection via ssh and let the raspberry pi authenticate using its public key.

Connect LAMP server on Azure to a websocket server

I have a LAMP server which communicates with a web socket server, both on different Linux machines. Using them in a local network works. Now, I want to put only the LAMP server on Azure (Linux Virtual Machine) and continue to communicate with the web socket server. How can I solve this issue? I was thinking to use SSH tunnel. Is it the right way to proceed with Azure? How can I do that?
Thanks.
So I understand your architecture...
Does your LAMP "server" talk to your WebSocket server using ws://? If so, you don't need some sort of tunnel. That's one of the benefits of the WS protocol; its web-friendly.
or
Does your LAMP "server" talk to your WebSocket server via TCP for some reason? If so... why not use the WS protocol? Or if you really need TCP, then you would need some sort of tunnel, either SSH or something like Kaazing KWIC on Azure.
Full disclosure. I work for Kaazing.

Geospatial Analytics - MQTT connection issue on BlueMix

I completed the following tutorial:
http://www.ibm.com/developerworks/library/mo-monitordevices-app/index.html
Next, I launch the app on BlueMix and click on the geo-starter Visualizer link. It launches the screen but I cannot see any of the connected devices on my screen. See screenshot of debug mode in browser. It seems like I am unable to connect to the MQTT server from my environment. This looks like a possible issue with the firewall on my network.
Couple questions:
How do I debug this further to determine if this is a firewall issue or something else?
The MQTT server seems to communicate via port 1883 as per instructions to the MQTT server url, see below:
mqtt1.m2m4connectedlife.com:1883
If my network is potentially blocking this port, is there an alternative port I can use such as port 80 to communicate with the MQTT server?
Would greatly appreciate any feedback on this!
Thanks!
mqtt-error
The corporate firewall was in fact the issue here. They won't allow traffic out on alternative ports without authorization which takes time. This port is reserved for MQTT traffic so hopefully it can be opened up once the traffic is better understood.

Resources