에듀이노-코딩교육 전문 쇼핑몰 에듀이노-코딩 교구는, 에듀이노!

학교, 공공기관이라면 후불결제하세요!

 
현재 위치
  1. 게시판
  2. 묻고답하기
상품 게시판 상세
온습도센서로 측정한 내용을 웹페이지에서 볼 수 있는 코드를 만드는데 도와주세요
  • 작성자 기린 (ip:)
  • 작성일 2021-07-31
  • 추천 추천하기
  • 조회수 446
평점 0점

이더넷 모듈을 구매했고, 온습도 센서로 측정한 측정값을 이더넷 모듈에 지정해준 고정IP에 접속해서 계속해서 확인하는 코드를 짜고있습니다.


상품 페이지에 올려주신 이 코드에서 


#include <EtherCard.h>
 
//0은 DHCP, 1은 Static으로 설정
#define STATIC 0  // set to 1 to disable DHCP (adjust myip/gwip values below)
 
//Static IP 일 경우 설정
#if STATIC
// ethernet interface ip address
static byte myip[] = { 192,168,0,6 };
// gateway ip address
static byte gwip[] = { 192,168,0,204 };
#endif
 
// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
 
byte Ethernet::buffer[500]; // tcp/ip send and receive buffer
 
//요청이 왔을 경우 뿌려줄 HTML 소스
const char page[] PROGMEM =
"HTTP/1.0 503 Service Unavailable\r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
"\r\n"
"<html>"
  "<head><title>"
    "Ethernet Module Test_EDUINO"
  "</title></head>"
  "<body>"
    "<h3>Eduino Ethernet Module Test</h3>"
    "<p><em>"
      "Let's Play With Arduino<br />"
    "</em></p>"
  "</body>"
"</html>"
;
 
void setup(){
  Serial.begin(57600);
  Serial.println("\n[backSoon]");
 
  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
    Serial.println( "Failed to access Ethernet controller");
#if STATIC
  ether.staticSetup(myip, gwip);
#else
  if (!ether.dhcpSetup())
    Serial.println("DHCP failed");
#endif
 
  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);  
  ether.printIp("DNS: ", ether.dnsip);  
}
#define STATIC 0  // set to 1 to disable DHCP (adjust myip/gwip values below)
void loop(){
  //웹브라우저의 요청이 들어왔을 경우 page 의 내용을 보내줌
  // wait for an incoming TCP packet, but ignore its contents
  if (ether.packetLoop(ether.packetReceive())) {
    memcpy_P(ether.tcpOffset(), page, sizeof page);
    ether.httpServerReply(sizeof page - 1);
  }
}


저는 고정IP를 사용할거니까 STATIC 1로 모두 설정해주었고 그 이후가 의문인데


제가 이더넷 없이 온습도 센서만 가지고 테스트 했을때는 온도와 습도 변수를 loop() 안에 넣어서 측정을 했었는데... 저 HTML코드는 아예 메소드 밖에 있고...

이 값을 어떻게 웹페이지에 뜰 수 있게 할 수 있을까요? 혹시 소스코드가 있으시다면 보내주실 수 있을까요?


비밀번호 : 삭제 수정
첨부파일
  • 써큘레이터 2021-07-31 0점
    수정 삭제 댓글
    스팸글 https://gist.github.com/alexishida/316f52c2d31597a43239188049cd5915
    참고해보세요
  • 기린 2021-07-31 0점
    수정 삭제 댓글
    스팸글 byte Ethernet::buffer[500]; 이 코드를 꼭 써야할까요? EthernetServer server(80); 이 코드를 쓰고 있는데... 둘 다 필요한가요
    앞에 코드를 입력하니까 자꾸 'Ethernet' is not a class, namespace, or enumeration 라는 에러가 뜹니다. 근데 제가 본문에 쓴 코드를 쓰면 또 에러가 안나요..

스팸신고 스팸해제

댓글 수정

비밀번호 :

수정 취소

/ byte

비밀번호 : 확인 취소

댓글 입력

이름: 비밀번호: 관리자답변보기

별점별점주기

/ byte

에게만 댓글 작성 권한이 있습니다.

댓글 입력

댓글달기이름 :비밀번호 :

확인

/ byte

왼쪽의 문자를 공백없이 입력하세요.(대소문자구분)

에게만 댓글 작성 권한이 있습니다.

«
»