Author Topic: Raspberry Pi Controlling LED over internet  (Read 3654 times)

0 Members and 1 Guest are viewing this topic.

Offline ParthTopic starter

  • Contributor
  • Posts: 18
  • Country: in
Raspberry Pi Controlling LED over internet
« on: November 21, 2017, 09:13:18 am »
Hi All

Recently 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   
« Last Edit: November 21, 2017, 09:15:01 am by Parth »
 

Offline Arjen_Arg

  • Contributor
  • Posts: 13
  • Country: ar
Re: Raspberry Pi Controlling LED over internet
« Reply #1 on: November 21, 2017, 02:17:24 pm »
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.
 
The following users thanked this post: Parth

Offline BroMarduk

  • Supporter
  • ****
  • Posts: 78
  • Country: us
Re: Raspberry Pi Controlling LED over internet
« Reply #2 on: November 21, 2017, 02:20:50 pm »
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.
 
The following users thanked this post: Parth

Offline ParthTopic starter

  • Contributor
  • Posts: 18
  • Country: in
Re: Raspberry Pi Controlling LED over internet
« Reply #3 on: November 21, 2017, 03:13:11 pm »
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 ? 
 

Offline mbless

  • Regular Contributor
  • *
  • Posts: 227
  • Country: 00
Re: Raspberry Pi Controlling LED over internet
« Reply #4 on: November 21, 2017, 06:56:36 pm »
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.
 
The following users thanked this post: Parth

Online rstofer

  • Super Contributor
  • ***
  • Posts: 9886
  • Country: us
Re: Raspberry Pi Controlling LED over internet
« Reply #5 on: November 21, 2017, 07:07:20 pm »
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.

« Last Edit: November 21, 2017, 11:58:53 pm by rstofer »
 
The following users thanked this post: Parth

Offline ParthTopic starter

  • Contributor
  • Posts: 18
  • Country: in
Re: Raspberry Pi Controlling LED over internet
« Reply #6 on: November 22, 2017, 03:45:51 am »
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 sure

Can you tell in a little bit which program which program I need.  which program I have to write ?   
 

Offline AG6QR

  • Frequent Contributor
  • **
  • Posts: 857
  • Country: us
    • AG6QR Blog
Re: Raspberry Pi Controlling LED over internet
« Reply #7 on: November 22, 2017, 04:19:01 am »
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.
 
The following users thanked this post: Parth

Offline ParthTopic starter

  • Contributor
  • Posts: 18
  • Country: in
Re: Raspberry Pi Controlling LED over internet
« Reply #8 on: November 22, 2017, 05:50:39 am »
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).

I 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.   

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.

I 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 internet

I will also read other ways that you tell me. If I do not understand  somewhere then I will let you know
« Last Edit: November 22, 2017, 05:52:39 am by Parth »
 

Offline technix

  • Super Contributor
  • ***
  • Posts: 3507
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: Raspberry Pi Controlling LED over internet
« Reply #9 on: November 25, 2017, 09:33:57 am »
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.
 

Offline cravenhaven

  • Contributor
  • Posts: 40
  • Country: au
Re: Raspberry Pi Controlling LED over internet
« Reply #10 on: November 26, 2017, 04:29:07 am »
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-setup
Similarly you can use teamviewer to do the same thing.

Good luck.
 
The following users thanked this post: Parth

Offline TomS_

  • Frequent Contributor
  • **
  • Posts: 834
  • Country: gb
Re: Raspberry Pi Controlling LED over internet
« Reply #11 on: November 27, 2017, 01:51:41 pm »
I am new, so I thought I try to control a led.

One step at a time and start with the basics like turning the LED on and off while you are sitting in front of it. Focus on how to achieve this 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.
« Last Edit: November 27, 2017, 01:53:46 pm by TomS_ »
 
The following users thanked this post: Parth

Offline frozenfrogz

  • Frequent Contributor
  • **
  • Posts: 936
  • Country: de
  • Having fun with Arduino and Raspberry Pi
Re: Raspberry Pi Controlling LED over internet
« Reply #12 on: November 27, 2017, 02:31:46 pm »
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: [Select]
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM) # GPIO numbers instead of board numbers
 
LED_1_GPIO = 4 # LED connected to GPIO 4
GPIO.setup(LED_1_GPIO, GPIO.OUT) # set GPIO as output
GPIO.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 re Raspberry Pi SSH and security as a starting point.
See also: https://www.raspberrypi.org/documentation/configuration/security.md
« Last Edit: November 27, 2017, 02:35:50 pm by frozenfrogz »
He’s like a trained ape. Without the training.
 
The following users thanked this post: Parth


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf