3

I'm working on quite a big project and I need few advices. Basically, Arduino will be receiving data (Strings) and will work with it. No problems with that, but I don't know what to do with receiving and sending data. Customers (all over the country, so the program will not run on LAN) will send the data, but the question is, via what? Application, that will make a TCP connection to Arduino, send UDP packet or maybe a website? Customers need to have access to data (it needs to be refreshed when arduino deletes it too). What would be the most efficient, easy to use and reliable system?

Next thing I want to know is how to make a connection. Open a port on router and connect arduino to that router? I currently have a python script that actually sends an UDP packet to local IP and it works great, but it is limited to LAN. Will it work if I just change the IP (to external) and send it to the port?

And the last thing (for now). I know how to programm in python and java. Which one is better for connections and GUIs?

Thank you for your help, and if you need any more info about the project, I will be happy to edit this post.

  • I modified title to match your question, hopefully that will interest more readers. – dlu Nov 21 '15 at 18:07
  • I am quite surprised people don't try google chart API if they really want to plot graph of sensor data. Setting up any arduino project over internet open to people just requires static ip and forwarded port, for Arduino projects I do not proffer default 80 port. I run apache on raspberry pi that manages everything. – Ciasto piekarz Jan 26 '17 at 18:19
3

What would be the most efficient, easy to use and reliable system?

What seems to me is that you need what is called Unified Application Routing. There are various technologies to do that but what I suggest is WAMP (Web Applicaton messaging protocol, do not get confused with wamp server stack) but you can check this comparison table and select the one that most helps you. Based on that what I suggest is crossbar.io. Is open source with a lot of examples, runs on small devices (raspberry pi for example) and is intended for the use you propose, connect devices and let users/apps to get/give information from them. You can publish/subcribe to topics and all devices or apps connected with that topic can read it. Imagine something like an arduino is reading temperatures from a room and publish that data to topic "Temp1". All devices(other arduino, servers, esp8266) or apps(websites, programs, what ever you clients you imagine) that also are connected at that moment to topic "Temp1" will get that update and act like you want. Wamp also provides a nice feature that is called RPC (remote procedure call). Imagine that you want some real nasty thing in your arduino but it lacks memory or is too slow for that. You can create a program that is, lets say in a raspberry, just waiting for that calculation and returns the result to arduino.

Take a look at this video as an example of what you can do with this ttype of techonologies. A lot of demos also in crossbar.io page. The beauty is that you can program in almost any language you are familiar with. They rely on websockets for the majority of things but crossbar is not restricted to it only, you can even use raw sockets.

As for the second part.

If you create your on server (crossbar lets say) inside the lan you have to forward the port he is listening in your router so other outside your network can access it( and possibly will need to get some kind of Dynamic DNS service if your internet provider do not have statics IPs). Or you can host your server outside your network (crossbar has a tutorial for Amazon EC2 and for Microsoft Azure I think). You only need to port forward server ports. Hwo do you connect arduino? Use ethernet shields, esp8266, choose a yun or make a combo like arduino with usb + raspberry. That way you can also use your raspberry as a crossbar server.

Here is an example of my home made crossbar.io server using 2 python programs , 1 rboard and a raspberry pi has a host to manage my home heating system and the webpage is being accessed from internet, not local lan.

Home Heating manager

  • wow, thank you! I have standard arduino uno with ethernet shield which will handle receiving and sending data. Data will be simple: string which will contain current time (minutes and hours) and date. Time will be handled via RTC (I think this is the best and most reliable solution). I'll take a look at link that you provided and do something out of it. I'm also not sure what would be the best for customers that are not familiar with computers. How to make app accessible to more devices (lets say android). Should I upload it to google play, so they can download it from there? – Rok Dolinar Nov 21 '15 at 15:45
2

If I'm understanding you correctly, you have your application running on a LAN and now want to figure out how to make it accessible over the Internet (WAN). If you're there the next step is relatively straight forward. All you need is an IP address that is visible on the Internet.

