ขึ้น error แนวทางการแก้ไขยังไงครับ ลอง return ค่ามาก็ไม่ได้ครับ
C:\Users\MIS02.AD\Documents\Arduino\project_\project_.ino: In function 'void loop()':
project_:131:12: error: too few arguments to function 'int sendHTTP(String)'
131 | sendHTTP();//String serverPath = serverName + "?sid=1&light=" + String(lx) + "&hum=" + String(h) + "×="+String(myString)+String(currentMonthName)+String(monthDay)+String(currentHour)+String(currentMinute)+String(currentSecond)+"&type=alert&key=18AD915D0";
| ^
C:\Users\MIS02.AD\Documents\Arduino\project_\project_.ino:215:5: note: declared here
215 | int sendHTTP(String ab){
| ^~~~~~~~
project_:136:12: error: too few arguments to function 'int sendHTTP(String)'
136 | sendHTTP();// String serverPath = serverName + "?sid=1&light=" + String(lx) + "&hum=" + String(h) + "×="+String(myString)+String(currentMonthName)+String(monthDay)+String(currentHour)+String(currentMinute)+String(currentSecond)+"&type=alert&key=18AD915D0";
| ^
C:\Users\MIS02.AD\Documents\Arduino\project_\project_.ino:215:5: note: declared here
215 | int sendHTTP(String ab){
| ^~~~~~~~
project_:143:11: error: too few arguments to function 'int sendHTTP(String)'
143 | sendHTTP();//String serverPath = serverName + "?sid=1&light=" + String(lx) + "&hum=" + String(h) + "×="+String(myString)+String(currentMonthName)+String(monthDay)+String(currentHour)+String(currentMinute)+String(currentSecond)+"&type=alert&key=18AD915D0";
| ^
C:\Users\MIS02.AD\Documents\Arduino\project_\project_.ino:215:5: note: declared here
215 | int sendHTTP(String ab){
| ^~~~~~~~
project_:148:16: error: too few arguments to function 'int sendHTTP(String)'
148 | sendHTTP();//sendHTTP(String ab)// String serverPath = serverName + "?sid=1&light=" + String(lx) + "&hum=" + String(h) + "×="+String(myString)+String(currentMonthName)+String(monthDay)+String(currentHour)+String(currentMinute)+String(currentSecond)+"&type=alert&key=18AD915D0";
| ^
C:\Users\MIS02.AD\Documents\Arduino\project_\project_.ino:215:5: note: declared here
215 | int sendHTTP(String ab){
| ^~~~~~~~
project_:174:21: error: too few arguments to function 'int sendHTTP(String)'
174 | sendHTTP();// String serverPath = serverName + "?sid=1&light=" + String(lx) + "&hum=" + String(h) + "×="+String(myString)+String(currentMonthName)+String(monthDay)+String(currentHour)+String(currentMinute)+String(currentSecond)+"&type=alert&key=18AD915D0";
| ^
C:\Users\MIS02.AD\Documents\Arduino\project_\project_.ino:215:5: note: declared here
215 | int sendHTTP(String ab){
| ^~~~~~~~
C:\Users\MIS02.AD\Documents\Arduino\project_\project_.ino: In function 'int sendHTTP(String)':
project_:251:5: error: return-statement with no value, in function returning 'int' [-fpermissive]
251 | return;
| ^~~~~~
project_:262:77: error: 'humi' cannot be used as a function
262 | int O = lux*humi(currentHour+currentMinute+currentSecond+yearint+monthint);
| ^
project_:271:14: error: redeclaration of 'String ab'
271 | String ab = String serverPath = serverName + "?sid=1&light=" + String(lx) + "&hum=" + String(h) + "×="+String(myString)+String(currentMonthName)+String(monthDay)+String(currentHour)+String(currentMinute)+String(currentSecond)+"&type=alert&key"+String(O);
| ^~
C:\Users\MIS02.AD\Documents\Arduino\project_\project_.ino:270:14: note: 'String ab' previously declared here
270 | String ab = "";
| ^~
project_:271:27: error: expected primary-expression before 'serverPath'
271 | String ab = String serverPath = serverName + "?sid=1&light=" + String(lx) + "&hum=" + String(h) + "×="+String(myString)+String(currentMonthName)+String(monthDay)+String(currentHour)+String(currentMinute)+String(currentSecond)+"&type=alert&key"+String(O);
| ^~~~~~~~~~
project_:273:26: error: 'serverPath' was not declared in this scope; did you mean 'serverName'?
273 | http.begin(client, serverPath.c_str());
| ^~~~~~~~~~
| serverName
project_:296:8: error: cannot convert 'String' to 'int' in return
296 | return ab;
| ^~
exit status 1
too few arguments to function 'int sendHTTP(String)'
โค้ดเพิ่มเติมครับ
#include <SimpleTimer.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
const char* ssid = "PCS-Office";
const char* password = "qawsedrf";
String serverName = "http://jaiangelbot.cc.pcs-plp.com/testbot/wtsensor.php";
unsigned long lastTime = 0;
unsigned long timerDelay = 5000;
/** date time */
#include "Wire.h"
#define DS3231_I2C_ADDRESS 0x68
/*************/
#include <Wire.h>
#include <BH1750FVI.h>
BH1750FVI LightSensor(BH1750FVI::k_DevModeContLowRes);
#include <TridentTD_LineNotify.h>
#include <Ticker.h>
unsigned long previousMillis = 0;
unsigned long previousMillisAlert = 0;
int alertsec = 0 , alertm = 0; //นับเวลาฉุกเฉิน หน่วง 10 นาที
int sec = 0, m = 0 , h = 0; //นับเวลาแจ้งเตือนไลน์
float setvalue[] = {300, 400, 500, 5}; //ค่า 1 2 ปกติ 3 และ 4ถ้าเริ่มน้อยแปลว่าให้เช็คเเละเริ่มแจ้งเตือนว่าเเสงน้อย (แสง)
Ticker ticker;
#define SSID "PCS-Office"
#define PASSWORD "qawsedrf"
#define LINE_TOKEN "KUdmGZVlBd5RS0vRZSjTJlQMT2fNgGJHAEs35KH9gOk"
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
int setvaluealert[] = {3, 7, 2, 15};
// Convert normal decimal numbers to binary coded decimal
#include <NTPClient.h>
#include <WiFiUdp.h>
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "jaiangelbot.cc.pcs-plp.com");
//Week Days
String weekDays[7] = {"01", "02", "03", "04", "05", "06", "07"};
//Month names
String months[12] = {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"};
SimpleTimer timer;
void setup() {
//timer.setInterval(1000, caltemp);
Serial.begin(115200);
LightSensor.begin();
//Serial.println(F("BH1750 Test begin"));
dht.begin();
Serial.println(LINE.getVersion());
InitWiFi();
/* WiFi.begin(SSID, PASSWORD);
Serial.printf("WiFi connecting ", SSID);
Wire.begin();
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(400);
}*/
Serial.printf("\nWiFi connected\nIP : ");
Serial.println(WiFi.localIP());
LINE.setToken(LINE_TOKEN);
timeClient.begin();
timeClient.setTimeOffset(25200);
}
void InitWiFi() {
WiFi.begin(SSID, PASSWORD);
Serial.printf("WiFi connecting ", SSID);
Wire.begin();
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(400);
}
Serial.printf("\nWiFi connected\nIP : ");
}
void loop() {
timer.run();
/************** date time เวลาประเทศไทยจาก server ******************** */
int a = 0;
int b = 0;
int c = 0;
unsigned long currentMillis = millis();
uint16_t lx = LightSensor.GetLightIntensity();
// float lx = lux*0.0079;
/* temp and humidity */
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
if (lx >= setvalue[0]) {
alertsec = alertm = previousMillisAlert = 0;
if (currentMillis - previousMillis >= 1000) {
// Serial.println("ค่าแสงตอนนี้: "+String(lx)+" W/m2");
//LINE.notify("ค่าแสงตอนนี้: "+String(lx)+" W/m2");
Serial.println("ค่าแสงตอนนี้: " + String(lx) + " " + String(sec) + "วิ");
// Serial.println((sec) +" วินาที");
sec++;
if (sec >= 60) {
m++;
Serial.println((m) + " นาที");
LINE.notify("ครบ" + String (m) + "นาที");
sendHTTP();//String serverPath = serverName + "?sid=1&light=" + String(lx) + "&hum=" + String(h) + "×="+String(myString)+String(currentMonthName)+String(monthDay)+String(currentHour)+String(currentMinute)+String(currentSecond)+"&type=alert&key=18AD915D0";
sec = 0;
}
if (m == 5) {
LINE.notify("ครั้งที่ 1 ตอน5นาที ค่าแสงตอนนี้: " + String(lx) + " W/m2");
sendHTTP();// String serverPath = serverName + "?sid=1&light=" + String(lx) + "&hum=" + String(h) + "×="+String(myString)+String(currentMonthName)+String(monthDay)+String(currentHour)+String(currentMinute)+String(currentSecond)+"&type=alert&key=18AD915D0";
m ++;
a = m;
h++; //นับ 15 นาที
}
else if (m == 10) { //ครบ 15 นาที
LINE.notify("ครั้งที่ 2 ตอน10นาที ค่าแสงตอนนี้: " + String(lx) + " W/m2");
sendHTTP();//String serverPath = serverName + "?sid=1&light=" + String(lx) + "&hum=" + String(h) + "×="+String(myString)+String(currentMonthName)+String(monthDay)+String(currentHour)+String(currentMinute)+String(currentSecond)+"&type=alert&key=18AD915D0";
m ++;
// Serial.print("ครั้งที่ 2 ตอน15นาที ค่าแสงตอนนี้: "+String(lx)+" W/m2");
h ++;
} else if (m == 15) { //ครบ 15 นาที
sendHTTP();//sendHTTP(String ab)// String serverPath = serverName + "?sid=1&light=" + String(lx) + "&hum=" + String(h) + "×="+String(myString)+String(currentMonthName)+String(monthDay)+String(currentHour)+String(currentMinute)+String(currentSecond)+"&type=alert&key=18AD915D0";
LINE.notify("ครั้งที่ 3 ตอน15นาที ค่าแสงตอนนี้: " + String(lx) + " W/m2");
m = 0;
}
previousMillis = currentMillis;
}
}
else {
unsigned long currentMillisAlert = millis();
if (lx <= setvaluealert[0]) {
if (currentMillisAlert - previousMillisAlert >= 1000) {
alertsec++;
Serial.print("alertsec: ");
Serial.println(alertsec);
if (alertsec >= 60) {
alertm++;
alertsec = 0;
Serial.print("alertm: ");
Serial.println(alertm);
}
if (alertm == 15) {
// LINE.notify("อันตราย!! ค่าแสงตอนนี้: "+String(lx)+" W/m2");
// Serial.print("อันตราย!! ค่าแสงตอนนี้: "+String(lx)+" W/m2");
alertm = 0;
h++;
if (h == 8) {
sendHTTP();// String serverPath = serverName + "?sid=1&light=" + String(lx) + "&hum=" + String(h) + "×="+String(myString)+String(currentMonthName)+String(monthDay)+String(currentHour)+String(currentMinute)+String(currentSecond)+"&type=alert&key=18AD915D0";
h = 0;
}
}
}
}
previousMillisAlert = currentMillisAlert;
}
}
/*
void readtimedate(){
timeClient.update();
time_t epochTime = timeClient.getEpochTime();
String formattedTime = timeClient.getFormattedTime();
int currentHour = timeClient.getHours();
int currentMinute = timeClient.getMinutes();
int currentSecond = timeClient.getSeconds();
String weekDay = weekDays[timeClient.getDay()];
//Get a time structure
struct tm *ptm = gmtime ((time_t *)&epochTime);
int monthDay = ptm->tm_mday;
int currentMonth = ptm->tm_mon+1;
String currentMonthName = months[currentMonth-1];
int currentYear = ptm->tm_year+1900;
String myString = String(currentYear);
String daye = (myString)+(currentMonthName)+(monthDay)+(currentHour)+(currentMinute)+(currentSecond);
int yearint = myString.toInt();
int monthint = currentMonthName.toInt();
int lux = (int)lx;
int humi = (int)h;
// String daye = (myString)+(currentMonthName)+(monthDay)+(currentHour)+(currentMinute)+(currentSecond);
int sumcal = humi * lux * (yearint + monthint + monthDay + currentHour + currentMinute + currentSecond) * 7;
if (int a > 1) {
a = sumcal;
}
}
void Sendhttp() {
}
*/
int sendHTTP(String ab){
timeClient.update();
time_t epochTime = timeClient.getEpochTime();
String formattedTime = timeClient.getFormattedTime();
int currentHour = timeClient.getHours();
int currentMinute = timeClient.getMinutes();
int currentSecond = timeClient.getSeconds();
String weekDay = weekDays[timeClient.getDay()];
//Get a time structure
struct tm *ptm = gmtime ((time_t *)&epochTime);
int monthDay = ptm->tm_mday;
int currentMonth = ptm->tm_mon+1;
String currentMonthName = months[currentMonth-1];
int currentYear = ptm->tm_year+1900;
String myString = String(currentYear);
int yearint = myString.toInt();
int monthint = currentMonthName.toInt();
/*
************* date time ********************
*/
/* sensor แสง */
uint16_t lx = LightSensor.GetLightIntensity();
// float lx = lux*0.0079;
/* temp and humidity */
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
int lux = (int)lx;
int humi = (int)h;
/*----------------------- จบ config sensor -----------------------------------*/
/** Key api **/
int O = lux*humi(currentHour+currentMinute+currentSecond+yearint+monthint);
/* จบ Key Api */
if ((millis() - lastTime) > timerDelay) {
//Check WiFi connection status
if (WiFi.status() == WL_CONNECTED) {
WiFiClient client;
HTTPClient http;
String ab = "";
String ab = String serverPath = serverName + "?sid=1&light=" + String(lx) + "&hum=" + String(h) + "×="+String(myString)+String(currentMonthName)+String(monthDay)+String(currentHour)+String(currentMinute)+String(currentSecond)+"&type=alert&key"+String(O);
// Your Domain name with URL path or IP address with path
http.begin(client, serverPath.c_str());
// Send HTTP GET request
int httpResponseCode = http.GET();
if (httpResponseCode > 0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println(payload);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
}
else {
Serial.println("WiFi Disconnected");
}
lastTime = millis();
}
return ;
}
PUYIOT
(อิทธิรงค์ ทองย้อย (ปุ๋ย))
3
ตัวอย่าง code ครับ
HTTPClient http;
String url = confgWeb
+ String(now_day) + "%20" + String(now_time) + "'&temperature='"
+ String(t) + "'&humidity='" + String(h) + "'&device='" + String(device)
+ "'";
http.begin(url); // HTTP Initial
int httpCode = http.GET(); // ทำการ GET Request ไปยัง Server String
delay(200);