일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- Reduce
- 콘솔한글깨짐
- getters
- react
- javascipt
- IntelliJ
- javscript
- Login
- includes
- 음양더하기
- v-for
- Emit
- mutations
- 템플릿문법
- vuex
- node.js
- KAKAO
- state
- kibana
- Vue.js
- 연동
- sns로그인
- v-on
- JavaScript
- azure
- axios
- programmers
- mixins
- Express.js
- v-if
- Today
- Total
공부용
jsn270 사용하기 본문
*jsn270 라이브러리입니다.
저희가 사용한 예제는
파일 - 예제 - JSN270 - Examples - JSN270_Simple_Web_Server를 이용하도록 하겠습니다!
수정할 부분만 빨간색표시를 하도록하겠습니다
//JSN270_Simple_Web_Server
#include <Debug.h>
#include <JSN270.h>
#include <Arduino.h>
#include <SoftwareSerial.h>
#define SSID "JSN270_2G" // 접속할 WiFi의 아이디 -> 예를들어 gothiczzang 이면 "gothiczzang"으로 수정
#define KEY "12345678" // 접속할 WiFi의 비밀번호 -> 예를들어 gothiczzang 이면 "gothiczzang"으로 수정
#define AUTH "WPA2" // your wifi network security (NONE, WEP, WPA, WPA2)
#define USE_DHCP_IP 1
#if !USE_DHCP_IP
#define MY_IP "192.168.1.133"
#define SUBNET "255.255.255.0"
#define GATEWAY "192.168.1.254"
#endif
#define SERVER_PORT 80
#define PROTOCOL "TCP"
int led_status = 0;
SoftwareSerial mySerial(3, 2); // RX, TX
JSN270 JSN270(&mySerial);
void setup() {
char c;
mySerial.begin(9600);
Serial.begin(9600);
Serial.println("--------- JSN270 Simple HTTP server Test --------");
// wait for initilization of JSN270
delay(5000);
//JSN270.reset();
delay(1000);
//JSN270.prompt();
JSN270.sendCommand("at+ver\r");
delay(5);
while(JSN270.receive((uint8_t *)&c, 1, 1000) > 0) {
Serial.print((char)c);
}
delay(1000);
#if USE_DHCP_IP
JSN270.dynamicIP();
#else
JSN270.staticIP(MY_IP, SUBNET, GATEWAY);
#endif
if (JSN270.join(SSID, KEY, AUTH)) {
Serial.println("WiFi connect to " SSID);
}
else {
Serial.println("Failed WiFi connect to " SSID);
Serial.println("Restart System");
return;
}
delay(1000);
JSN270.sendCommand("at+wstat\r");
delay(5);
while(JSN270.receive((uint8_t *)&c, 1, 1000) > 0) {
Serial.print((char)c);
}
delay(1000);
JSN270.sendCommand("at+nstat\r");
delay(5);
while(JSN270.receive((uint8_t *)&c, 1, 1000) > 0) {
Serial.print((char)c);
}
delay(1000);
}
void loop() {
if (!JSN270.server(SERVER_PORT, PROTOCOL)) {
Serial.println("Failed connect ");
Serial.println("Restart System");
} else {
Serial.println("Waiting for connection...");
}
String currentLine = ""; // make a String to hold incoming data from the client
int get_http_request = 0;
while (1) {
if (mySerial.overflow()) {
Serial.println("SoftwareSerial overflow!");
}
if (JSN270.available() > 0) {
char c = JSN270.read();
Serial.print(c);
if (c == '\n') { // if the byte is a newline character
if (currentLine.length() == 0) {
if (get_http_request) {
Serial.println("new client");
//Serial.println("HTTP RESPONSE");
// Enter data mode
JSN270.sendCommand("at+exit\r");
delay(100);
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
JSN270.println("HTTP/1.1 200 OK");
JSN270.println("Content-type:text/html");
JSN270.println();
// the content of the HTTP response follows the header:
JSN270.print("Click <a href=\"/H\">here</a> turn the LED on pin 9 on<br>");
JSN270.print("Click <a href=\"/L\">here</a> turn the LED on pin 9 off<br>");
// The HTTP response ends with another blank line:
JSN270.println();
// wait until all http response data sent:
delay(1000);
// Enter command mode:
JSN270.print("+++");
delay(100);
// break out of the while loop:
break;
}
}
// if you got a newline, then clear currentLine:
else {
// Check the client request:
if (currentLine.startsWith("GET / HTTP")) {
Serial.println("HTTP REQUEST");
get_http_request = 1;
}
else if (currentLine.startsWith("GET /H")) {
//Serial.println("GET HIGH");
get_http_request = 1;
led_status = 1;
}
else if (currentLine.startsWith("GET /L")) {
//Serial.println("GET LOW");
get_http_request = 1;
led_status = 0;
}
currentLine = "";
}
}
else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
}
}
if (led_status) {
JSN270.sendCommand("at+gpioset=15,1\r"); // GET /H turns the LED on
}
else {
JSN270.sendCommand("at+gpioset=15,0\r"); // GET /H turns the LED off
}
// close the connection
JSN270.sendCommand("at+nclose\r");
Serial.println("client disonnected");
}
*ip를 할당받은 모습
할당받은 ip를 url에 치고 :80을 붙이시면
* http://192.168.0.12/
위와 같이 나오시면 성공입니다
'2018-2 IoT 가습기 > 아두이노' 카테고리의 다른 글
jsn270으로 5v릴레이모듈 켜기 (0) | 2018.11.16 |
---|---|
hm-10 블루투스 모듈 사용하기 (0) | 2018.11.16 |
DHT11 & 릴레이모듈 설정하기 (0) | 2018.11.16 |
부품내용 (0) | 2018.11.16 |