Author Topic: NodeMCU Network Temp Probe  (Read 930 times)

0 Members and 1 Guest are viewing this topic.

Offline paulcaTopic starter

  • Super Contributor
  • ***
  • Posts: 4031
  • Country: gb
NodeMCU Network Temp Probe
« on: January 13, 2018, 08:19:19 pm »
Well that was easy.

Dallas DS18B20.
Soldered a 4k7 across Data and Vcc
Female to female jumper leads
VCC to 3.3V
Data to D2
GND to... well GND
Heat shrink the Dallas sensor
USB wall wart.
Sprinkle some code.
VoilĂ  Wifi enabled temp probe.
Stuff it in a corner of a remote room.

Now I have this little set:
Quote

paul@localhost /mnt/hub_home/lcd_test/sh $ bash query.sh
BR:21.12:'C,AP:1014.4113:Hpa,AT:22.15:'C,DS:22.125:'C,OD:6.937:'C,HM:37.5819:%
BR:     21.12 'C
AP:     1014.4113 Hpa
AT:     22.15 'C
DS:     22.125 'C
OD:     6.937 'C
HM:     37.5819 %

BR is bedroom - the NodeMCU
DS is downstairs
OD outdoors (hanging out the window on an RJ45)
AP air pressure, HM humidity, AT aux_temp (provided by the pressure/humidity sensor)
All of the above from the living room PI3

Still sucks that the power supply costs more than the flipping NodeMCU.  Especially as I could only find a 2A Raspberry PI wall wart and they aren't cheap.

Code:
Code: [Select]
#include <OneWire.h>
#include <ESP8266WiFi.h>
#include <DallasTemperature.h>
#include <WiFiUdp.h>

// Put your wifi SID and password in a file of this name
// or uncomment and edit these
// const char* ssid = "mysid";
// const char* password = "mypassword";
#include "credentials.h"

#define ONE_WIRE_BUS D1

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);


void setup() {
  WiFi.begin(ssid, password);
  sensors.begin();
}

void loop() {
  sensors.requestTemperatures();

  double temp = sensors.getTempCByIndex(0);

  WiFiUDP Udp;
  Udp.beginPacket("10.0.0.3", 9999);  // host, port

  char data[255];
  memset(data, 0, 255);
  int len = snprintf(data, 255, "BR:%.2f:'C", temp);  // KEY:VALUE:UNIT

  Udp.write(data, len);
  Udp.endPacket();

  delay(5000);
}

EDIT:
References/credits:
http://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/udp-examples.html
https://github.com/esp8266/Arduino/issues/584  WTF? 
http://www.hobbytronics.co.uk/ds18b20-arduino
« Last Edit: January 13, 2018, 08:23:38 pm by paulca »
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 

Offline paulcaTopic starter

  • Super Contributor
  • ***
  • Posts: 4031
  • Country: gb
Re: NodeMCU Network Temp Probe
« Reply #1 on: January 13, 2018, 08:24:49 pm »
If you want to use it without a "hub" to receive the UDP you would be better off following the example in the link which uses the ESP8266 Webserver instead.
« Last Edit: January 13, 2018, 08:35:02 pm by paulca »
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf