Raspberry Pi Controlling LED over internet  - Page 1
Forum section: electronics / general

author: Parth
author_rank: Contributor
timestamp: November 21, 2017, 09:13:18 am
content: Hi AllRecently I got my Raspberry Pi 3. I have one LED and resistor. I have connected LED to Raspberry Pi 3. I wanted to control this LED over internet. I have been searching a lot on internet. I don't understand how to do it. Which server and language I need to complete this project?Have you controlled any device with the help of internet ? I am looking sample program. Please share some ideas

author: Arjen_Arg
author_rank: Contributor
timestamp: November 21, 2017, 02:17:24 pm
content: You should start with the most basic tutorial or "getting started on...". The Raspberry Pi is a Linux machine, you can create your application in many different languages and run it there. If you wanted to access it remotely, you don't really need a server. You can create an application that either uses a TCP socket or a webserver to listen for commands. Then you access it from the internet over your home IP.

author: BroMarduk
author_rank: Unknown
timestamp: November 21, 2017, 02:20:50 pm
content: You are going to have to write some code...but give this link a shot:https://www.pubnub.com/blog/2015-06-11-remote-control-raspberry-pi-leds-from-a-web-browser-ui/Basically, you use a GPIO library in python to send the on/off signal to the proper pin from the server running on the Pi.Also, you will need to make sure the Pi's IP address is reachable from the outside if you want to control it from outside your local network.

author: Parth
author_rank: Contributor
timestamp: November 21, 2017, 03:13:11 pm
content: I am getting very confused. I am explaining to you in simple language what I want to do. You are working in a city and your house is in another city. You want that you can control the device in your house when you are sitting in the office. You want to turn on/ off the device at home from your office. I know this is possible. You can do it but question is how will you do it?I am new, so I thought I try to control a led. Now you think that you are in office and you want to control led that is in your house connected with Raspberry. You will open your laptop. You will open web page in web browser. There will be a button inside the web page that will turn on /off LED.I have computer at office and Raspberry board at home. Led connected to Raspberry board . I have complete hardware to make this project. The problem is that only in programming part.I already followed many articles but I am getting very confused. Will you tell me some point What I have to do step by step ?

author: mbless
author_rank: Regular Contributor
timestamp: November 21, 2017, 06:56:36 pm
content: I use Flask with Python.This guide got me started.I only run mine on the local network, so to get outside access you probably just need to open the port on your router.

author: rstofer
author_rank: Super Contributor
timestamp: November 21, 2017, 07:07:20 pm
content: Your description of the intended operation is absolutely correct. Your Pi needs to run a web server and there needs to be a web page that has linkage down to the GPIOs.Here is one description of the process:http://www.instructables.com/id/Simple-and-intuitive-web-interface-for-your-Raspbe/The main problem that was alluded to above is that many of us use NAT to translate our internal LAN. Our PCs might be on the 192.168.1.xxx network and that simply doesn't route and can't be reached from outside. The modem/router translates these addresses to a routable IP address.You need to know your outside IP address (you can probably get it from your router/modem) and you need to poke a hole through the firewall for a specific port (80? 8080?) to allow an external connection through the router and to a dedicated machine (Pi) on your network. On my router, I can tell it to route the external connection to a specific IP in the 192.168.1.xxx domain.

author: Parth
author_rank: Contributor
timestamp: November 22, 2017, 03:45:51 am
content: I know I have to run the web server on Raspberry. I have to make web page to control device that will store on the web server. Now I will open web browser on another computer and I will search the web page that is stored on raspberry's server. I think so we can do it like this but I am not sureCan you tell in a little bit which program which program I need. which program I have to write ?

