#1 2016-10-05 20:12:11

VladV
Учасник
Зареєстрований: 2015-01-10
Повідомлень: 19

Помогите советом,ArduinoUNO +ENC28J60 +web-server +socket client +noob

На мой взгляд задача совершенно простая, нужно что поднять на UNO web-server и сокет клиент, веб-сервер отображает статус датчиков, сокет-клиент передает эти показания сокет-серверу. Я новичок, из кусков набросал данную программку для проверки:

#include <UIPEthernet.h>

byte mac[] = {0x00,0x01,0x02,0x03,0x04,0x05};
IPAddress ip(192,168,1,203);
IPAddress socket_serv_ip(192,168,1,108);
int socket_serv_port(9734);
EthernetClient socket_client;
EthernetServer web_server(80);

void setup() {

  Serial.begin(9600);
  Ethernet.begin(mac,ip);
  web_server.begin();

  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());  
  Serial.print("subnetMask: ");
  Serial.println(Ethernet.subnetMask());
  Serial.print("gatewayIP: ");
  Serial.println(Ethernet.gatewayIP());
  Serial.print("dnsServerIP: ");
  Serial.println(Ethernet.dnsServerIP());

}

void loop() 
{
  //===================================WEB SERVER=======================================
  EthernetClient web_client = web_server.available();
  Serial.println(web_client);
  if(web_client) 
  {
    Serial.println("new web_client");
    boolean currentLineIsBlank = true;
    while(web_client.connected()) 
    {
      if(web_client.available()) 
      {
        char c = web_client.read();
        Serial.write(c);
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          web_client.println("HTTP/1.1 200 OK");
          web_client.println("Content-Type: text/html");
          web_client.println("Connection: close");  // the connection will be closed after completion of the response
          web_client.println("Refresh: 10"); 
          web_client.println();
          web_client.println("<!DOCTYPE HTML>");
          web_client.println("<html>");
          // output the value of each analog input pin
          for(int analogChannel = 0; analogChannel < 6; analogChannel++) 
          {
            int sensorReading = analogRead(analogChannel);
            web_client.print("analog input ");
            web_client.print(analogChannel);
            web_client.print(" is ");
            web_client.print(sensorReading);
            web_client.println("<br />");       
          }
          web_client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } 
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1000);
    // close the connection:
    web_client.stop();
    Serial.println("client disonnected");
    }
    //===================================WEB SERVER END=======================================
    delay(1000);
    //===================================SOCKET CLIENT=======================================
    if(socket_client.connect(IPAddress(socket_serv_ip),socket_serv_port))
      {
          Serial.println("Client connected");
          socket_client.println("Hello world!!");
          delay(500);
          if(socket_client.available()==0)
            {
              Serial.println("Client disconnect");
              socket_client.stop();
            } 
      }
     //===================================SOCKET CLIENT END=======================================    
  }

Проблема в том, что сокет-клиент регулярно отправляет данные сокет-серверу, а веб страница просто не загружается, убираю из кода часть с сокет-клиентом, веб-страница начинает работать, подскажите где я туплю? hmm
Заранее благодарю, тех кто хоть пытался помочь!

Остання редакція VladV (2016-10-05 20:12:33)

Неактивний

Швидке повідомлення

Введіть повідомлення і натисніть Надіслати

Підвал форуму