Skip to content

206 UV Index

206をI2Cの端子につなぎます。

ソースコード

index.html

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<body>
UV INDEX: %UVINDEX%<br>
IR: %IR%<br>
VISIBLE: %VISIBLE%<br>
</body>
</html>

Arduino

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "WiFi.h"
#include "ESPAsyncWebServer.h"
#include "FS.h"
#include "SPIFFS.h"
#include "FaBoUV_Si1132.h"

FaBoUV faboUV;

const char ssid[] = "ESP32AP-AKIRA";
const char pass[] = "11111111";
const IPAddress ip(192,168,0,1);
const IPAddress subnet(255,255,255,0);
AsyncWebServer server(80);

double uvindex = 0;
double ir = 0;
double visible = 0;

String processor(const String& var)
{
  if(var == "UVINDEX") {
    return String(uvindex, DEC);
  }
  if(var == "IR") {
    return String(ir, DEC);
  }
  if(var == "VISIBLE") {
    return String(visible, DEC);
  }
  return String();
}

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

  while(!faboUV.begin()){
    Serial.println("Si1132 Not Found");
    delay(5000);
  }

  SPIFFS.begin();
  WiFi.softAP(ssid,pass);
  delay(100);
  WiFi.softAPConfig(ip,ip,subnet);
  IPAddress serverIP = WiFi.softAPIP();
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send(SPIFFS, "/index.html", String(), false, processor);
  });  
  server.begin();

  Serial.println();
  Serial.print("AccessPoint:");
  Serial.println(ssid);
  Serial.print("IP:");
  Serial.println(serverIP);
}

void loop() {
  uvindex = faboUV.readUV()/100;
  ir = faboUV.readIR();
  visible = faboUV.readVisible();

  Serial.print("UV:");
  Serial.println(uvindex);
  Serial.print("IR:");
  Serial.println(ir);
  Serial.print("Visible:");
  Serial.println(visible);
  Serial.println("");  

  delay(1000);
}

改造

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Refresh" content="3">
<meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<body>
UV INDEX: %UVINDEX%<br>
IR: %IR%<br>
VISIBLE: %VISIBLE%<br>
</body>
</html>