2016-11-29 6 views
0

저는 Arduino를 처음 접했기 때문에 이것은 간단한 문제 일 수도 있지만 해결책을 찾지 못했습니다.Arduino 웹 서버 응답은 "It Works!"입니다.

Intel Galileo Gen 2 보드가 있습니다. 나는 요청에 따라 웹 서버를 제공하는 간단한 프로그램을 작성하려고 노력하고 있는데, 요청에 따라 센서에서 얻은 값을 리턴한다. 네트워크를 성공적으로 구성하고 값을 얻었지만 서버에 대한 모든 요청은 "작동합니다!" 메시지를 응답으로 보냅니다. 나는 다른 브라우저 (chromw에서 lynx까지)와 다른 nework 위치에서 시도했다.

나는 코드를 사용하고있다 : 내가 잘못 뭐하는 거지

#include <SPI.h> 
#include <Ethernet.h> 

byte mac[] = { 0x98, 0x4F, 0xEE, 0x05, 0x65, 0x02 }; 
char SENSORNAME[ ] = "galileo01"; 
IPAddress ip(192, 168, 15, 177); 
IPAddress dnServer(8, 8, 8, 8); 

EthernetServer server(80); 

int sensorPin = A0; // select the input pin for the potentiometer 
int readValue = 0; 
int prevValue = 0; 

void setup() { 
    Serial.begin(9600); 

    system("ifconfig enp0s20f6 down "); 
    system("ip link set enp0s20f6 name eth0"); 
    system("ifconfig eth0 up"); 
    Ethernet.begin(mac, ip, dnServer); 
    server.begin(); 

} 

void loop() { 
    readValue = analogRead(sensorPin); 
    EthernetClient client = server.available(); 
    if (client) { 
    boolean currentLineIsBlank = true; 
    while (client.connected()) { 
     if (client.available()) { 
     char c = client.read(); 
     Serial.write(c); 
     if (c == '\n' && currentLineIsBlank) { 
      client.println("HTTP/1.1 200 OK"); 
      client.println("Content-Type: text/html"); 
      client.println("Connection: close"); 
      client.println(); 
      client.print("{\"sensor\":\""); 
      client.print(SENSORNAME); 
      client.print("\",\"value\":\""); 
      client.print(readValue); 
      client.println("\"}"); 
      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(1); 
    // close the connection: 
    client.stop(); 
    Serial.println("client disonnected"); 
    } 
} 

?

감사합니다.


UPDATE :

내가 참조하면 요청을 할 때 루프() 함수가 처리되지 않는 것입니다. 센서 읽기 결과를 볼 수 있지만 if 절을 결코 통과하지 못합니다.

EthernetClient client = server.available(); 
    if (client) { 

내부 웹 서버가 있습니까? 어떻게 설정해야합니까?

+0

위치 : 기본 시스템은이 코드는 isue를 해결했다 추가 포트 80에서 새 서버를 설정할 수 없습니다 실행중인 웹 서버와 함께 제공? – shazin

+0

나는 그렇게 믿어. 코드에서 일부 추적을 설정하고 직렬 모니터에서 내 메시지를 볼 수 있습니다. 또한 메시지에 응답 할 때 IP가 올바르게 설정되어 있음을 알 수 있습니다. – jordi

답변

0

나는 마침내 그것을 발견했다. 당신은 아두 이노에이 코드를 번쩍 한 여부를 확인

system("systemctl stop lighttpd > /dev/ttyGS0"); 
system("systemctl stop disable > /dev/ttyGS0");