DEV Community

Komsan Nurak
Komsan Nurak

Posted on

1

ESP32 WiFiManager and ArduinoJson 7

#include <WiFi.h>
#include <WiFiManager.h>
#include <ArduinoJson.h>

// ตั้งค่า WiFiManager
WiFiManager wm;

// ตั้งค่า JSON document
StaticJsonDocument<200> doc;

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

  // รีเซ็ตการตั้งค่า WiFi เมื่อกดปุ่มรีเซ็ตนาน 3 วินาที
  wm.resetSettings();

  bool res = wm.autoConnect("ESP32-AP");

  if (!res) {
    Serial.println("Failed to connect");
    // ไม่สามารถเชื่อมต่อ WiFi ให้เข้าสู่โหมด Deep Sleep
  } else {
    Serial.println("Connected to WiFi");
  }

  // เพิ่มข้อมูลลงใน JSON document
  doc["sensor"] = "BME280";
  doc["data"][0] = 24.5;
  doc["data"][1] = 65.2;

  // สร้าง JSON string จาก JSON document
  String output;
  serializeJson(doc, output);
  Serial.println(output);
}

void loop() {
  // ไม่มีการทำงานอื่นในลูป
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay