Приветствую всех. Нужна помощь (не за спасибо конечно) в реализации данного проекта. Есть 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(); } }
День добрый, гляньте этот пример, может это Вам поможет http://fluuux.de/2013/03/arduino-als-webserver-einrichten-und-webpage-von-sd-karte-laden/ Там страница сайта и рисунки на SD. Или Вам нужно исправить ошибку, в этом коде? Ошибки у Вас везде, где есть строка e.print(". Либо сделайте в одну строку. Либо создайте переменную Код (Text): String text = e.print("<a href='?led1=off&led2=on'><button style='border: 1px solid #ff0000;"; text += "border-left: 10px solid #ff0000' type='button'>LED1 IS ON</button></a><a href='?led1=on&led2=off'>"; e.print(text); Если Вам нужен исполнитель, тогда не сюда. Есть отдельная ветка Ищу исполнителя (вроде так). А так разумеется не за спасибо, надеюсь будете помогать форумчанам, по мере сил.
Не за что, лучше пишите, тут, последнее время, часто на форуме, да и другие поддержат. Если проект не закрытый (если секретный, тогда да можно на мыло). А так, лучше тут, чтобы другие могли воспользоватся Вашими наработками. И спрашивайте, если будут вопросы, мы все учимся. Просто кто-то начал раньше.
все открыто. Поменял строчку но всеравно ошибка осталась, а есть возможность в мой скетч вставить Ваш код так чтоб правильно? мне главное понять где грабли
Вот код в начале заголовка не ссылки на библиотеку, наверно, просто не вставили. Дальше без библиотеке проверить не смогу. Код (Text): 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); String print0 = "<a href='?led1=off&led2=off'><button style='border: 1px solid #ff0000;"; String print0 += "border-left: 10px solid #ff0000' type='button'>LED1 IS ON</button></a><a href='?led1=on&led2=on'>"; String print0 += "<br/><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>"; String print0 += "LED2 IS OFF</button></a>"; e.print(print0); } else if (strcmp(params, "?led1=off&led2=on") == 0) { digitalWrite(outputPin, LOW); digitalWrite(anotherOutputPin, HIGH); String print1 = "<a href='?led1=on&led2=on'><button style='border: 1px solid #000;"; print1 += "border-left: 10px solid #000' type='button'>LED1 IS OFF</button></a><a href='?led1=off&led2=off'>"; print1 += "<br/><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>" print1 += "LED2 IS ON</button></a>" e.print(print1); } else if (strcmp(params, "?led1=off&led2=off") == 0) { digitalWrite(outputPin, LOW); digitalWrite(anotherOutputPin, LOW); String print2 = "<a href='?led1=on&led2=off'><button style='border: 1px solid #000;"; print2 += "border-left: 10px solid #000' type='button'>LED1 IS OFF</button></a><a href='?led1=off&led2=on'>"; print2 += "<br/><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>"; print2 += "LED2 IS OFF</button></a>"; e.print(print2); } else if (strcmp(params, "?led1=on&led2=on") == 0) { digitalWrite(outputPin, HIGH); digitalWrite(anotherOutputPin, HIGH); String print3 = "<a href='?led1=off&led2=on'><button style='border: 1px solid #ff0000;"; print3 += "border-left: 10px solid #ff0000' type='button'>LED1 IS ON</button></a><a href='?led1=on&led2=off'>"; print3 += "<br/><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>"; print3 += "LED2 IS ON</button></a>"; e.print(); } e.respond(); } }
Без ошибок. Но устройства нет, проверить не могу. Код (Text): #include <ETHER_28J60.h> #include <etherShield.h> 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); char print0[] = "<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>"; e.print(print0); } else if (strcmp(params, "?led1=off&led2=on") == 0) { digitalWrite(outputPin, LOW); digitalWrite(anotherOutputPin, HIGH); char print1[] = "<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>"; e.print(print1); } else if (strcmp(params, "?led1=off&led2=off") == 0) { digitalWrite(outputPin, LOW); digitalWrite(anotherOutputPin, LOW); char print2[] = "<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>"; e.print(print2); } else if (strcmp(params, "?led1=on&led2=on") == 0) { digitalWrite(outputPin, HIGH); digitalWrite(anotherOutputPin, HIGH); char print3[] = "<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.print(print3); } e.respond(); } } Пока сделал, что называется в лоб. Выяснилось, что print хочет char[], а не String. Завтра подскажу как сделать, нормально. И когда пишите код, используйте отступы, как у меня в коде. Так меньше шансов ошибиться.
Все правильно пишет, это такой код. Дан видимо как заготовка, для расширения. Он отображает пример. Он управляет 6 и 7 пином, через запросы в адресной строке. А пока запустите и вбейте в браузер http://192.168.0.150/?led1=on&led2=on Он должен включить 6 и 7 пин, но если на нем ни чего нет, не увидете. http://192.168.0.150/?led1=off&led2=off Отключить. Спрашивал. Сегодня уже отдыхать, завтра около 12 часов появлюсь.
Вроде тут нет, чему зависать. Код я понял был взят из примера и доработан. Попробуйте так Код (Text): #include <ETHER_28J60.h> #include <etherShield.h> 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>Управление</h1>"); e.print("<h1><a href='/?led1=off&led2=off'><input type='button' value='Led1 и Led2 вык.' /></a></h1>"); e.print("<h1><a href='/?led1=on&led2=off'><input type='button' value='Led1 вкл., Led2 выкл.' /></a></h1>"); e.print("<h1><a href='/?led1=off&led2=on'><input type='button' value='Led1 выкл. и Led2 вкл.' /></a></h1>"); e.print("<h1><a href='/?led1=on&led2=on'><input type='button' value='Led1 и Led2 вкл.' /></a></h1>"); if (strcmp(params, "?led1=on&led2=off") == 0) { digitalWrite(outputPin, HIGH); digitalWrite(anotherOutputPin, LOW); } else if (strcmp(params, "?led1=off&led2=on") == 0) { digitalWrite(outputPin, LOW); digitalWrite(anotherOutputPin, HIGH); } else if (strcmp(params, "?led1=off&led2=off") == 0) { digitalWrite(outputPin, LOW); digitalWrite(anotherOutputPin, LOW); } else if (strcmp(params, "?led1=on&led2=on") == 0) { digitalWrite(outputPin, HIGH); digitalWrite(anotherOutputPin, HIGH); } e.respond(); } }
Как вариант, не дергать ноги всегда Код (Text): #include <ETHER_28J60.h> #include <etherShield.h> 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>Управление</h1>"); e.print("<h1><a href='/?led1=off&led2=off'><input type='button' value='Led1 и Led2 вык.' /></a></h1>"); e.print("<h1><a href='/?led1=on&led2=off'><input type='button' value='Led1 вкл., Led2 выкл.' /></a></h1>"); e.print("<h1><a href='/?led1=off&led2=on'><input type='button' value='Led1 выкл. и Led2 вкл.' /></a></h1>"); e.print("<h1><a href='/?led1=on&led2=on'><input type='button' value='Led1 и Led2 вкл.' /></a></h1>"); if (strcmp(params, "?led1=on&led2=off") == 0) { if (!digitalRead(outputPin)) { digitalWrite(outputPin, HIGH); } if (digitalRead(anotherOutputPin)) { digitalWrite(anotherOutputPin, LOW); } } else if (strcmp(params, "?led1=off&led2=on") == 0) { if (digitalRead(outputPin)) { digitalWrite(outputPin, LOW); } if (!digitalRead(anotherOutputPin)) { digitalWrite(anotherOutputPin, HIGH); } } else if (strcmp(params, "?led1=off&led2=off") == 0) { if (digitalRead(outputPin)) { digitalWrite(outputPin, LOW); } if (digitalRead(anotherOutputPin)) { digitalWrite(anotherOutputPin, LOW); } } else if (strcmp(params, "?led1=on&led2=on") == 0) { if (!digitalRead(outputPin)) { digitalWrite(outputPin, HIGH); } if (!digitalRead(anotherOutputPin)) { digitalWrite(anotherOutputPin, HIGH); } } e.respond(); } } И теперь у Вас будут кнопки, просто нажимайте их