정보나눔

오픈소스하드웨어 프로젝트에 대한 다양한 정보를 나누는 공간입니다.

web client예제의 활용에 대해 질문 드립니다.
이것만끝내자 | 2019-11-27

#include <SPI.h>
#include "WizFi250.h"


char ssid[] = "20133057";    // your network SSID (name)
char pass[] = "uw3845aa";          // your network password
int status = WL_IDLE_STATUS;       // the Wifi radio's status

char server[] = "35b872ed.ngrok.io";

// Initialize the Ethernet client object
WiFiClient client;

void printWifiStatus();

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

  WiFi.init();

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

    // attempt to connect to WiFi network
    while ( status != WL_CONNECTED) {
      Serial.print("Attempting to connect to WPA SSID: ");
      Serial.println(ssid);
      // Connect to WPA/WPA2 network
      status = WiFi.begin(ssid, pass);
    }

    // you're connected now, so print out the data
    Serial.println("You're connected to the network");

    printWifiStatus();

    Serial.println();
    Serial.println("Starting 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.println("GET /page.html HTTP/1.1");
      client.println("Host: 35b872ed.ngrok.io");
      client.println("Connection: close");
      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);
    
  }
}


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");
}

 

 

안녕하세요. 코드와 시리얼 모니터 출력 값 입니다.

ngrok를 통해서 임시적으로 웹브라우저를 열었고, 거기서 원하는 값을 시리얼 모니터로 출력했습니다.

 

여기서 출력한 값(빨간박스)을 저희가 the Day로 두고 이용하려는데

char c = client.read();
      Serial.write(c);
      char theDay;
       theDay = c ;
       Serial.println(theDay); 

 

시리얼 모니터의 파란 박스 안의 내용이 전부  the Day로 입력이 됩니다.

빨간 박스안의 내용만 the Day로 받아오려면 어떻게 코드를 수정해야 할까요?

프로필사진

판다마니아 2019-12-03 13:27:35

  while (client.available()) {
      char c = client.read();
      Serial.write(c);
    
  }

현재 이부분이 데이터를 받아 출력하는 부분입니다.

 

현재는 1글자씩 받아 그대로 시리얼 모니터에 출력되도록 되어있는데, 이부분을 수정하여 1글자씩 받을 때 String 변수에 계속 더하도록 만드신 다음에 모든 데이터가 다 받아졌으면 저장한 Strintg 변수 값을 수정하여 원하는 데이터를 추출하시면됩니다.

이전글   |    DIY 금고 지문인식 관련해서 질문합니다. 2019-11-27
다음글   |    조도센서,피에조부저 관련 질문 드립니다.... 2019-11-27