?>

Hard Copy World

HCW

Q&A

Home > Forum >

Q&A

와이파이쉴드에서 DB로 값을 넘길때 값이 이상하게 넘어가지네요 (내용참조좀 부탁드립니다)

페이지 정보

작성자 조진호 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 작성일16-05-22 17:12 조회919회 댓글1건

본문

#include <SPI.h>
#include <WiFi.h>

char ssid[] = "G3_2306"; //  your network SSID (name)
char pass[] = "tk5dbr123";    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;            // your network key Index number (needed only for WEP)
char sn1=557;
char latitude1=60;
char longitude1=55;
int status = WL_IDLE_STATUS;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
IPAddress server(39,121,179,204);  // numeric IP for Google (no DNS)
//char server[] = "39.121.179.204";    // name address for Google (using DNS)

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
WiFiClient client;

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv != "1.1.0") {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.println("Connected to wifi");
  printWifiStatus();

  Serial.println("\nStarting connection to server...");
  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected to server");
    // Make a HTTP request:
    client.print("GET /insert_gps.php?sn=");
    client.print(sn1);
    client.print("&latitude=");
    client.print(latitude1);
    client.print("&longitude=");
    client.print(longitude1);
    client.print("HTTP/1.1");
    client.println("Host: 39.121.179.204");
    client.println();
  }
}

void loop() {
  // if there are incoming bytes available
  // from the server, read them and print them:
  while (client.available()) {
    char c = client.read();
    Serial.write(c);
  }

  client.println("GET /insert_gps.php?sn=");
    client.print(sn1);
    client.print("&latitude=");
    client.print(latitude1);
    client.print("&longitude=");
    client.print(longitude1);
    client.print(" HTTP/1.1");
    client.println("Host: 39.121.179.204");
    client.println();

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting from server.");
    client.stop();

    // do nothing forevermore:
    while (true);
  }
}


void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

소스를 이렇게 되있는데 그림처럼 DB에 변수값만 아니라 HTTP/1.1.host까지 값이 들어가버리네여 해결할수 있는 방법좀 알려주세요!
 

댓글목록

최고관리자님의 댓글

최고관리자 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 작성일

HTTP 요청을 보낼때 헤더에 포함되는 각 항목들 사이에 공백과 줄넘김 문자가 정확히 들어가야 서버에서 제대로 인식됩니다.
아래 예제 참고하세요.
https://github.com/adafruit/Adafruit_CC3000_Library/blob/master/examples/WebClient/WebClient.ino