Включить реле по Post запросу Arduino + enc28j60 с помощью EtherCard.h, как?

syberex
syberex аватар
Offline
Зарегистрирован: 08.03.2016

Нужно включить и выключать реле по  Post запросу Arduino + enc28j60 с применением именно  EtherCard.h, какой самый простой код?

syberex
syberex аватар
Offline
Зарегистрирован: 08.03.2016

есть страничка она коннектится к модулю, какой код нужно добавить чтоб место сэкономить и все работало?

<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <title>Arduino</title>
</head>
<body>
    <form action="http://192.168.10.150/" method="post">
        <p><b>LED control</b></p>
        <input type="radio" name="led" value="on">ON<Br>
        <input type="radio" name="led" value="off">OFF</p>
        <p><input type="submit" value="ReFresh"></p>
    </form>
</html>
syberex
syberex аватар
Offline
Зарегистрирован: 08.03.2016
#include <enc28j60.h>
#include <EtherCard.h>
#include <net.h>
 
//#include <EtherCard.h> //Подключаем библиотку для управления Ethernet модулем enc28j60
#include <EEPROM.h>
 
// MAC Address должен быть уникальным в вашей сети. Можно менять. 
const byte mymac[] PROGMEM = {0x5A,0x5A,0x5A,0x5A,0x5A,0x5A}; // mac адресс
byte myip[]={0,0,0,0};
//byte my_ip_for_ping[]={192,168,10,1};
byte my_ip_for_ping[]={0,0,0,0};
char ip_for_ping[20];
//char ip_for_ping[]=my_ip_for_ping(char);
//byte myip[]  = {192,168,10,150 }; // ip статический / постоянный Address нашей Web страницы.
//char ip_for_ping[]  = "192.168.10.1"; // адрес пингуемого устройства static
//static byte session;
 
 
// Буфер, чем больше данных на Web странице, тем больше понадобится значения буфера.
byte Ethernet::buffer[700];
BufferFiller bfill;
static uint32_t timer;
 
const char http_OK[] PROGMEM =
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\n"
"Pragma: no-cache\r\n\r\n";
 
const char http_Found[] PROGMEM =
"HTTP/1.0 302 Found\r\n"
"Location: /\r\n\r\n";
 
const char http_Unauthorized[] PROGMEM =
"HTTP/1.0 401 Unauthorized\r\n"
"Content-Type: text/html\r\n\r\n"
"<h1>401 Unauthorized</h1>";
 
// нас пингуют- событие выполненяется автоматически
static void gotPinged (byte* ptr) {
  ether.printIp(">>> ping from: ", ptr);
}
 
void get_ip_ping_eeprom(void);
void get_my_ip_from_eeprom(void);
 
void setup() 
{
  //set_ip_ping_eeprom();
  get_ip_ping_eeprom();
  get_my_ip_from_eeprom();
  Serial.begin(9600);
  Serial.println(ip_for_ping);
  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0);
  ether.staticSetup(myip);
  ether.printIp("My SET IP: ", ether.myip); // Выводим в Serial монитор статический IP адрес. 
  ether.parseIp(ether.hisip,ip_for_ping);// задаем адрес для пингования устройства
  ether.printIp("SRV: ", ether.hisip); // Выводим в Serial монитор статический IP адрес.
  ether.registerPingCallback(gotPinged); // регистрируем событие - если пингуют нас
  timer = -9999999; // start timing out right away
  }
 
void loop() {
  //Serial.println("loop");
  delay(1); // Дёргаем микроконтроллер.
  // при добавлении двух строк внизу появляется возможность пинговать устройство
  word len = ether.packetReceive();   // check for ethernet packet / проверить ethernet пакеты.
  word pos = ether.packetLoop(len);   // check for tcp packet / проверить TCP пакеты.
   // report whenever a reply to our outgoing ping comes back
  if (len > 0 && ether.packetLoopIcmpCheckReply(ether.hisip))
  {
    Serial.print("  ");
    Serial.print((micros() - timer) * 0.001, 3);
    Serial.println(" ms");
  }
  
  // ping a remote server once every few seconds
  if (micros() - timer >= 5000000) {
    ether.printIp("Pinging: ", ether.hisip);
    timer = micros();
    ether.clientIcmpRequest(ether.hisip);
  }
  //-------------------------------
    
    
  }
 
 
void def_my_ip(void)//сброс IP по умолчанию
{
  EEPROM.write(0, 192);
  EEPROM.write(1, 168);
  EEPROM.write(2, 10);
  EEPROM.write(3, 150);
}
 
void get_my_ip_from_eeprom(void)//считываем IP с eeprom
{
 myip[0]=EEPROM.read(0);
 myip[1]=EEPROM.read(1);
 myip[2]=EEPROM.read(2);
 myip[3]=EEPROM.read(3);
}
 
void set_ip_ping_eeprom(void)//запись IP ping 
{
  EEPROM.write(4, my_ip_for_ping[0]);
  EEPROM.write(5, my_ip_for_ping[1]);
  EEPROM.write(6, my_ip_for_ping[2]);
  EEPROM.write(7, my_ip_for_ping[3]);
}
 
void get_ip_ping_eeprom(void)//считываем IP с eeprom
{
 my_ip_for_ping[0]=EEPROM.read(4);
 my_ip_for_ping[1]=EEPROM.read(5);
 my_ip_for_ping[2]=EEPROM.read(6);
 my_ip_for_ping[3]=EEPROM.read(7);
 sprintf (ip_for_ping,"%u.%u.%u.%u",my_ip_for_ping[0],my_ip_for_ping[1],my_ip_for_ping[2],my_ip_for_ping[3]);
}
 
Radjah
Offline
Зарегистрирован: 06.08.2014