Wake up the computer remotely with the Arduino Ethernet

Source: Internet
Author: User

Translated from: http://ricardo-dias.com/2010/11/20/arduino-wakes-my-pc/

I've always dreamed of controlling something in my room through the Internet. Watch IPTV on the computer, turn on/off the lights, remote control peer download ... To do this, I need a server – my old desktop can do it. Of course, I didn't mean to hang it all day/week/month ... ^^

I need to find a way to revive it whenever I want to. So I think I can use an Arduino and Ethernet board to send wake on LAN packets (to enable the remote server to boot).

This Udpraw library allows the original packet to be sent, so all I have to do is do the following "Magic Packet" – it consists of 6 0xFF and the 16 target MAC addresses that follow.

byte wolmac[] = {0X00,0X00,0X00,0X36,0X45,0XC1};

All I need now is to copy the MAC address 16 times after 6*0xff. That's what I did:

byte All[102];int i,c1,j=0;for (i = 0; i < 6; i++,j++) {all[j] = 0xFF;} for (i = 0; i < +; i++) {for (c1 = 0; c1 < 6; c1++,j++) all[j] = wolmac[c1];}

After running the code, all of these arrays will get the complete magic packet, ready to send:

Udpraw.sendpacket (All,102,targetip,targetport);

So the test, I figured out a simple program, when a button is pressed, the package is sent. Then, I used an interrupt on pin 2. The Arduino is basically able to keep listening on that pin, from low to high, to perform certain functions.

after I've done that, I plan to use Arduino to listen to the network port, and when it receives a specified sequence of packets, it wakes up the computer. This will be in any corner of the world called to start my server!

This is the full Arduino code:

/** Arduino wakemypc * Ricardo dias * http://ricardo-dias.com/ * * This sketch sends the "Magic Packe T "to wake up * a PC in Local area Network when a push-button * is pressed. */#include <Ethernet.h> #i Nclude <udpraw.h>//ARDUINO configbyte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; Arduino macbyte ip[] = {192, 168, 1, 112}; Arduino ipbyte gw[] = {192, 168, 1, 254}; Gateway IP Addressint localport = 8888; Local port to listen on//the targetbyte targetip[] = {192, 168, 1, 255};int targetport = 5456;byte wolmac[] = {0x00, 0X00,0X00,0X36,0X45,0XC1}; The target PC Mac addressvoid setup () {  ethernet.begin (MAC,IP,GW);  udpraw.begin (LocalPort); //would r Un the SENDPKT () function when a button wired to //PIN 2 is pressed  attachinterrupt (0, SENDPKT, RISING);} void Loop () {  delay (1);} void Sendpkt () { //The ' magic Packet ' consists of 6 times 0xFF followed by times //The HarDware address (MAC) .  byte all[102];  int i,c1,j=0;  for (i = 0; i < 6; i++,j++) {    ALL[J] = 0  xff; }  for (i = 0; i <, i++) {    for (c1 = 0; c1 < 6; c1++,j++)       ALL[J] = wolmac[c1]; }  Udpraw.sendpacket (all,102,targetip,targetport);}

PS: You might be thinking, "Heck, why can't it just send these packets to the computer?" ”

You can explain this: my ISP likes to restart the Router 2 o'clock every night. Then the router restarts and the server is down, and it does not know which Ethernet port the server is attached to. To resolve this issue, these packages need to be sent to the broadcast IP. However, it is only in the local area network.


More communication with us: [email protected]

Welcome to Login Wiznet Official website: http://www.iwiznet.cn

Wake up the computer remotely with the Arduino Ethernet

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.