Skip to content

Instantly share code, notes, and snippets.

@insom
Created December 20, 2016 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save insom/b80b13f20cc7ff6ca992f540ed288be5 to your computer and use it in GitHub Desktop.
Save insom/b80b13f20cc7ff6ca992f540ed288be5 to your computer and use it in GitHub Desktop.
Micropython Temperature Logger
import gc
import webrepl
from machine import Pin, I2C
from bme280 import BME280
from socket import socket, AF_INET, SOCK_DGRAM
from time import sleep
webrepl.start()
gc.collect()
bus = I2C(scl=Pin(5), sda=Pin(4), freq=100000)
b = BME280(i2c=bus)
s = socket(AF_INET, SOCK_DGRAM)
s.connect(('192.168.0.1', 5555))
while True:
s.send(b.values[0])
sleep(5)
require 'socket'
ss = TCPSocket.new('127.0.0.1', 2003)
us = UDPSocket.new
us.bind('0.0.0.0', 5555)
while x = us.recvfrom(100)[0]
next if x.empty?
right = x.split('C').first
p ("mobile.bme280 #{ right } #{ Time.now.utc.to_i }\n")
ss.write("mobile.bme280 #{ right } #{ Time.now.utc.to_i }\n")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment