0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ESP8266にDS18B20を4つつないでAmbientに送る

Posted at

ESP8266のDeepSleep利用
秋月「Wi-Fiモジュール ESP-WROOM-02 DIP化キット」
エネループ2本でとりあえず動く
5分おき計測・送信でどのくらい持つのか実測予定
DS18B20はAmazonのHiLetgo社防水加工、コード付き5本で1000円くらいを利用
セットの5本にて上下1℃程の差あり

ソース


# include <OneWire.h>
# include <DallasTemperature.h>
# include <Ambient.h>

//-----------------------------------------------
const char* ssid = "  ---SSID----  ";
const char* password = "  ----LAN Pass----  ";
unsigned int channelID =  ----Ambient channel id---- ;
const char* writeKey = "  ----Ambient write key----  ";
float temp01;  //センサー4つ
float temp02;
float temp03;
float temp04;


//-----------------------------------------------

//WiFi
WiFiClient client;

//OneWire&DS18B20
# define ONE_WIRE_BUS 4 //センサー接続は4番利用
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

//Ambient
Ambient ambient;

//-----------------------------------------------


void setup() {
  
  //Check用。運用時はコメントアウト
  //Serial.begin(115200);
  //Serial.println("");
  //Serial.println("Start");
  
  WiFi.begin(ssid, password);
  ambient.begin(channelID, writeKey, &client);

  sensors.begin();
  
  //センサーのシリアル番号は利用しない。握って温度変化みて特定(原始的)
  sensors.requestTemperatures();
  temp01 = sensors.getTempCByIndex(0);
  temp02 = sensors.getTempCByIndex(1);
  temp03 = sensors.getTempCByIndex(2);
  temp04 = sensors.getTempCByIndex(3);
  
  ambient.set(1,temp01);
  ambient.set(2,temp02);
  ambient.set(3,temp03);
  ambient.set(4,temp04);
  
  ambient.send();
  delay(1000*3);  //このdelayがないとスリープから復帰しない。3秒も必要かどうか不明。理由不明。
  
  //Serial.println(temp01);  //check用。普段コメントアウト
  ESP.deepSleep(5*60*1000*1000);  //μ秒指定 5分
  delay(1000*1);

}

void loop() {
  // DeepSleepから覚めたらsetup()から動くみたいなので、すべてsetup()で完結させた

}

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?