Web + реле

jks123
Offline
Зарегистрирован: 21.05.2012

Приветствую всех. Нужна помощь (не за спасибо конечно) в реализации данного проекта. Есть Nano328 и шилд ENC28J60 (HR911105A) все подключил по схеме как http://ergoz.ru/electronics/arduino/rabota-arduino-nano-s-setevyim-kontrollerom-enc28j60.html залил скетч и вебсерв работает, но не могу сделать чтоб в браузере били кнопки(включалки с подписями и изображением "ВКЛ""ВЫКЛ") и соответственно управлять выходами ардуины нано. Вот собственно помощь нужна!

jks123
Offline
Зарегистрирован: 21.05.2012

jks123 пишет:

Приветствую всех. Нужна помощь (не за спасибо конечно) в реализации данного проекта. Есть Nano328 и шилд ENC28J60 (HR911105A) все подключил по схеме как http://ergoz.ru/electronics/arduino/rabota-arduino-nano-s-setevyim-kontrollerom-enc28j60.html залил скетч и вебсерв работает, но не могу сделать чтоб в браузере били кнопки(включалки с подписями и изображением "ВКЛ""ВЫКЛ") и соответственно управлять выходами ардуины нано. Вот собственно помощь нужна!

 

вот код на один диод и кнопку но есть ошибка при кампиляции

int outputPin = 6; // LED1 to pin 6

int anotherOutputPin = 7; // LED2 to pin 7

static uint8_t mac[6] = {

0x54, 0x55, 0x58, 0x10, 0x00, 0x24}; // this just needs to be unique for your network,

static uint8_t ip[4] = {

192, 168, 0, 150}; // IP address for the webserver

static uint16_t port = 80; // Use port 80 - the standard for HTTP

ETHER_28J60 e;

void setup()

{

e.setup(mac, ip, port);

pinMode(outputPin, OUTPUT);

pinMode(anotherOutputPin, OUTPUT);

}

void loop()

