lsc0523 / cafe_monitoring_system

0 stars 2 forks source link

아두이노 스케치 문제 #8

Open Macsim2 opened 5 years ago

Macsim2 commented 5 years ago

각 센서를 연결한 nodemcu에 아두이노 스케치 코드를 포팅한 상태에서 usb 연결선을 컴퓨터와 분리하기 전까지는 잘되는데 분리한 후에는 nodemcu 작동을 하지 않습니다. 무슨 문제 일까요?ㅠㅠ 아래는 아두이노 스케치 코드입니다. `#include

include

include

include

include

include

include "iAQcore.h"

OneWire ourWire(D5); DallasTemperature sensor(&ourWire); login login1; const char host = login1.gethost(); String url = "/sensors?"; const int httpPort = 3000; const char ssid = login1.getid(); // Your own ssid here const char* password = login1.getpw(); // Your own password here

iAQcore iaqcore; int SOUND_SENSOR = D3; int threshold = 25; //감도조절 int Sensor_value;

String working() { /***** Temperature Sensor **/ sensor.requestTemperatures(); float temper = sensor.getTempCByIndex(0); Serial.print("temper: "); Serial.println(temper);

/*** Air Quality Sensor ****/ uint16_t eco2; uint16_t stat; uint32_t resist; uint16_t etvoc; iaqcore.read(&eco2,&stat,&resist,&etvoc);

Serial.print("iAQcore: "); Serial.print("eco2="); Serial.print(eco2); Serial.print(" ppm, "); Serial.print("stat=0x"); Serial.print(stat,HEX); Serial.print(", "); Serial.print("resist="); Serial.print(resist); Serial.print(" ohm, "); Serial.print("tvoc="); Serial.print(etvoc); Serial.print(" ppb"); Serial.println();

/** Volume Sensor **/ Sensor_value = analogRead(D3); // Analog PIN D8에서 입력값을 읽어와서 Sensor_value에 저장 Serial.print("volume value: "); Serial.println(Sensor_value); // 시리얼모니터에 감도표시 Serial.println("");

return(String("temper=") + String(temper)+ "&"

void delivering(String payload) { WiFiClient client; Serial.print("connecting to "); Serial.println(host); if (!client.connect(host, httpPort)) { Serial.print("connection failed: "); client.print("failed!\n"); Serial.println(payload); return; }

/ send to database 'mydb' through my ubuntu server/ String getheader = "GET "+ String(url) +"&"+ String(payload) +" HTTP/1.1"; client.println(getheader); client.println("User-Agent: ESP8266 ChanYang Sim");
client.println("Host: " + String(host));
client.println("Connection: close");
client.println();

//Serial.println(getheader); /while (client.connected()) { String line = client.readStringUntil('\n'); Serial.println(line); }/ Serial.println("Done cycle."); }

void connect_wifi() { Serial.println(); Serial.print("connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.print("\n Got WiFi, IP address: "); Serial.println(WiFi.localIP());
}

void setup() { / Serial setup / Serial.begin(115200);

/ sound / Serial.println("Set up...."); pinMode(SOUND_SENSOR, INPUT); / AQ setup / Wire.begin(/SDA/D2,/SCL/D1); Wire.setClockStretchLimit(1000); // Default is 230us, see line78 of https://github.com/esp8266/Arduino/blob/master/cores/esp8266/core_esp8266_si2c.c // Enable iAQ-Core iaqcore.begin(); connect_wifi();

}

void loop() { String payload = working(); delivering(payload); delay(10000);

}`