You don't say what your connection to the Internet is, so let's look at both of the likely (IPv4) possibilities:

  • You have a block of publicly visible addresses (something other than an IP address starting with 10, 172.16, or 192.168 that are allocated by RFC 1918), or

  • You are behind a single IP address using NAT (network address translation) to provide the internal machines with access to the Internet. The internal machines (and devices) will all have an RFC 1918 address and will not be accessible from the Internet – except by traffic responding to requests made by those machines which are routed to them using NAT. For many users this is the more likely case.

In the first case it is simply a matter of connecting the Arduino to a network segment that is connected to the Internet and assigning an IP address (or configuring DHCP). Also, make sure that the UDP port you are using is not assigned to another service.

In the second case you will also need to connect the Arduino to a network segment with access to the Internet, but because of NAT users outside will not be able to get to the Arduino (yet). To solve that problem you will need to map a port and your external address (the address of your router) to a port and the internal address of your Arduino. For example:

  • Assume your service runs on port 3142 and your IP address on the Internet is 8.9.10.11 and the Arduino is at 192.168.0.42 on your internal network.

  • Then you would configure the port forwarding settings on your router to direct UDP traffic bound for port 3142 to the internal IP address of 192.168.0.42. Some routers will only allow you to forward to the same port, others will also allow you to use a different internal port as well.

  • You may also need to open up a "hole" in your firewall to allow traffic to the port where your service runs. The truly cautious will connect the Arduino to a network segment in the DMZ and there will be another firewall protecting your internal computers and devices.

Once you have this set up anybody on the outside will be able to use the service on the Arduino – if they know the IP address and the port number. Typically you would run the service at a well known host name and use DNS to translate the host name to an IP address. From your question I can't tell how you want to advertise the service, that would be another good question…

  • Thank you for long reply! I understand the basics (I'm computer science student actually), but I don't have real time practice to do that stuff. I know how to connect it to internet (port forwarding, IPs, NAT..), but I'm not sure if it is safe to work with UDP packets (or if I should make TCP connetion). And if I make TCP connection, how should I do it etc. The point is that every person, who will buy the product, will have it mounted at their place and I don't know what to do with the App - ie. if he needs app on another phone, how will he connect to the right device? – Rok Dolinar Nov 21 '15 at 17:45
  • It might be easier to discuss something like this in specifics (if you feel comfortable talking about what the service is and who you expect to be using it). But in generalities UDP is an unreliable service (you are responsible to making sure that the packet gets there and retrying or other wise handling the error if it does not) and TCP is a reliable service – your packet will be delivered correctly or you will get notified that it fails. There are some excellent examples of TCP based services on the Arduino out there. I'd start by looking at them (if you need TCP). – dlu Nov 21 '15 at 17:51
  • Yeah no problem, my project is basically bell system for churches. Basically, the guy who has to do stuff manually (get to the church, type it in...), will be able to do it via android app from his home. So, app will send it to arduino that will store the time into buffer and then loop over that buffer to check if current time is equal to the time in buffer. It is already working, but only for LAN. – Rok Dolinar Nov 21 '15 at 17:57
  • I'd be inclined to do this via TCP, but since you already have it working on UDP I wouldn't change it. The important thing to keep in mind is that you will need to handle failures (the Arduino will have to acknowledge settings because otherwise you won't be sure they were received). Since you have it working on the LAN, all you need to do is the port mapping and then you can start using the external IP (or hostname) of the church – assuming that they have a web site in the building and your device will be added to their network. – dlu Nov 21 '15 at 18:02
  • Yes, I took care of that, Arduino sends back a message, that he successfully received the data, but I'll probably remake the whole thing, so it'll work via TCP connection. Hmm, they don't have a website. I'm making this project with my ISP, he will took care of internet connection (router, switch, static IP) and I have to take care of everything else. – Rok Dolinar Nov 21 '15 at 18:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.