Web + реле
- Войдите на сайт для отправки комментариев
Втр, 18/03/2014 - 18:19
Приветствую всех. Нужна помощь (не за спасибо конечно) в реализации данного проекта. Есть Nano328 и шилд ENC28J60 (HR911105A) все подключил по схеме как http://ergoz.ru/electronics/arduino/rabota-arduino-nano-s-setevyim-kontrollerom-enc28j60.html залил скетч и вебсерв работает, но не могу сделать чтоб в браузере били кнопки(включалки с подписями и изображением "ВКЛ""ВЫКЛ") и соответственно управлять выходами ардуины нано. Вот собственно помощь нужна!
Приветствую всех. Нужна помощь (не за спасибо конечно) в реализации данного проекта. Есть 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();
}
}
Если я не ошибаюсь в этом скетче нужно нажать на текст "Arduino Web Remote" и появятся 2 кнопки:
LED1 IS ON;
LED2 IS ON
должны былы появится, но увы. вот рабочий может кому пригодится
#include "etherShield.h" #include "ETHER_28J60.h" int outputPin3 = 3; int outputPin5 = 5; int outputPin6 = 6; int outputPin7 = 7; int outputPin8 = 8; int outputPin9 = 9; 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] = {10, 0, 0, 100}; // 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(outputPin3, OUTPUT); pinMode(outputPin5, OUTPUT); pinMode(outputPin6, OUTPUT); pinMode(outputPin7, OUTPUT); pinMode(outputPin8, OUTPUT); pinMode(outputPin9, OUTPUT); } void loop() { char* params; if (params = e.serviceRequest()) { e.print("<H1>JKS home</H1>"); if (strcmp(params, "?led1=on") == 0) { if (!digitalRead(outputPin3)) { digitalWrite(outputPin3, HIGH); } } else if (strcmp(params, "?led2=on") == 0) { if (!digitalRead(outputPin5)) { digitalWrite(outputPin5, HIGH); } } else if (strcmp(params, "?led3=on") == 0) { if (!digitalRead(outputPin6)) { digitalWrite(outputPin6, HIGH); } } else if (strcmp(params, "?led4=on") == 0) { if (!digitalRead(outputPin7)) { digitalWrite(outputPin7, HIGH); } } else if (strcmp(params, "?led5=on") == 0) { if (!digitalRead(outputPin8)) { digitalWrite(outputPin8, HIGH); } } else if (strcmp(params, "?led6=on") == 0) { if (!digitalRead(outputPin9)) { digitalWrite(outputPin9, HIGH); } } else if (strcmp(params, "?led1=off") == 0)// Modified -- 2011 12 15 # Ben Schueler { if (digitalRead(outputPin3)) { digitalWrite(outputPin3, LOW); } } else if (strcmp(params, "?led2=off") == 0)// Modified -- 2011 12 15 # Ben Schueler { if (digitalRead(outputPin5)) { digitalWrite(outputPin5, LOW); } } else if (strcmp(params, "?led3=off") == 0)// Modified -- 2011 12 15 # Ben Schueler { if (digitalRead(outputPin6)) { digitalWrite(outputPin6, LOW); } } else if (strcmp(params, "?led4=off") == 0)// Modified -- 2011 12 15 # Ben Schueler { if (digitalRead(outputPin7)) { digitalWrite(outputPin7, LOW); } } else if (strcmp(params, "?led5=off") == 0) // Modified -- 2011 12 15 # Ben Schueler { if (digitalRead(outputPin8)) { digitalWrite(outputPin8, LOW); } } else if (strcmp(params, "?led6=off") == 0) // Modified -- 2011 12 15 # Ben Schueler { if (digitalRead(outputPin9)) { digitalWrite(outputPin9, LOW); } } if (digitalRead(outputPin3)) { e.print("<a href='?led1=off'><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>LED 1 ON</button></a>"); } else { e.print("<a href='?led1=on'><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>LED 1 OFF</button></a>"); } if (digitalRead(outputPin5)) { e.print("<a href='?led2=off'><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>LED 2 ON</button></a>"); } else { e.print("<a href='?led2=on'><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>LED 2 OFF</button></a>"); } if (digitalRead(outputPin6)) { e.print("<a href='?led3=off'><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>LED 3 ON</button></a>"); } else { e.print("<a href='?led3=on'><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>LED 3 OFF</button></a>"); } e.respond(); } }