You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
2.6 KiB
Arduino

void Ethernet_setup(){
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x00 };
IPAddress ip(192, 168, 20, 177);
IPAddress gateway(192, 168, 20, 1);
IPAddress subnet(255, 255, 255, 0);
// Mac as unique value by change last byte from ip last value.
mac[5] = ip[3] & 0xFF;
// initialize the ethernet device
Ethernet.begin(mac, ip, gateway, subnet);
// start listening for clients
server.begin();
web.begin();
// Report address
Serial.print("MAC>>");
for (int i = 0; i < 6; i++) {
if (mac[i] < 16) {
Serial.print("0");
}
Serial.print(mac[i], HEX);
if (i < 5) {
Serial.print(":");
}
}
Serial.println();
Serial.print("IP >>");
Serial.println(Ethernet.localIP());
}
void webReponse(){
EthernetClient webClient = web.available();
if (webClient) {
Serial.println("Web client connected");
while (webClient.connected()) {
if (webClient.available()) {
// 웹 브라우저에서 요청이 도착한 경우
String request = webClient.readStringUntil('\r');
//Serial.println(request);
webClient.flush();
// 웹 브라우저에 출력할 문구 작성
String response = "HTTP/1.1 200 OK\r\n";
response += "Content-Type: text/html\r\n\r\n";
response += "<html><body>";
response += Prcss_AI_Read();
//response += "<h1>Hello, World!</h1>";
response += "</body></html>";
// 문구를 웹 브라우저로 전송
webClient.print(response);
delay(1);
// 클라이언트 연결 종료
webClient.stop();
}
}
}
}
String demuxCMD(String command, String* rightPart) {
// ":"를 기준으로 문자열을 분리
int separatorIndex = command.indexOf(":");
String leftPart = command.substring(0, separatorIndex);
*rightPart = command.substring(separatorIndex + 1);
leftPart.replace(" ", "");
return leftPart;
}
int demuxNum(String rightPart, unsigned int data[]) {
// 우측의 16진수 배열을 분리하여 추출
const char* delimiter = ",";
int startIndex = 0;
int endIndex = rightPart.indexOf(delimiter);
int index = 0;
while (endIndex >= 0) {
String hexValue = rightPart.substring(startIndex, endIndex);
// 16진수 문자열을 16진수 숫자로 변환하여 data 배열에 저장
data[index] = strtoul(hexValue.c_str(), NULL, 16);
index++;
startIndex = endIndex + 1;
endIndex = rightPart.indexOf(delimiter, startIndex);
}
// 남은 마지막 16진수 배열 원소 처리
String hexValue = rightPart.substring(startIndex);
data[index] = strtoul(hexValue.c_str(), NULL, 16);
index++;
return index;
}