author: AG6QR
author_rank: Frequent Contributor
timestamp: November 22, 2017, 04:19:01 am
content: I think one problem in getting help on this task is that there are far too many ways to do it.But however you do it, you can break it in half, solve the two halves separately, and connect them. The two halves are: how to control a light from the Pi, and how to invoke a task on the Pi over the Internet.The easiest way to control a light from the Pi is to wire the LED, with suitable current-limiting resistor, to a GPIO pin and ground on your Pi. Then write a program in your favorite language to turn the GPIO pin on and off. If you want to skip the wiring part, you could perhaps use one of the Pi's built in status LEDs (the ones that are by default set up to indicate power and disk activity).There are many ways to invoke a task on the Pi over the Internet. One way is to use ssh to connect a terminal session from a distant computer to your Pi. Then you can type any command at the command line. Another way is to write your own software to listen on a particular port for commands, and then connect to that port using either custom software or something like telnet or PuTTy. Another way is to set up a web server on your Pi, and write some php code or similar to invoke a command when a web page is visited or a button on a page is clicked. There are more ways.The job of invoking a task on the Pi over the Internet can further be divided in half: Invoking a task on your Pi from another computer on your local area network, and setting up your router so that computers outside of your home network can get in and connect to your Pi to invoke the task.Any time you enable someone to connect to your Pi from the broader Internet, you at least have some potential for malicious actors to try and get in. Don't open more ports than you need to. Don't expose your Pi to ssh without first 1) disabling root logon, 2) changing the default password for the "pi" account, if not eliminating that account entirely in favor of some account with a nonstandard name. People WILL look for an open port 22 and try to brute-force guess the password to your root account.You'll have to open a port on your router and forward it to your Pi. If your ISP doesn't provide you with a static IP, you'll have to use some sort of dynamic DNS system to publish your IP address.

author: Parth
author_rank: Contributor
timestamp: November 22, 2017, 05:50:39 am
content: Quote from: AG6QR on November 22, 2017, 04:19:01 amI really appreciate your answer. I was hoping for such a type of response. I have connected led with resistor to raspberry PI and wrote python program to blink led. I completed that task successfully. My LED was blinking.Quote from: AG6QR on November 22, 2017, 04:19:01 amI want to implement on this way. I want to run web server on PI. Whenever I access Raspberry from from another computer. LED should be turn on/off over internetI will also read other ways that you tell me. If I do not understand somewhere then I will let you know

author: technix
author_rank: Super Contributor
timestamp: November 25, 2017, 09:33:57 am
content: If you can get your Web server running with appropriate privileges to access the GPIO sysfs interface, you can create Python files or shell scripts implementing CGI to manipulate the LED.CGI is one of the earliest way to allow Web servers to serve dynamically generated pages, and still remains to be one of the most versatile one since all it uses is the standard input and output streams and the environment variables, all of which are standard in all hosted languages.

author: cravenhaven
author_rank: Contributor
timestamp: November 26, 2017, 04:29:07 am
content: Have a look at Dataplicity.https://www.dataplicity.com/You install the application on your Pi and then access a Pi terminal session remotely via the dataplicity web site. Once you have remotely logged into your Pi from your remote pc (or phone) you can run any command line tool such as a Python script to control your LED.Another way is to use the more advanced Dataplicity wormhole function to access a web page on your Pi. All the information is available on the Dataplicity web site.Other options are installing VNC on your Pi and then accessing remotely:https://www.realvnc.com/en/connect/docs/raspberry-pi.html#raspberry-pi-setupSimilarly you can use teamviewer to do the same thing.Good luck.

author: TomS_
author_rank: Frequent Contributor
timestamp: November 27, 2017, 01:51:41 pm
content: Quote from: Parth on November 21, 2017, 03:13:11 pmOne step at a time andstart with the basicslike turning the LED on and off while you are sitting in front of it. Focus on how to achievethis little bit first, before you add extra layers of complexity like remote control.There are more considerations for the remote control part than simple programming tasks or setting up a server to allow you to control the LED, like how are you going to access your rpi from remote locations?As I said, start with the basics and move on from there.

author: frozenfrogz
author_rank: Frequent Contributor
timestamp: November 27, 2017, 02:31:46 pm
content: Personally I would not recommend running a web server with an exposed site on the Raspberry Pi. A more convenient way would be to write a small Python script and use SSH to log onto the Pi from remote.Very basic script for reference:Code:import RPi.GPIO as GPIOGPIO.setmode(GPIO.BCM) # GPIO numbers instead of board numbersLED_1_GPIO = 4 # LED connected to GPIO 4GPIO.setup(LED_1_GPIO, GPIO.OUT) # set GPIO as outputGPIO.output(LED_1_GPIO, GPIO.LOW) # GPIO control LED »off«GPIO.output(LED_1_GPIO, GPIO.HIGH) # GPIO control LED »on«Edit: Some more input reRaspberry Pi SSH and securityas a starting point.See also:https://www.raspberrypi.org/documentation/configuration/security.md