이제 최종소스를 만들면 된다.
그런데 슬프게도 큰 문제점이 있다.
ESP8266을 할떄 하고는 다르게 아두이노 우노의 2k의 메모리가 부족하다.
문장을 만들기에는 부족하다.
이전 소스 그데로 아두이노 메가로 변경하면 문제 없다.
그러나 지금 보드 바꾸고 할라고 하니 귀찮다.
그래서 이것저것 줄일것 모두 줄여도 부족하다.
이제 생각나는 방법은 하나 뿐 PROGMEM 이다.
예) const char message [27][200] PROGMEM
이것에 대해서는 다음에 공부하기로 하고 일단 넘어가자.
그리고 전체적인 소스코드도 약간 변경 있으니 차근 차근 공부 하자.
/*Web Server*/ #include <SPI.h> #include <Ethernet.h> #include <string.h> #include <avr/pgmspace.h>
// Enter a MAC address and IP address for your controller below. byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; IPAddress ip(192, 168, 5, 177);
// Initialize the Ethernet server library // with the IP address and port you want to use // (port 80 is default for HTTP): EthernetServer server(80); char msg[200]; char* m; int select= 0; const char message [27][200] PROGMEM = { {"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"}, {" http://www.w3.org/1999/xhtml\">"</html xmlns=\"}, {"<head>"}, {"<meta http-equiv=\"Content-Type\" content=\"application/xhtml+xml; charset=utf-8\" />"}, {"<meta name=\"viewport\" content=\"user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, width=device-width\" />"}, {" http://code.google.com/apis/maps/documentation/javascript/examples/standard.css\" rel=\"stylesheet\" type=\"text/css\" />"</link href=\"}, {" }, {"<script type=\"text/javascript\">"}, {"function initalize() {"}, {"var mapOptions = {"}, {"zoom: 15,"}, {"center: new google.maps.LatLng(0, 0),"}, {"disableDefaultUI: true,"}, {"mapTypeId: google.maps.MapTypeId.ROADMAP,"}, {"draggable: false "}, {"} "}, {"var map = new google.maps.Map(document.getElementById(\"map_canvas\"), mapOptions);"}, {"var marker = new google.maps.Marker({map: map, position: map.getCenter()});"}, {"}"}, {"</script> "}, {"<title> Google Map JavaScript API </title>"}, {"</head> "}, {"<body onload=\"initalize()\">"}, {"<div id=\"map_canvas\" style=\"width: 640px; height: 480px; margin: 0 auto; top:50px; border: 1px solid black;\"> </div>"}, {"</body>"}, {"</html>"}, };
void setup() { Serial.begin(115200); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } Serial.println("Ethernet WebServer Example");
// start the Ethernet connection and the server: Ethernet.begin(mac, ip);
// Check for Ethernet hardware present if (Ethernet.hardwareStatus() == EthernetNoHardware) { Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); while (true) { delay(1); // do nothing, no point running without Ethernet hardware } } if (Ethernet.linkStatus() == LinkOFF) { Serial.println("Ethernet cable is not connected."); } // start the server server.begin(); Serial.print("server is at "); Serial.println(Ethernet.localIP()); select= 0; m =msg; }
void loop() { // listen for incoming clients EthernetClient client = server.available(); if (client) { Serial.println("new client"); // an http request ends with a blank line bool currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c; *(m) = c = client.read(); m++; //Serial.write(c); // if you've gotten to the end of the line (received a newline // character) and the line is blank, the http request has ended, // so you can send a reply if (c == '\n') { *m='\0'; Serial.write(msg); m = msg; if(currentLineIsBlank) { webPage3(client, 36.4251083, 127.389638); break; } else { // 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 disconnected"); } }
void webPage3(EthernetClient& c, double y, double x) { for(int i =0; i < 26; i++) { char* p = msg; if(i!=11) { for (byte k = 0; k < strlen_P(message[i]); k++) { *p = pgm_read_byte_near(message[i]+k); p++; } *p ='\0'; } else { p+=sprintf(p,"center: new google.maps.LatLng(%s, %s),", String(y,8).c_str(), String(x,8).c_str()); } if(strlen(msg) >200) { Serial.print(strlen(msg)); Serial.print(msg); Serial.println(); } c.println(msg); delay(10); }
return ; }
|
'아두이노' 카테고리의 다른 글
아두이노 이더넷 클라이언트의 시작-#1 (0) | 2020.05.23 |
---|---|
아두이노 이더넷 웹서버 만들기 -#18 (0) | 2020.05.20 |
아두이노 이더넷 웹서버 만들기 -#16 (0) | 2020.05.19 |
아두이노 이더넷 웹서버 만들기 -#15 (0) | 2020.05.19 |
아두이노 이더넷 웹서버 만들기 -#14 (0) | 2020.05.19 |
댓글