Things used in this project

Hardware components:
D1 mini
Everything ESP Wemos D1 Mini
×1
ds18b20 (temperature sensor)
×1
12002 04
Breadboard (generic)
×1
11026 02
Jumper wires (generic)
×1
Software apps and online services:
DFRobot upycraft IDE
micropython
Cayenne logo hi
myDevices Cayenne

Schematics

wemos ds18b20
Wemosds18b20 xtbvz6dx5q

Code

dstemp.pyPython
code to test the temperature sensor
import time
import machine
import ds18x20
import onewire

# the device is on GPIO12
dat = machine.Pin(12)

# create the onewire object
ds = ds18x20.DS18X20(onewire.OneWire(dat))

# scan for devices on the bus
roms = ds.scan()
print('found devices:', roms)

# loop 10 times and print all temperatures
while True:
    print('temperatures:', end=' ')
    ds.convert_temp()
    time.sleep_ms(750)
    for rom in roms:
        print(ds.read_temp(rom), end=' ')
    print()
cayennetemp.pyPython
code to send your temperature data to the cayenne service
from umqtt.simple import MQTTClient
from machine import Pin
import network
import time
import ds18x20
import onewire

# the device is on GPIO12
dat =Pin(12)
# create the onewire object
ds = ds18x20.DS18X20(onewire.OneWire(dat))
# scan for devices on the bus
roms = ds.scan()
print('found devices:', roms)

#wifi setting
SSID=" " #insert your wifi ssid
PASSWORD=" " #insert your wifi password

SERVER = "mqtt.mydevices.com"
CLIENT_ID = " " #insert your client ID
username=' ' #insert your MQTT username
password=' ' #insert your MQTT password
TOPIC = ("v1/%s/things/%s/data/1" % (username, CLIENT_ID))

def connectWifi(ssid,passwd):
  global wlan
  wlan=network.WLAN(network.STA_IF)
  wlan.active(True)
  wlan.disconnect()
  wlan.connect(ssid,passwd)
  while(wlan.ifconfig()[0]=='0.0.0.0'):
    time.sleep(1)
    
connectWifi(SSID,PASSWORD)
server=SERVER
c = MQTTClient(CLIENT_ID, server,0,username,password)
c.connect()

def senddata():
  ds.convert_temp()
  time.sleep_ms(100)
  temp = ds.read_temp(roms[0])
  c.publish(TOPIC, str(temp))

  time.sleep(10)
  print("temperature is: ", temp)
  print("data sent")
  
while True:
	try:
		senddata()
	except OSError:
		pass

Credits

Hendra presentasi
Hendra Kusumah
10 projects • 45 followers
Love hacking and making new things from IoT to robotics
Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaBlog