![]() |
放熱グリスでアルミ蓋に貼り付けてカプトンテープで固定。カプトンの意味ないですが。 |
ESP-WROOM-02にCMOSの温度センサーをつなぎ、単純なwait loopで1分ごとにデータ収集してみました。センサーはアナログ出力で8.2mV/Cなのですが、手を抜いて1/2に分圧してESP-WROOM-02のTOUTに入れているだけなので分解能低いです。ADC入力0-1023が2vに対応するので、約2mVが最小単位。約0.25度単位でしかデータを収集できません。ちゃんとオペアンプなどでレベルシフトし、ここ東京の気温域-5 〜 40度ぐらいがフルスケールになるようにすれば、0.05度ぐらいは計れるのですが(ノイズが)。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Time.h> | |
#include <ESP8266WiFi.h> | |
#include <WiFiClient.h> | |
extern "C" { | |
#include "user_interface.h" | |
} | |
// | |
// Wifi | |
// | |
const char *ssid = "*************"; | |
const char *password = "*************"; | |
WiFiClient client; | |
//int prevMinute; | |
void setup() { | |
Serial.begin(115200); | |
// | |
// Wifi | |
// | |
WiFi.begin ( ssid, password ); | |
Serial.println("Started"); | |
// Wait for connection | |
while ( WiFi.status() != WL_CONNECTED ) { | |
delay ( 500 ); | |
Serial.print ( "." ); | |
} | |
Serial.println("Wifi Connected"); | |
prevMinute = minute(); | |
} | |
void loop() { | |
if (prevMinute != minute()) { | |
sendTemperature(); | |
prevMinute = minute(); | |
} | |
delay(1000); | |
} | |
void sendTemperature() { | |
char buffer[20]; | |
float t = readTemperature(); | |
dtostrf(t, 2, 1, buffer); | |
Serial.println(buffer); | |
String postStr = "&field1=" + String(buffer); | |
send(postStr); | |
Serial.println(postStr); | |
} | |
void send(String inPostStr) { | |
String apiKey = "**********************"; | |
Serial.print("Connecting..."); | |
if (client.connect("184.106.153.149", 80)) { // api.thingspeak.com | |
Serial.print("Connected...."); | |
String postStr = apiKey + inPostStr + "\r\n\r\n"; | |
client.print("POST /update HTTP/1.1\n"); | |
client.print("Host: api.thingspeak.com\n"); | |
client.print("Connection: close\n"); | |
client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n"); | |
client.print("Content-Type: application/x-www-form-urlencoded\n"); | |
client.print("Content-Length: "); | |
client.print(postStr.length()); | |
client.print("\n\n"); | |
client.print(postStr); | |
Serial.println("posted."); | |
} | |
client.stop(); | |
} | |
float readTemperature() { | |
float v = system_adc_read() / 1.062000 * 2.00000; // mV | |
return 30.00000 - (v - 1474.000) / 8.2000000; | |
} | |
ということで、今度は「Deep Sleepで55秒休んでconnect〜送信したらすぐまた休む」方法を試そう! …と思ったら充電済のエネループがありませんでした。現在送っているデータは私の部屋の温度です。面白くもなんともないな。
追記:113時間持ちました。
強化版単3エネループに換算すると350時間。1ヶ月の道は遠いです。
とりあえずソースはこちら。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Time.h> | |
#include <ESP8266WiFi.h> | |
#include <WiFiClient.h> | |
extern "C" { | |
#include "user_interface.h" | |
} | |
// | |
// Wifi | |
// | |
const char *ssid = "***********"; | |
const char *password = "***********"; | |
WiFiClient client; | |
void setup() { | |
Serial.begin(115200); | |
// | |
// Wifi | |
// | |
WiFi.begin ( ssid, password ); | |
Serial.println("Started"); | |
// Wait for connection | |
while ( WiFi.status() != WL_CONNECTED ) { | |
delay ( 500 ); | |
Serial.print ( "." ); | |
} | |
Serial.println("Wifi Connected"); | |
sendTemperature(); | |
ESP.deepSleep(55*1000*1000, WAKE_RF_DISABLED); | |
delay(1000); | |
} | |
void loop() { | |
} | |
void sendTemperature() { | |
char buffer[20]; | |
float t = readTemperature(); | |
dtostrf(t, 2,1, buffer); | |
Serial.println(buffer); | |
String postStr = "&field1=" + String(buffer); | |
send(postStr); | |
Serial.println(postStr); | |
} | |
void send(String inPostStr) { | |
String apiKey = "**********************"; | |
Serial.print("Connecting..."); | |
if (client.connect("184.106.153.149", 80)) { // api.thingspeak.com | |
Serial.print("Connected...."); | |
String postStr = apiKey + inPostStr + "\r\n\r\n"; | |
client.print("POST /update HTTP/1.1\n"); | |
client.print("Host: api.thingspeak.com\n"); | |
client.print("Connection: close\n"); | |
client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n"); | |
client.print("Content-Type: application/x-www-form-urlencoded\n"); | |
client.print("Content-Length: "); | |
client.print(postStr.length()); | |
client.print("\n\n"); | |
client.print(postStr); | |
Serial.println("posted."); | |
} | |
client.stop(); | |
} | |
float readTemperature() { | |
float v = system_adc_read() / 1.062000 * 2.00000; // mV | |
return 30.00000 - (v - 1474.000) / 8.2000000; | |
} |
なお、某TareObjects社のBoard1基板ではRESETとIO16をハンダジャンパだけで簡単に接続することができるのでお薦めです(謎)。
今回100均で買ったジャム瓶に入れて風呂の湯温を計ったりしてみたんですが、やっぱり水漏れしますね。プラスチック+アルミ蓋なので、お湯で温まった時に空気が出て、冷えるとその分水を吸い込んでくる感じ。低電圧なので少し濡れたぐらいでは壊れたりしないのですが、やっぱ防水って難しいです。
詳細な製作記事はいずれまた。
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。