Skip to content

Instantly share code, notes, and snippets.

@mokjpn
mokjpn / Espruino-BME280-WiFi-MQTT.js
Created September 13, 2015 08:37
Using Espruino board, obtain pressure/humidity/temperature data by BME280 sensor, then send it to MQTT server by ESP-WROOM-02(ESP8266) Wi-Fi module.
// Main
console.log("Start!");
// Espruinoのピンのうち, B8とB9ピンをI2C用として使う
I2C1.setup({scl:B8,sda:B9});
console.log("Initialize BME280...");
// BME280用モジュールを読み込んで初期化
var bme = require("BME280").connect(I2C1);
// MQTTサーバにつながるまではデータを送らないためのフラグ
var mqttconnected = false;
## modified from http://www.r-bloggers.com/how-to-download-complete-xml-records-from-pubmed-and-extract-data/
# Install XML and RCrul package and call library(XML) and library(RCurl) before use this.
searchPubMed <- function(query.term) {
# change spaces to + in query
query.gsub <- gsub(" ", "+", query.term)
# change single-quotes to URL-friendly %22
query.gsub <- gsub("'","%22", query.gsub)
# Perform search and save history, this will save PMIDS in history
pub.esearch <- getURL(paste("http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=",
serial = require('serialport')
mqtt = require 'mqtt'
SerialPort = serial.SerialPort
sp = new SerialPort("/dev/tty.usbserial-XXXXXXXX", { # replace this to your serial port name.
baudrate: 115200,
parser: serial.parsers.readline("\n")
})
atdesk = 0
@mokjpn
mokjpn / Konashi-Grove-Barometer
Last active August 29, 2015 14:13
Read Barometer from GROVE I2C Barometer Module.
( for name )
@mokjpn
mokjpn / Konashi-Grove-Temperature
Last active February 18, 2016 23:47
Read Temperature from GROVE analog Temperature Module.
(to name gist)
# plusMonth(time, diff)
# POSIXltに変換可能な型で与えられた日付を表すx に対して、diff月増減させた日付をPOSIXctで返す。
# 月だけを増減させ、日付はそのままにするので、検査スケジュールなどを扱うのに適しているか。
# diffは負でもよい。
plusMonth <- function(x, diff=1) { # diff を省略すると1としたことになる
cur <- as.POSIXlt(x)
mon <- cur$mon
cur$year <- cur$year + (mon+diff)%/% 12
cur$mon <- (mon+diff) %% 12
library(grDevices)
rsnake <- function(x=8,y=8, auto=NULL, plot=TRUE, detailed=FALSE) {
bodycheck <- function(newhead) {
if(newhead[1] < 1 || newhead[1] > x || newhead[2] < 1 || newhead[2] > y) return(FALSE)
return(sum(sapply(1:length(snake), function(x){identical(snake[[x]], newhead)})) == 0)
}
newfood <- function() {
while(!bodycheck(food <<- c(round(runif(1, min=1, max=x)), round(runif(1,min=1, max=y))))) FALSE