{

char* params;

if (params = e.serviceRequest())

{

e.print("<h1><a href='/?led1=off&led2=off'>Arduino Web Remote</a></h1>");

if (strcmp(params, "?led1=on&led2=off") == 0)

{

digitalWrite(outputPin, HIGH);

digitalWrite(anotherOutputPin, LOW);

e.print("<a href='?led1=off&led2=off'><button style='border: 1px solid #ff0000;
border-left: 10px solid #ff0000' type='button'>LED1 IS ON</button></a><a href='?led1=on&led2=on'>
<br/><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>
LED2 IS OFF</button></a>");

}

else if (strcmp(params, "?led1=off&led2=on") == 0)

{

digitalWrite(outputPin, LOW);

digitalWrite(anotherOutputPin, HIGH);

e.print("<a href='?led1=on&led2=on'><button style='border: 1px solid #000;
border-left: 10px solid #000' type='button'>LED1 IS OFF</button></a><a href='?led1=off&led2=off'>
<br/><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>
LED2 IS ON</button></a>");

}

else if (strcmp(params, "?led1=off&led2=off") == 0)

{

digitalWrite(outputPin, LOW);

digitalWrite(anotherOutputPin, LOW);

e.print("<a href='?led1=on&led2=off'><button style='border: 1px solid #000;
border-left: 10px solid #000' type='button'>LED1 IS OFF</button></a><a href='?led1=off&led2=on'>
<br/><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>
LED2 IS OFF</button></a>");

}

else if (strcmp(params, "?led1=on&led2=on") == 0)

{

digitalWrite(outputPin, HIGH);

digitalWrite(anotherOutputPin, HIGH);

e.print("<a href='?led1=off&led2=on'><button style='border: 1px solid #ff0000;
border-left: 10px solid #ff0000' type='button'>LED1 IS ON</button></a><a href='?led1=on&led2=off'>
<br/><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>
LED2 IS ON</button></a>");

}

e.respond();

}

}

xseregax
Offline
Зарегистрирован: 27.03.2014

Если я не ошибаюсь в этом скетче нужно нажать на текст "Arduino Web Remote" и появятся 2 кнопки:

LED1 IS ON;

LED2 IS ON

jks123
Offline
Зарегистрирован: 21.05.2012

должны былы появится, но увы. вот рабочий может кому пригодится

001#include "etherShield.h"
002#include "ETHER_28J60.h"
003 
004 int outputPin3 = 3;
005 int outputPin5 = 5;
006 int outputPin6 = 6;
007 int outputPin7 = 7;
008 int outputPin8 = 8;
009 int outputPin9 = 9;
010 
011  
012 static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24}; // this just needs to be unique for your network,
013 
014 static uint8_t ip[4] = {10, 0, 0, 100}; // IP address for the webserver
015 
016 static uint16_t port = 80; // Use port 80 - the standard for HTTP
017 
018 ETHER_28J60 e;
019 
020 void setup()
021 {
022   e.setup(mac, ip, port);
023   pinMode(outputPin3, OUTPUT);
024   pinMode(outputPin5, OUTPUT);
025   pinMode(outputPin6, OUTPUT);
026   pinMode(outputPin7, OUTPUT);
027   pinMode(outputPin8, OUTPUT);
028   pinMode(outputPin9, OUTPUT);
029    
030 }
031 
032 void loop()
033 {
034   char* params;
035   if (params = e.serviceRequest())
036   {
037     e.print("<H1>JKS home</H1>");
038     if (strcmp(params, "?led1=on") == 0)
039     {
040       if (!digitalRead(outputPin3))
041       {
042         digitalWrite(outputPin3, HIGH);
043       }
044     }
045     else if (strcmp(params, "?led2=on") == 0)
046     {
047       if (!digitalRead(outputPin5))
048       {
049         digitalWrite(outputPin5, HIGH);
050       }
051     }
052     else if (strcmp(params, "?led3=on") == 0)
053     {
054       if (!digitalRead(outputPin6))
055       {
056         digitalWrite(outputPin6, HIGH);
057       }
058     }
059     else if (strcmp(params, "?led4=on") == 0)
060     {
061       if (!digitalRead(outputPin7))
062       {
063         digitalWrite(outputPin7, HIGH);
064       }
065     }
066     else if (strcmp(params, "?led5=on") == 0)
067     {
068       if (!digitalRead(outputPin8))
069       {
070         digitalWrite(outputPin8, HIGH);
071       }
072     }
073     else if (strcmp(params, "?led6=on") == 0)
074     {
075       if (!digitalRead(outputPin9))
076       {
077         digitalWrite(outputPin9, HIGH);
078       }
079     }
080     else if (strcmp(params, "?led1=off") == 0)// Modified -- 2011 12 15 # Ben Schueler
081     {
082       if (digitalRead(outputPin3))
083       {
084         digitalWrite(outputPin3, LOW);
085       }
086     }
087     else if (strcmp(params, "?led2=off") == 0)// Modified -- 2011 12 15 # Ben Schueler
088     {
089       if (digitalRead(outputPin5))
090       {
091         digitalWrite(outputPin5, LOW);
092       }
093     }
094     else if (strcmp(params, "?led3=off") == 0)// Modified -- 2011 12 15 # Ben Schueler
095     {
096       if (digitalRead(outputPin6))
097       {
098         digitalWrite(outputPin6, LOW);
099       }
100     }
101     else if (strcmp(params, "?led4=off") == 0)// Modified -- 2011 12 15 # Ben Schueler
102     {
103       if (digitalRead(outputPin7))
104       {
105         digitalWrite(outputPin7, LOW);
106       }
107     }
108     else if (strcmp(params, "?led5=off") == 0) // Modified -- 2011 12 15 # Ben Schueler
109     {
110       if (digitalRead(outputPin8))
111       {
112         digitalWrite(outputPin8, LOW);
113       }
114     }
115     else if (strcmp(params, "?led6=off") == 0) // Modified -- 2011 12 15 # Ben Schueler
116     {
117       if (digitalRead(outputPin9))
118       {
119         digitalWrite(outputPin9, LOW);
120       }
121     }
122     if (digitalRead(outputPin3))
123     {
124       e.print("<a href='?led1=off'><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>LED 1 ON</button></a>");
125     }
126     else
127     {
128       e.print("<a href='?led1=on'><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>LED 1 OFF</button></a>");
129     }
130     if (digitalRead(outputPin5))
131     {
132       e.print("<a href='?led2=off'><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>LED 2 ON</button></a>");
133     }
134     else
135     {
136       e.print("<a href='?led2=on'><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>LED 2 OFF</button></a>");
137     }
138     if (digitalRead(outputPin6))
139     {
140       e.print("<a href='?led3=off'><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>LED 3 ON</button></a>");
141     }
142     else
143     {
144       e.print("<a href='?led3=on'><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>LED 3 OFF</button></a>");
145     }
146 
147     e.respond();
148   }
149 }