WIFI 통신(TCP/IP)으로 서버 시간 가져오기

특징

WIFI 통신이 가능한 무선통신 모듈입니다. 시리얼통신 방식이라 아두이노, AVR, PIC 등에연결하여 쉽게 사용 가능합니다.

 

  • 802.11 b / g / n
  • Wi-Fi Direct (P2P), soft-AP
  • Built-in TCP / IP protocol stack
  • Built-in TR switch, balun, LNA, power amplifier and matching network
  • Built-in PLL, voltage regulator and power management components
  • 802.11b mode + 19.5dBm output power
  • Built-in temperature sensor
  • Support antenna diversity
  • off leakage current is less than 10uA
  • Built-in low-power 32-bit CPU: can double as an application processor
  • UART
  • STBC, 1×1 MIMO, 2×1 MIMO
  • A-MPDU, A-MSDU aggregation and the 0.4 Within wake
  • 2ms, connect and transfer data packets
  • standby power consumption of less than 1.0mW (DTIM3)

 

WAT-Arduino128 예제

부품 목록
번호 부품명 수량 기능 판매처
 1  WAT-Arduino128  1 아두이노 https://kit128.com/goods/view?no=64
 2 WIFI 모듈  1 WIFI 통신 https://kit128.com/goods/view?no=63

 

WAT-Arduino128 WIFI 모듈

 

핀 연결

아래와 WAT-Arduino128 모듈의 J26 에 연결합니다.

 

 

소스코드

소스코드는 [파일]=>[예제]=> [WhiteAT] => [Simple_GetTime] 에 있습니다.

/*
	WAT-Arduino128 과 ESP8266 wifi 예제
	서버에 접속하여 시간을 가져오는 예제

	WAT-Arduino128 : https://kit128.com/goods/view?no=64
	ESP8266 : https://kit128.com/goods/view?no=63

	출처: http://whiteat.com/Arduino
*/


#include "ESP8266.h"
#include <WAT_Multi.h>

#define SSID "kit128_ssid"
#define PASS "mypassword"
#define DST_IP "watclean7.com"  
#define PORT 1010

int pRESET = PD4;

ESP8266 wifi = ESP8266(Serial1);
WMulti tWifiSend = WMulti(5000); // for each 5 second

void setup()
{
	pinMode(pRESET, OUTPUT);
	digitalWrite(pRESET, LOW);
	delay(1000);
	digitalWrite(pRESET, HIGH);

	Serial.begin(115200);
	Serial.println("Arduino Examples - ESP8266 WiFi");
	Serial.println("    https://docs.whiteat.com/?p=675");

	// ESP8266
	Serial1.begin(9600);
	wifi.begin();
	wifi.setTimeout(1000);

	// test
	Serial.print("test: ");
	Serial.println(getStatus(wifi.test()));

	// restart
	Serial.print("restart: ");
	Serial.println(getStatus(wifi.restart()));

	// getVersion
	char version[16] = {};
	Serial.print("getVersion: ");
	Serial.print(getStatus(wifi.getVersion(version, 16)));
	Serial.print(" : ");
	Serial.println(version);

	// joinAP
	Serial.print("joinAP: ");
	Serial.println(getStatus(wifi.joinAP((char *)SSID, (char *)PASS)));

	// connect
	Serial.print("connect: ");
	Serial.println(getStatus(wifi.connect(ESP8266_PROTOCOL_TCP, DST_IP, PORT)));

	delay(1000);

	// send
	Serial.print("send: ");
	Serial.println(getStatus(wifi.send64((byte *)"TTT", 64)));

}

void loop()
{

	// read data
	unsigned int id;
	int length;
	int totalRead;
	char buffer[300] = {};

	if ((length = wifi.available()) > 0) {
		id = wifi.getId();
		totalRead = wifi.read(buffer, 300);

		if (length > 0) {
			Serial.print("Received ");
			Serial.print(totalRead);
			Serial.print("/");
			Serial.print(length);
			Serial.print(" bytes from client ");
			Serial.print(id);
			Serial.print(": ");
			Serial.println((char*)buffer);
		}
	}

	TaskWifiSend(&tWifiSend);

}

void TaskWifiSend(WMulti * _task)
{
	if (!_task->IsMyTurn()) return;
	Serial.print("send: ");
	Serial.println(getStatus(wifi.send64((byte *)"T", 64)));
}

String getStatus(bool status)
{
	if (status)
		return "OK";

	return "KO";
}

 

 

결과

일정시간마다 서버 시간을 가져옵니다.

 

 

 

제품구매

WAT-Arduino128는 https://kit128.com/goods/view?no=64 에서
WIFI Module는 https://kit128.com/goods/view?no=63 에서 구매하실 수 있습니다.

 

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다