Skip to content

Commit 2a3b511

Browse files
committed
Merge branch 'tempmeter'
2 parents 773da60 + d7f5034 commit 2a3b511

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

Arduino/WeatherDisplay/WeatherDisplay.ino

+30-22
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,32 @@
1111
#include <ESP8266WiFi.h>
1212
#include <ESP8266HTTPClient.h>
1313

14-
#include <time.h>
14+
#include <Ambient.h>
15+
#include <DHT.h>
16+
1517
// Please enter your sensitive data in the Secret tab or arduino_secrets.h(SECRET_xxxx defines)
1618
#include "arduino_secret.h"
1719

18-
#define JST 9*3600
19-
#define USER_DATA_ADDR 66
20+
// Uncomment the type of sensor in use:
21+
//#define DHTTYPE DHT11 // DHT 11
22+
#define DHTTYPE DHT22 // DHT 22 (AM2302)
23+
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
24+
25+
#define DHTPIN D3
2026

2127
// for SPI pin definitions see e.g.:
2228
// C:\Users\xxx\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic\common.h
2329

24-
GxIO_Class io(SPI, /*CS=D8*/ D8, /*DC=D3*/ D3, /*RST=D4*/ D4); // arbitrary selection of D3(=0), D4(=2), selected for default of GxEPD_Class
25-
GxEPD_Class display(io, /*RST=D4*/ D4, /*BUSY=D2*/ D2); // default selection of D4(=2), D2(=4)
30+
GxIO_Class io(SPI, /*CS=D8*/ D8, /*DC=D3*/ D4, /*RST=D4*/ D2); // arbitrary selection of D3(=0), D4(=2), selected for default of GxEPD_Class
31+
GxEPD_Class display(io, /*RST=D4*/ D2, /*BUSY=D2*/ D1); // default selection of D4(=2), D2(=4)
2632
HTTPClient client;
2733
BearSSL::WiFiClientSecure secure;
34+
Ambient ambient;
35+
WiFiClient ambientClient;
36+
DHT dht(DHTPIN, DHTTYPE);
2837

2938
const uint32_t getWeatherInfoPeriod = 10 * 60 * 1000;
30-
const uint32_t getCurrentTempPeriod = 10 * 60 * 1000;
39+
const uint32_t getCurrentTempPeriod = 1 * 60 * 1000;
3140

3241
struct {
3342
uint64_t getWeatherInfoJpeg;
@@ -40,7 +49,6 @@ void setup()
4049
Serial.begin(74880);
4150
Serial.println();
4251
Serial.println("setup");
43-
4452
display.init(74880); // enable diagnostic output on Serial
4553

4654
WiFi.begin(SECRET_SSID, SECRET_SSID_PASSWORD);
@@ -56,13 +64,8 @@ void setup()
5664
Serial.println(WiFi.localIP());
5765
secure.setInsecure();
5866

59-
// Serial.print("Time syncing");
60-
// configTzTime("JST-9", "ntp.nict.jp", "ntp.jst.mfeed.ad.jp");
61-
// while (time(NULL) <= 100000){
62-
// delay(500);
63-
// Serial.print(".");
64-
// }
65-
// Serial.println("done");
67+
ambient.begin(SECRET_AMBIENT_CHANNEL, SECRET_AMBIENT_WRITE, &ambientClient);
68+
dht.begin();
6669

6770
Serial.println("Init data");
6871
lastExecDate.getCurrentTemp = 0;
@@ -73,9 +76,6 @@ void setup()
7376

7477
void loop()
7578
{
76-
// time_t now = time(NULL);
77-
// tm *tm = localtime(&now);
78-
// Serial.printf("Now: %02d/%02d %02d:%02d:%02d\n", tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
7979
uint32_t now = millis();
8080

8181
if(now < lastExecDate.getCurrentTemp || now < lastExecDate.getWeatherInfoJpeg ){
@@ -92,14 +92,10 @@ void loop()
9292
}
9393
if (lastExecDate.getCurrentTemp == 0 || now - lastExecDate.getCurrentTemp > getCurrentTempPeriod)
9494
{
95-
//TODO: 現在の気温を取得する
9695
Serial.println("getCurrentTemp()");
96+
getCurrentTemp();
9797
lastExecDate.getCurrentTemp = now;
9898
}
99-
// 最終実行日時を保存
100-
// ESP.rtcUserMemoryWrite(USER_DATA_ADDR, (uint32_t *)&lastExecDate, sizeof(lastExecDate));
101-
102-
// delay(1000);
10399
}
104100

105101
void getWeatherInfoJpeg(){
@@ -131,4 +127,16 @@ httpaccess:
131127
delay(1000 * 10);
132128
goto httpaccess;
133129
}
130+
}
131+
132+
void getCurrentTemp()
133+
{
134+
float t = dht.readTemperature();
135+
float h = dht.readHumidity();
136+
137+
Serial.printf("temp:%f, humi:%f\n", t, h);
138+
139+
ambient.set(1, t);
140+
ambient.set(2, h);
141+
ambient.send();
134142
}

0 commit comments

Comments
 (0)