아두이노에 연결된 온도센서의 값을 읽어서 ESP8266과 PHP를 이용하여 MySQL에 저장하는 예제입니다.
2016. 5. 21. 최초작성
2018. 10. 17. 마지막 업데이트
1. 다음 포스팅에 Arduino Uno와 ESP8266 연결하는 방법과 필요한 라이브러리를 설치하는 방법이 소개되어있습니다.
먼저 진행을 해야 합니다.
Arduino Uno에 ESP8266 WiFi 모듈을 연결하여 사용하는 방법 http://webnautes.tistory.com/755 |
2. 다음 포스팅에 Arduino Uno와 DB18B20 연결 방법과 필요한 라이브러리를 설치하는 방법이 소개되어 있습니다.
먼저 진행을 해야 합니다.
Arduino Uno에서 DS18B20 1-Wire 온도 센서 사용하기 http://webnautes.tistory.com/631 |
2. 윈도우 또는 리눅스에 아파치 웹서버, MySQL, PHP를 설치합니다.
Ubuntu 16.04에 LAMP ( Apache2, MySQL , PHP7) 설치하는 방법 http://webnautes.tistory.com/1028 Ubuntu 18.04에 LAMP ( Apache2, MySQL , PHP 7) 설치하는 방법 http://webnautes.tistory.com/1185 윈도우 기반 웹 개발 환경 만들기 ( Apache2, PHP, MySQL, PhpMyAdmin ) http://webnautes.tistory.com/1206 Raspberry Pi 3에 LAMP (Linux, Apache, MySQL, PHP) 설치하는 방법 http://webnautes.tistory.com/842 |
3. 데이터를 저장할 테이블을 생성합니다.
mysql> create database db; |
4. 데이터베이스에 값을 넣을때 사용할 PHP 파일을 생성하여 다음 내용을 복사하여 붙여넣기 해줍니다.
리눅스
sudo nano /var/www/html/insert_data.php |
윈도우
C:\wamp64\www 위치에 insert_data.php 파일 생성 |
<?php |
5. 다음 아두이노 코드를 업로드 합니다.
#include <OneWire.h> #define PASSWORD "공유기의 비밀번호" #define SERVERIP "서버 아이피" //SoftwareSerial mySerial(11, 10); /* RX:D11, TX:D10 */ SoftwareSerial mySerial(10, 9); /* RX:D10, TX:D9 */ |
6. 아두이노 IDE에서 툴 > 시리얼모니터를 선택합니다.
공유기에 접속 성공하면 “OK, Connected to WiFi” 메시지가 보입니다.
아두이노에 연결된 DB18B20를 찾았다면 “Found 1 devices”라는 메시지가 보입니다.
이후 온도를 가져오고(Requesting temperatures...Done)
웹서버에 온도를 저장하는 것(GET /insert_data.php?num=온도)을 반복합니다.
7. MySQL을 확인해보면 데이터가 입력되는 것을 볼 수 있습니다.
'WiFi ESP8266' 카테고리의 다른 글
Arduino UNO에서 ESP8266 WiFi 모듈을 사용하는 방법 (120) | 2019.01.16 |
---|---|
Arduino Uno에서 ESP8266을 이용하여 MYSQL에 온도값(DB18B20) 넣기 (245) | 2018.10.17 |
Android 앱에서 ESP8266 WiFi 모듈을 연결한 Arduino Uno 제어하기 (66) | 2018.09.02 |
ESP8266 모듈을 위한 펌웨어 컴파일 환경 구축 및 MicroPython 스크립트 태스트 (0) | 2016.05.22 |
ESP8266 모듈에서 MicroPython 프로그래밍 (0) | 2016.05.22 |
ESP8266 펌웨어 업그레이드 및 공유기 접속 테스트 (3) | 2016.05.21 |
포스트 작성시에는 문제 없었지만 이후 문제가 생길 수 있습니다.
질문을 남겨주면 가능한 빨리 답변드립니다.
여러분의 응원으로 좋은 컨텐츠가 만들어집니다.
지금 본 내용이 도움이 되었다면 유튜브 구독 부탁드립니다.
감사합니다 ~~
유튜브 구독하기
제가 쓴 책도 한번 검토해보세요 ^^
- 이전 댓글 더보기
-
-
원인을 찾은 듯합니다.
다음 두가지를 모두 검토해보세요.
1. 다음 포스트와 핀 연결이 달라서 문제일 수 있습니다.
Arduino Uno에 ESP8266 WiFi 모듈을 연결하여 사용하는 방법
http://webnautes.tistory.com/755
실제 핀 연결을 한번 더 확인하고 수정하세요.
//SoftwareSerial mySerial(11, 10); /* RX:D11, TX:D10 */
SoftwareSerial mySerial(10, 9); /* RX:D10, TX:D9 */
2. 윈도우 10 업데이트 후.. 기존 방법으로 외부 연결이 안됩니다.
방어벽을 해제해야 동작합니다.
질문하신 것은..
1. 위에서 언급한 두가지를 모두 살펴보면 해결될 듯합니다.
2. 밎습니다. 폴더 안에 넣으면 됩니다.
3. 웹에서 사용하는 방식으로 접근하기 때문입니다.
4. 소수점 없는 문자열로 보내면 정수로 저장될겁니다.
-
코드22 2019.05.21 15:51
감사합니다. 두가지 모두 검토해서 rx,tx핀도 본문과 같이 바꿨고, windos상에서 방화벽도 해제했습니다. 죄송하게도... 아직 값이 안들어가는데 제가 에러로그를 살펴보니 아래 오류 부분이 문젠것같습니다.
_____________________________________
[Tue May 21 15:41:30.860322 2019] [mpm_prefork:notice] [pid 3470] AH00163: Apache/2.4.29 (Ubuntu) configured -- resuming normal operations
[Tue May 21 15:41:30.860413 2019] [core:notice] [pid 3470] AH00094: Command line: '/usr/sbin/apache2'
이 부분을 apache2 -t 해봤을 때 구문오류로 apache2.conf파일의 'DefaultRuntimeDir'이 유효한 디렉토리여야하고 serverroot와 연관성있어야한다는데 어떤식으로 바꿔야할지 모르겠습니다.
현재는 'DefaultRuntimeDir ${APACHE_RUN_DIR}' 라고 되어있습니다.
-
-
학생B 2019.05.20 15:53
안녕하세요. 항상 잘보고 있습니다 . 현재 포트는 RX:D0, TX:D1 로 해 놓은 상태이고 그 외의 변경점은 없습니다.
지금 와이파이를 이용하여 db에 접속시키려고 하는데 와이파이가 연결되지 않고 Can not connect to the WiFi 만 나오고 있습니다.
어떤 부분에서 고쳐야 할 지 알 수 있을까요?
#include <OneWire.h>
#include <DallasTemperature.h>
#include <string.h>
#include "ESP8266.h"
#include <SoftwareSerial.h>
#define SSID "olleh_WiFi_AF96"
#define PASSWORD "0000008238"
#define SERVERIP "59.0.194.34"
//SoftwareSerial mySerial(11, 10); /* RX:D11, TX:D10 */
SoftwareSerial mySerial(0, 1); /* RX:D10, TX:D9 */
//DS18B20 온도 센서의 데이터선인 가운데 핀을 아두이노 3번에 연결합니다.
#define ONE_WIRE_BUS 3
//1-wire 디바이스와 통신하기 위한 준비
OneWire oneWire(ONE_WIRE_BUS);
// oneWire선언한 것을 sensors 선언시 참조함.
DallasTemperature sensors(&oneWire);
//다비아스 주소를 저장할 배열 선언
DeviceAddress insideThermometer;
char * floatToString(char * outstr, double val, byte precision, byte widthp){
char temp[16]; //increase this if you need more digits than 15
byte i;
temp[0]='\0';
outstr[0]='\0';
if(val < 0.0){
strcpy(outstr,"-\0"); //print "-" sign
val *= -1;
}
if( precision == 0) {
strcat(outstr, ltoa(round(val),temp,10)); //prints the int part
}
else {
unsigned long frac, mult = 1;
byte padding = precision-1;
while (precision--)
mult *= 10;
val += 0.5/(float)mult; // compute rounding factor
strcat(outstr, ltoa(floor(val),temp,10)); //prints the integer part without rounding
strcat(outstr, ".\0"); // print the decimal point
frac = (val - floor(val)) * mult;
unsigned long frac1 = frac;
while(frac1 /= 10)
padding--;
while(padding--)
strcat(outstr,"0\0"); // print padding zeros
strcat(outstr,ltoa(frac,temp,10)); // print fraction part
}
// generate width space padding
if ((widthp != 0)&&(widthp >= strlen(outstr))){
byte J=0;
J = widthp - strlen(outstr);
for (i=0; i< J; i++) {
temp[i] = ' ';
}
temp[i++] = '\0';
strcat(temp,outstr);
strcpy(outstr,temp);
}
return outstr;
}
void setup(void)
{
//시리얼 포트 초기화
Serial.begin(9600);
/////////////////////////////////////////////////////////////////////////
Serial.setTimeout(5000);
mySerial.begin(9600);
Serial.println("ESP8266 connect");
boolean connected=false;
for(int i=0;i<10;i++)
{
if(connectWiFi())
{
connected = true;
break;
}
}
if (!connected){while(1);}
delay(5000);
mySerial.println("AT+CIPMUX=0");
///////////////////////////////////////////////////////////////////////////
//1-wire 버스 초기화
sensors.begin();
//발견한 디바이스 갯수
Serial.print("Found ");
Serial.print(sensors.getDeviceCount(), DEC);
Serial.println(" devices.");
// parasite power 모드일 때에는 2핀(GND와 DQ 핀)만 연결하면 됨.
Serial.print("Parasite power is: ");
if (sensors.isParasitePowerMode()) Serial.println("ON");
else Serial.println("OFF");
//버스에서 첫번째 장치의 주소를 가져온다.
if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
//버스에서 발견한 첫번째 장치의 주소 출력
Serial.print("Device 0 Address: ");
printAddress(insideThermometer);
Serial.println();
//데이터시트에서 확인결과 9~12비트까지 설정 가능
sensors.setResolution(insideThermometer, 10);
Serial.print("Device 0 Resolution: ");
Serial.print(sensors.getResolution(insideThermometer), DEC);
Serial.println();
}
// 온도를 출력하는 함수
void printTemperature(DeviceAddress deviceAddress)
{
//섭씨 온도를 가져옴
float tempC = sensors.getTempC(deviceAddress);
Serial.print("Temp C: ");
Serial.print(tempC);
Serial.print(" Temp F: ");
//화씨 온도로 변환
Serial.println(DallasTemperature::toFahrenheit(tempC));
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += SERVERIP;
cmd += "\",80";
Serial.println(cmd);
mySerial.println(cmd);
if(mySerial.find("Error"))
{
Serial.println( "TCP connect error" );
return;
}
char test[20];
String temp(floatToString(test,tempC, 2, 0));
cmd = "GET /insert_data.php?moisture_level="+temp+"\r\n";
mySerial.print("AT+CIPSEND=");
mySerial.println(cmd.length());
Serial.println(cmd);
if(mySerial.find(">"))
{
Serial.print(">");
}else
{
mySerial.println("AT+CIPCLOSE");
Serial.println("connect timeout");
delay(1000);
return;
}
mySerial.print(cmd);
delay(2000);
//Serial.find("+IPD");
while (Serial.available())
{
char c = Serial.read();
mySerial.write(c);
if(c=='\r') mySerial.print('\n');
}
Serial.println("====");
delay(1000);
}
//디바이스 주소를 출력하는 함수
void printAddress(DeviceAddress deviceAddress)
{
for (uint8_t i = 0; i < 8; i++)
{
if (deviceAddress[i] < 16) Serial.print("0");
Serial.print(deviceAddress[i], HEX);
}
}
void loop(void)
{
Serial.print("Requesting temperatures...");
//sensors.requestTemperatures(); //연결되어 있는 전체 센서의 온도 값을 읽어옴
sensors.requestTemperaturesByIndex(0); //첫번째 센서의 온도값 읽어옴
Serial.println("DONE");
//센서에서 읽어온 온도를 출력
printTemperature(insideThermometer);
}
boolean connectWiFi()
{
//mySerial.println("AT+CWMODE=1");
String cmd="AT+CWJAP=\"";
cmd+=SSID;
cmd+="\",\"";
cmd+=PASSWORD;
cmd+="\"";
mySerial.println(cmd);
Serial.println(cmd);
delay(3000);
if(mySerial.find("OK"))
{
Serial.println("OK, Connected to WiFi.");
return true;
}
else
{
Serial.println("Can not connect to the WiFi.");
return false;
}
} -
영원 2019.05.29 20:36
올려주신 것을 기반으로 오류나는 것들은 빼고 우선 와이파이에 연결하는 것 까지는 성공했습니다.
윈도우용 wampserver을 설치했으며,
백신프로그램에서 방화벽도 관리하길래 설정 들어가서 아파치 http 서버 프로그램도 허용해놓고,
개인 네트워크로 설정해둔 상태입니다.
웹 브라우저에서 테스트 해보면 DB로 잘 넘어가는데 문제는 시리얼 모니터상에서는 계속 php 파일에 접근을 못하고 있습니다. 혹시나 해서 dust=40 이런 식으로 아두이노 코딩 시에 바로 값을 넣어서 보내게끔 해봤는데도 동일하구요.
지금 보내려는 값은 int형 dusty입니다. get 형식이 문자열 형식으로 받는거는 알겠는데 이것을 어떻게 적용해야 할 지를 모르겠네요.
#include <Wire.h>
#include <SoftwareSerial.h>
#include <doxygen.h>
#include "ESP8266.h"
#include <string.h>
SoftwareSerial mySerial(6,5);
#define SSID "ASUS"
#define PASSWORD "kp960531"
#define SERVERIP "192.168.0.31"
float previous_dustDensity = 0;
float alpha = 0.8; // 깨끗한 상태의 측정 전압(기준)
float fanSpeed = 0; //
float fanPWM = 3; // Pin D3 팬의 PWM 센서에 연결
int fanSensor = 8; // Pin D8 팬의 RPM 센서에 연결
int Speed = 0; //0부터 255까지 속도 지정.
unsigned long SensorPulsTijd;
int measurePin = 0; //먼지 센서의 센서를 아두이노 A0핀에 연결
int ledPower = 2; // 먼지 센서의 LED를 아두이노 D2 핀에 연결
int pm50_pin = 10; // 노랑 LED - PM 50 이하 OK
int pm70_pin = 11; // 빨강 LED - PM 70 이상 경고
int samplingTime = 280;
int deltaTime = 40;
int sleepTime = 9680;
float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;
float average_dustDensity = 0;
float previousDensity = 0.0;
int num = 50; //샘플수
float sum = 0.0;
float D[] = {
0.0, 0.0, 0.0, 0.0, 0.0,0.0, 0.0, 0.0, 0.0,0.0,
0.0, 0.0, 0.0, 0.0, 0.0,0.0, 0.0, 0.0, 0.0,0.0,
0.0, 0.0, 0.0, 0.0, 0.0,0.0, 0.0, 0.0, 0.0,0.0,
0.0, 0.0, 0.0, 0.0, 0.0,0.0, 0.0, 0.0, 0.0,0.0,
0.0, 0.0, 0.0, 0.0, 0.0,0.0, 0.0, 0.0, 0.0,0.0
};
void setup(){
Serial.begin(9600);
pinMode(ledPower,OUTPUT);// 미세먼지 센서 내부 LED
pinMode(pm50_pin, OUTPUT);digitalWrite(pm50_pin,LOW); //PM50 LED
pinMode(pm70_pin, OUTPUT);digitalWrite(pm70_pin,LOW); //PM70 이상 LED
pinMode(fanSensor, INPUT);
pinMode(fanSpeed, INPUT);
digitalWrite(fanSensor, HIGH);
Serial.setTimeout(5000);
mySerial.begin(9600);
Serial.println("ESP8266 connect");
}
void loop() {
D[num-1] = particleSensing();
for ( int i = 0; i<num; i++ ) {
D[i] = D[i+1];
sum = sum + D[i];
}
average_dustDensity = sum/num;
int dnsty = alpha*previousDensity + (1.0-alpha)*average_dustDensity;
if( dnsty <= 50 ) {digitalWrite(pm70_pin, LOW);digitalWrite(pm50_pin, HIGH);delay(50);analogWrite(3, Speed=100);}
if( dnsty >= 70 ) {digitalWrite(pm50_pin, LOW);digitalWrite(pm70_pin, HIGH);delay(50);analogWrite(3, Speed=185);}
if( dnsty >= 90 ) {digitalWrite(pm50_pin, HIGH);digitalWrite(pm70_pin, LOW);delay(50);analogWrite(3, Speed=255);}
sum = 0.0;
previousDensity = average_dustDensity;
Serial.print("dust_level: ");
Serial.println((int)dnsty);
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += SERVERIP;
cmd += "\",80";
Serial.println(cmd);
mySerial.println(cmd);
if(mySerial.find("Error"))
{
Serial.println( "TCP connect error" );
return;
}
char test[20];
cmd = "GET /test.php?dust=50\r\n";
mySerial.print("AT+CIPSEND=");
mySerial.println(cmd.length());
Serial.println(cmd);
if(mySerial.find(">"))
{
Serial.print(">");
}else
{
mySerial.println("AT+CIPCLOSE");
Serial.println("connect timeout");
delay(1000);
return;
}
mySerial.print(cmd);
delay(2000);
//Serial.find("+IPD");
while (Serial.available())
{
char c = Serial.read();
mySerial.write(c);
if(c=='\r') mySerial.print('\n');
}
Serial.println("====");
delay(1000);
}
float particleSensing() {
digitalWrite(ledPower,LOW); // power on the LED
delayMicroseconds(samplingTime);
voMeasured = analogRead(measurePin);
delayMicroseconds(deltaTime);
digitalWrite(ledPower,HIGH); // turn the LED off
delayMicroseconds(sleepTime);
calcVoltage = voMeasured * (5.0 / 1024.0);
if( calcVoltage > 0.6 ) {
dustDensity =1000.0*( 0.172 * calcVoltage - 0.1);
delay(190);
}
return dustDensity;
}
boolean connectWiFi()
{
String cmd="AT+CWJAP=\"";
cmd+=SSID;
cmd+="\",\"";
cmd+=PASSWORD;
cmd+="\"";
mySerial.println(cmd);
Serial.println(cmd);
delay(3000);
if(mySerial.find("OK"))
{
Serial.println("OK, Connected to WiFi.");
return true;
}
else
{
Serial.println("Can not connect to the WiFi.");
return false;
}
}-
C:\wamp64\logs에 있는 로그에 기록이 남아있지 않다면 아파치 웹서버에 접속이 안되는듯합니다. 다음 코드로 테스트해보세요..
#include <string.h>
#include "ESP8266.h"
#include <SoftwareSerial.h>
#define SSID "SSID"
#define PASSWORD "비밀번호"
#define SERVERIP "아이피주소"
SoftwareSerial mySerial(10, 9); /* RX:D10, TX:D9 */
void setup(void)
{
//시리얼 포트 초기화
Serial.begin(9600);
/////////////////////////////////////////////////////////////////////////
Serial.setTimeout(5000);
mySerial.begin(9600);
Serial.println("ESP8266 connect");
boolean connected=false;
for(int i=0;i<10;i++)
{
if(connectWiFi())
{
connected = true;
break;
}
}
if (!connected){while(1);}
delay(5000);
mySerial.println("AT+CIPMUX=0");
///////////////////////////////////////////////////////////////////////////
}
// 온도를 출력하는 함수
void printTemperature()
{
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += SERVERIP;
cmd += "\",80";
Serial.println(cmd);
mySerial.println(cmd);
if(mySerial.find("Error"))
{
Serial.println( "TCP connect error" );
return;
}
char test[20];
cmd = "GET /insert_data.php?num=44\r\n";
mySerial.print("AT+CIPSEND=");
mySerial.println(cmd.length());
Serial.println(cmd);
while (Serial.available())
{
char c = Serial.read();
mySerial.write(c);
if(c=='\r') mySerial.print('\n');
}
if(mySerial.find(">"))
{
Serial.print(">");
}else
{
mySerial.println("AT+CIPCLOSE");
Serial.println("connect timeout");
delay(1000);
return;
}
mySerial.print(cmd);
delay(2000);
//Serial.find("+IPD");
while (Serial.available())
{
char c = Serial.read();
mySerial.write(c);
if(c=='\r') mySerial.print('\n');
}
Serial.println("====");
delay(1000);
}
void loop(void)
{
Serial.print("Requesting temperatures...");
//센서에서 읽어온 온도를 출력
printTemperature();
}
boolean connectWiFi()
{
//mySerial.println("AT+CWMODE=1");
String cmd="AT+CWJAP=\"";
cmd+=SSID;
cmd+="\",\"";
cmd+=PASSWORD;
cmd+="\"";
mySerial.println(cmd);
Serial.println(cmd);
delay(3000);
if(mySerial.find("OK"))
{
Serial.println("OK, Connected to WiFi.");
return true;
}
else
{
Serial.println("Can not connect to the WiFi.");
return false;
}
} -
영원 2019.05.30 08:09
int dnsty = alpha*previousDensity + (1.0-alpha)*average_dustDensity;
if( dnsty <= 50 ) {digitalWrite(pm70_pin, LOW);digitalWrite(pm50_pin, HIGH);delay(50);analogWrite(3, Speed=100);}
if( dnsty >= 70 ) {digitalWrite(pm50_pin, LOW);digitalWrite(pm70_pin, HIGH);delay(50);analogWrite(3, Speed=185);}
if( dnsty >= 90 ) {digitalWrite(pm50_pin, HIGH);digitalWrite(pm70_pin, LOW);delay(50);analogWrite(3, Speed=255);}
sum = 0.0;
previousDensity = average_dustDensity;
Serial.print("dust_level: ");
Serial.println((int)dnsty);
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += SERVERIP;
cmd += "\",80";
Serial.println(cmd);
mySerial.println(cmd);
if(mySerial.find("Error"))
{
Serial.println( "TCP connect error" );
return;
}
cmd = "GET /test.php?dust='dusty'\r\n";
mySerial.print("AT+CIPSEND=");
mySerial.println(cmd.length());
아뇨..int형으로 되어있습니다.
이걸 string형으로 바꿀려면 어떻게 해야할까요..?
-
다음 링크를 참고하세요
https://stackoverflow.com/questions/7910339/how-to-convert-int-to-string-on-arduino -
dsd 2019.06.03 17:40
선생님 안녕하세요. 위 첫번째 덧글 다신 분과 같이
링크에 있는 wifi 연결하기는 성공했는데 소스에서는 wifi에 연결이 안되네요 ㅠ
AT+CWJAP="SSID","PASSWORD"(잘 채웠는데 안되네요..ㅠ)
Can not connect to the WiFi
아두이노에 코딩 할때 ,로 구분하는것도 맞는것 같은데 왜 안될까요ㅠ
공유기에는 비밀번호가 없어서 모바일 핫스팟 사용했습니다.
-------------------------------------------------------------------
지금 이상황이랑 같습니다.. ㅠ 선생님께서 링크 주신 아두이노 우노와 esp-01 연결에서 맨 처음에는
카페 wifi로 해서 도저히 안되다가 핸드폰 핫스팟으로 wifi변경을 하니 되서 거기까지는 성공했습니다.
(도대체 무슨 차이인지를 모르겠더군요)
그래서 똑같이 이대로 소스 코드 하고 했는데도 (분명 SSID와 비밀번호가 같습니다. 서버 아이피도 IPCONFIG로 확인해서 제대로 쳤구요..)
그런데도 WIFI연결이 실패했다고만 뜨네요 ㅠ 도대체 무슨 문제일까요 ?-
ㅇㄴㅁㅇ 2019.06.03 18:26
***** Test which uses port 80 *****
===== Tested by command netstat filtered on port 80 =====
Test for TCP
Your port 80 is used by a processus with PID = 3704
The processus of PID 3704 is 'httpd.exe' Session: Services
The service of PID 3704 for 'httpd.exe' is 'Apache2.4'
*** ERROR *** This service IS NOT from Wampserver - Should be: 'wampapache64'
Test for TCPv6
Your port 80 is used by a processus with PID = 3704
The processus of PID 3704 is 'httpd.exe' Session: Services
The service of PID 3704 for 'httpd.exe' is 'Apache2.4'
*** ERROR *** This service IS NOT from Wampserver - Should be: 'wampapache64'
===== Tested by attempting to open a socket on port 80 =====
Your port 80 is actually used by :
Server: Apache/2.4.39 (Win64) PHP/7.3.5
80포트 결과입니다.. -
ㅁㄴㅇㅇ 2019.06.03 18:27
[Wed May 29 20:16:06.272715 2019] [mpm_winnt:notice] [pid 7616:tid 748] AH00455: Apache/2.4.39 (Win64) PHP/7.2.18 configured -- resuming normal operations
[Wed May 29 20:16:06.273712 2019] [mpm_winnt:notice] [pid 7616:tid 748] AH00456: Apache Lounge VC15 Server built: Mar 28 2019 11:59:33
[Wed May 29 20:16:06.273712 2019] [core:notice] [pid 7616:tid 748] AH00094: Command line: 'c:\\wamp64\\bin\\apache\\apache2.4.39\\bin\\httpd.exe -d C:/wamp64/bin/apache/apache2.4.39'
[Wed May 29 20:16:06.300640 2019] [mpm_winnt:notice] [pid 7616:tid 748] AH00418: Parent: Created child process 628
[Wed May 29 20:16:08.107809 2019] [mpm_winnt:notice] [pid 628:tid 4] AH00354: Child: Starting 64 worker threads.
[Wed May 29 20:19:31.073688 2019] [mpm_winnt:notice] [pid 7616:tid 748] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Wed May 29 20:19:33.077329 2019] [mpm_winnt:notice] [pid 628:tid 4] AH00364: Child: All worker threads have exited.
[Wed May 29 20:19:33.108246 2019] [mpm_winnt:notice] [pid 7616:tid 748] AH00430: Parent: Child process 628 exited successfully.
[Wed May 29 20:19:38.663394 2019] [mpm_winnt:notice] [pid 6112:tid 748] AH00455: Apache/2.4.39 (Win64) PHP/7.2.18 configured -- resuming normal operations
[Wed May 29 20:19:38.663394 2019] [mpm_winnt:notice] [pid 6112:tid 748] AH00456: Apache Lounge VC15 Server built: Mar 28 2019 11:59:33
[Wed May 29 20:19:38.663394 2019] [core:notice] [pid 6112:tid 748] AH00094: Command line: 'c:\\wamp64\\bin\\apache\\apache2.4.39\\bin\\httpd.exe -d C:/wamp64/bin/apache/apache2.4.39'
[Wed May 29 20:19:38.686334 2019] [mpm_winnt:notice] [pid 6112:tid 748] AH00418: Parent: Created child process 11580
[Wed May 29 20:19:41.187645 2019] [mpm_winnt:notice] [pid 11580:tid 716] AH00354: Child: Starting 64 worker threads.
[Thu May 30 23:47:24.714238 2019] [mpm_winnt:notice] [pid 6112:tid 748] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Thu May 30 23:47:26.783032 2019] [mpm_winnt:notice] [pid 11580:tid 716] AH00364: Child: All worker threads have exited.
[Thu May 30 23:47:26.938986 2019] [mpm_winnt:notice] [pid 6112:tid 748] AH00430: Parent: Child process 11580 exited successfully.
이게 아파치 로그입니다.
-
-
-
sh 2019.06.14 20:42
안녕하세요 질문이있습니다.
제가 원래코드의 Wifi connect가 계속오류가 나서 선생님의 ESP8266과 TCP통신을 하는 예제에서
와이파이 연결하는 부분을 따와서 사용했습니다.
현재 LED상태에 따라 값을 넘겨주는 코드를 작성했는데요 코드를 한번봐주실 수 있는지 궁금합니다.
그리고 PHP파일에 데이터베이스이름은 기존의 mysql을 수정하지않았다면
db로 하는게맞나요?
$con = mysqli_connect("localhost", "root", "-----", "db"); 이렇게 되있습니다.
#include <string.h>
#include "ESP8266.h"
#include <SoftwareSerial.h>
#define SSID "DAWN-2F"
#define PASSWORD "cafedawn11"
#define SERVERIP "172.30.1.1"
SoftwareSerial mySerial(9, 10);
boolean inConnected = false;
ESP8266 wifi(mySerial);
char * floatToString(char * outstr, double val, byte precision, byte widthp){
char temp[16]; //increase this if you need more digits than 15
byte i;
temp[0]='\0';
outstr[0]='\0';
if(val < 0.0){
strcpy(outstr,"-\0"); //print "-" sign
val *= -1;
}
if( precision == 0) {
strcat(outstr, ltoa(round(val),temp,10)); //prints the int part
}
else {
unsigned long frac, mult = 1;
byte padding = precision-1;
while (precision--)
mult *= 10;
val += 0.5/(float)mult; // compute rounding factor
strcat(outstr, ltoa(floor(val),temp,10)); //prints the integer part without rounding
strcat(outstr, ".\0"); // print the decimal point
frac = (val - floor(val)) * mult;
unsigned long frac1 = frac;
while(frac1 /= 10)
padding--;
while(padding--)
strcat(outstr,"0\0"); // print padding zeros
strcat(outstr,ltoa(frac,temp,10)); // print fraction part
}
// generate width space padding
if ((widthp != 0)&&(widthp >= strlen(outstr))){
byte J=0;
J = widthp - strlen(outstr);
for (i=0; i< J; i++) {
temp[i] = ' ';
}
temp[i++] = '\0';
strcat(temp,outstr);
strcpy(outstr,temp);
}
return outstr;
}
void setup(void)
{
//시리얼 포트 초기화
Serial.begin(9600);
/////////////////////////////////////////////////////////////////////////
Serial.setTimeout(5000);
mySerial.begin(9600);
Serial.println("ESP8266 connect");
Serial.print("FW Version:");
Serial.println(wifi.getVersion().c_str());
if (wifi.setOprToStationSoftAP()) {
Serial.print("to station + softap ok\r\n");
} else {
Serial.print("to station + softap err\r\n");
}
if (wifi.joinAP(SSID, PASSWORD)) {
Serial.print("Join AP success\r\n");
Serial.print("IP:");
Serial.println( wifi.getLocalIP().c_str());
} else {
Serial.print("Join AP failure\r\n");
}
if (wifi.disableMUX()) {
Serial.print("single ok\r\n");
} else {
Serial.print("single err\r\n");
}
Serial.print("setup end\r\n");
//////////////////////////////////////////////////////////////////////////
}
// 온도를 출력하는 함수
void printTemperature()
{
//섭씨 온도를 가져옴
//float tempC = sensors.getTempC(deviceAddress);
//Serial.print("Temp C: ");
// Serial.print(tempC);
// Serial.print(" Temp F: ");
//화씨 온도로 변환
// Serial.println(DallasTemperature::toFahrenheit(tempC));
int state = 0;
if(digitalRead(11) == HIGH){
digitalWrite(11, LOW);
state = 0;
} else {
digitalWrite(11, HIGH);
state = 1;
}
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += SERVERIP;
cmd += "\",80";
Serial.println(cmd);
mySerial.println(cmd);
if(mySerial.find("Error"))
{
Serial.println( "TCP connect error" );
return;
}
char test[20];
String temp(floatToString(test,state, 2, 0));
cmd = "GET /insert_data.php?num="+temp+"\r\n";
mySerial.print("AT+CIPSEND=");
mySerial.println(cmd.length());
Serial.println(cmd);
if(mySerial.find(">"))
{
Serial.print(">");
}else
{
mySerial.println("AT+CIPCLOSE");
Serial.println("connect timeout");
delay(1000);
return;
}
mySerial.print(cmd);
delay(2000);
//Serial.find("+IPD");
while (Serial.available())
{
char c = Serial.read();
mySerial.write(c);
if(c=='\r') mySerial.print('\n');
}
Serial.println("====");
delay(1000);
}
void loop(void)
{
Serial.print("Requesting temperatures...");
Serial.println("DONE");
//센서에서 읽어온 온도를 출력
printTemperature();
}
boolean connectWiFi()
{
//mySerial.println("AT+CWMODE=1");
String cmd="AT+CWJAP=\"";
cmd+=SSID;
cmd+="\",\"";
cmd+=PASSWORD;
cmd+="\"";
mySerial.println(cmd);
Serial.println(cmd);
delay(3000);
if(mySerial.find("OK"))
{
Serial.println("OK, Connected to WiFi.");
return true;
}
else
{
Serial.println("Can not connect to the WiFi.");
return false;
}
} -
학생2323 2019.08.21 17:46
아두이노 우도 보드가 아닌 아두이노 메가보드에서 진행중인데...
연결오류가 계속 뜨네요 ㅠㅠㅠ
위에서 말씀하신
#include <SoftwareSerial.h> 를 삭제하고
ESP8266 wifi (Serial1) 을 적어주고
Serial1로 사용하기는 하였으나 연결이 계속 커넥트 되지않는다라고 뜨네요 ㅠㅠ -
학생1111 2019.09.19 15:22
안녕하세요 선생님
제가 아두이노에서 rfid센서로 값을 받고
라즈베리파이 웹서버 mysql에 저장되어 있는 rfid 값을 입력받아 두 값을 비교해 일치하면 mysql 테이블에 값을 보내 수정하려고 합니다.
값을 받는것까지는 했는데
입력해주는건 막혔습니다.
제가 여기서 궁금한점은
if(mySerial.find(">")){
이 부분이 무슨 뜻인지는 알겠는데 여기서 막혀서 else로 넘어갑니다
어느 부분에서 > 가 출력이 되어서 찾는건지 알려주실 수 있으신가요?
그리고
SoftwareSerial Serial1(2, 3); // RX, TX
이렇게 설정해서 쓰는데
AT통신이 되는지 안되는지 확인하는 방법이 있을까요?
기존 0,1번 포트에 연결하면 시리얼 모니터에서 AT통신이 되는데 저렇게 바꾸면 되는지 안되는지 모르겠어요 -
-
코딩e 2019.10.22 00:42
선생님 안녕하세요. 이 글을 보고 따라하다보니 잘 작동합니다. 감사합니다 ^^ 마지막 단계에서 막힌게 있는데.. 현재 공유기 포트포워딩도 해주고 virtualbox 브릿지 설정도 잘 해줘서 공유기로는 다 db내 데이터에 접근이 가능한데(여러 공유기로 테스트 해보았습니다), 이상하게 휴대폰 핫스팟으로 연결하면 접근이 되지 않습니다. 혹시 어떤 문제일까요?
-
달달한피부 2019.10.31 22:20
php 문을
<?php
$db_host = "192.168.0.xx";
$db_user = "root";
$db_passwd = "xxxxx1995!";
$db_name = "test";
// MySQL - DB ����.
$con = mysqli_connect($db_host,$db_user,$db_passwd,$db_name);
if (mysqli_connect_errno()){
echo "MySQL ���� ���� : " , mysqli_connect_error();
exit;
} else {
echo "DB : \"$db_name\"�� ���� ����.<br/>";
$num=$_GET["num"];
$sql = "INSERT INTO sensor(time,value) VALUES(now(),$num)";
$result = mysqli_query($con, $sql);
mysqli_close($con);
}
?>
한 후 localhost/insert_data.php 실행 해보니
경고 : 패킷이 잘못되었습니다. 예상 0에서 1 패킷 크기 = 75을받은 C : \ XAMPP \ htdocs를 \ insert_data.php 라인에 9
경고 : mysqli_connect을 () : MySQL의 서버에서 사라 졌는지 C : \ XAMPP \ htdocs를 \ insert_data.php 라인에 9
경고 : mysqli_connect () : 인사말 패킷을 읽는 중 오류가 발생했습니다. 9 행의 C : \ xampp \ htdocs \ insert_data.php 에서 PID = 2224 경고 : mysqli_connect () : (HY000 / 2006) : MySQL 서버가 9 행의 C : \ xampp \ htdocs \ insert_data.php 에서 사라졌습니다 MySQL : MySQL 서버가 사라졌습니다
나옵니다 .. 뭐가 잘못된것일까요 ㅠㅠ?? -
WEBVISITOR 2019.11.01 02:48
"OneWire.h"를 위한 복수개의 라이브러리가 발견되었습니다
사용됨: C:\Users\달달한보자기\Documents\Arduino\libraries\OneWire
"DallasTemperature.h"를 위한 복수개의 라이브러리가 발견되었습니다
사용됨: C:\Users\달달한보자기\Documents\Arduino\libraries\dallas-temperature-control
"ESP8266.h"를 위한 복수개의 라이브러리가 발견되었습니다
사용됨: C:\Users\달달한보자기\Documents\Arduino\libraries\ITEADLIB_Arduino_WeeESP8266-master
"SoftwareSerial.h"를 위한 복수개의 라이브러리가 발견되었습니다
사용됨: C:\Users\달달한보자기\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SoftwareSerial
선생님 예제보면서 라이브러리를 추가시켰는데 이런 증상이 나옵니다 ㅠㅠ 어떻게 해결해야되는지 알려주실수 있으신가요?.. -
-
-
지나가는나그네 2020.03.04 10:14
선생님 블로그글 정말 감사합니다.
블로그 보다가 궁금한 점이 생겨서요.
아두이노에 조건을 달면 일정 온도 이상의 값만
데이터 전송 가능할까요? -
kim 2020.04.24 01:44
안녕하세요! 글 잘 읽고 있습니다
궁금한 점이 있어서 댓글 남깁니다!
제가 온도 센서 말고 DHT11 온습도 센서를 이용해보고 싶은데
온*습도, 이 2개의 data를 받아오려면 코드의 어느 부분을 수정해서 사용해야 할까요?
뭔가 어디를 수정해야겠다는 감이 조금 오기는 오는데 어떻게 고쳐야할지 모르겠습니다
-