1

I'm building a home IoT device and I want to be able to ship this device to anyone having previously set a static IP and all they would have to do is connect to the internet and be good to go. I'll be running a server locally to monitor each robot so I thought I would set a static IP on each RPi and once delivered to the customer they'll simply have to get their RPi on their network and do some port forwarding. Then they would download the app and issue commands to the robot (I'm using their login information to know which RPi to control). The issue is that if the IP does change I would lose comms to that remote device. In other words is there a way to have my local server connect to all the remote devices?

I have very limited experience with networking, I'm hacking my way through and I may be looking at this the wrong way. Any help is greatly appreciated!

2
  • when you look at ie smartphones - servers don't connect to them, servers serve. it's smartphones as clients connecting to servers. i know, it's not obvious at the beginning :) the same goes with viruses and any other service. it works and clients don't have to set up any port forwarding (and in case of ISP giving only local IP, your clients would have to ask ISP for port forwarding, problematic).
    – rsm
    Jan 18, 2017 at 2:12
  • To add the the comment from @rsm: In addition its more secure, because the device does not have any port opened up to the Internet, and therefore no one can open a connection to the device and exploit vulnerabilities. Jan 18, 2017 at 10:01

3 Answers 3

1

You need to implement a schema where your RPi are a clients to your server.
What you really need - it is either a static IP at your home/business or any cheap VPS or DDNS(dynamic DNS service). This way when you sending your RPi to your clients, set them all to setup IP automatically over DHCP and add to start up a command that connect to your server over SSH (preferably using public key authentication) with turned reverse SSH setting. This way you may connect to any of your RPis on reversed port on your own server. Regardless where your RPi are located you will always be able to access them (of course if they not behind professional firewalls that restrict outgoing connections from LAN without authentication.)

6
  • Much less work (for your customers) if the device configures itself using DHCP and connects to the Internet server, than if the customer has to manually set up port forwarding!
    – CBHacking
    Jan 18, 2017 at 2:33
  • @CBHacking That what I actually meant - DHCP on RPi(devices that supposed to be sent to customer's premises). If OP will set up static IP on his server or will use DDNS then any remote devices would be able to find its home when they were born instead of asking customers to do complicated networking
    – Alex
    Jan 18, 2017 at 2:48
  • Yes, sorry, I meant that as a comment in agreement with you, pointing out that it's not only a better design technically, it's also easier on the OP's users.
    – CBHacking
    Jan 18, 2017 at 5:05
  • @CBHacking Ohh, then I'm sorry too that I didn't get it
    – Alex
    Jan 18, 2017 at 5:18
  • Thanks guys for the feedback, I'll have to do some research and I'll definitely update this post. I'm was told to look into Toredo which is what I'm doing as of now but DHCP on the RPis is next on the list.
    – Melomaniac
    Jan 20, 2017 at 3:57
0

A home network's external IPv4 is under the control of their ISP and can change at any time if it's dynamic, which most residential Internet connections are.

There are several providers of "Dynamic DNS" providers (such as NoIP) that will let you make an account, pick a DNS domain name from a list, and then allow a "Dynamic Update Client" to connect to it and update the DNS record. Your IoT device would have to run this client.

These providers usually have a free tier offering one or two names for free, requiring you to pay if you want more names. Honestly this is not terribly scalable for more than a few devices.

If this is a large deployment of devices, then the right thing to do if you want your devices "plug and play" really is design your devices so they initiate the connection to a central server instead of relying on the server connecting to them, and move your server to a non-residental hosting service or VPS cloud provider such as Amazon, Azure, etc.

1
  • Thanks @LawrenceC for the advice, I'm getting a few different opinions. I'll let you know if I end up using your solution (which involves third party software/services) but I'd rather avoid that if possible
    – Melomaniac
    Jan 20, 2017 at 4:00
0

Here is an update in case anyone is having the same issue. As recommended RPis are configured as clients. I ended up using node package ip to update each robot's ip in my database. Each client then pulls the ip from the DB to connect.

Here is a snippet of my code. The server is fired on boot.

var ip = require('ip');
var mongo = require('mongodb')
var MongoClient = mongo.MongoClient

var url = 'your_url'
var name = "example"
function updateIP() { // update ip if need be
  var my_ip = ip.address()
  console.log(my_ip)
  MongoClient.connect(url, function(err, db){
    console.log(err)
    var robots = db.collection('robots')
    robots.findAndModify(
       {name: name},
       [['name', 1]],
       {$set: {ip: my_ip}},
       {update: true})
  })
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .