ช่วยด้วยครับทำ เครื่องวัดอุณหภูมิ และ ความชื้นผ่าน Blynk แต่หา Esp32 ผ่านwifi ไม่เจอครับ

#include "iotree_board_beta.h"
#define BLYNK_PRINT Serial
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
//#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

char auth[] = "6WqT3cZ6j9dPZ9JCi6sf1GJ6vNB5sCNj"; //อย่าลืมแก้ไข TOKEN*****************************************************************
char ssid[] = "OPPO"; // อย่าลืมแก้ไข ssid **********************************************************
char pass[] = "034612220"; // อย่าลืมแก้ไข password*********************************************************

void sendSensor() {
 float h = dht.readHumidity();
 float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
 int ss = moist_read();
 //int ss = map(s, 3760, 1300, 0, 100);
 double value_flow = water_flow_read(); 

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  Blynk.virtualWrite(V33, h);
  Blynk.virtualWrite(V32, t);
  Blynk.virtualWrite(V35, ss);
  Blynk.virtualWrite(V34, value_flow);
}

BLYNK_WRITE(V0){ //LED
  WidgetLED ledon(V5);
  WidgetLED ledoff(V6);
  int pinValueB = param.asInt(); // assigning incoming value from pin V1 to a variable
  if(pinValueB == HIGH)
  {
      ledcWrite(1, 500);
      ledon.on();
      ledoff.off();
  }
  else {
      ledcWrite(1, 0);
      ledon.off();
      ledoff.on();
  }
}

BLYNK_WRITE(V1){ //Fan
  int pinValueC = param.asInt(); 
  WidgetLED ledfanon(V7);
  WidgetLED ledfanoff(V8);
  if(pinValueC == HIGH)
  {
      fan_write(1024);
      ledfanon.on();
      ledfanoff.off();
  }
  else {
     fan_write(0);
     ledfanon.off();
     ledfanoff.on();
  }
}

BLYNK_WRITE(V2){ //PUMP
  int pinValueD = param.asInt();
  WidgetLED ledpumpon(V9);
  WidgetLED ledpumpoff(V10);
  if(pinValueD == HIGH)
  {
    pump_write(128);
    ledpumpon.on();
    ledpumpoff.off();
  }
  else {
   pump_write(0);
   ledpumpon.off();
   ledpumpoff.on();
  }
}

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

  // initialize display
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever
  }

  display.clearDisplay();
  display.drawBitmap(
    (display.width()  - IOTree_LOGO_WIDTH ) / 2,
    (display.height() - IOTree_LOGO_HEIGHT) / 2,
    IOTree_logo_bmp, IOTree_LOGO_WIDTH, IOTree_LOGO_HEIGHT, 1);
  display.display();
  delay(1000);
  display.setTextSize(1); // Draw 2X-scale text
  display.setTextColor(SSD1306_WHITE);
  
  Blynk.begin(auth,ssid,pass,"122.154.241.138",9443);
  hardware_init();
  dht.begin();
}

void loop() {
  Blynk.run();
  sendSensor();
  delay(100);
}


มันขึ้นออนไลน์ไหมครับ

1 Like


ขึ้นแบบนี้ครับท่าน

ใช้ port 8080 ครับ 9443 สำหรับ แอพ