-
Notifications
You must be signed in to change notification settings - Fork 9
/
experiment30.js
45 lines (40 loc) · 1.03 KB
/
experiment30.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var WIFI_NAME = "";
var WIFI_KEY = "";
var wifi;
// This code is for Espruino Pico + ESP8266
function onInit() {
USB.setConsole(true);
Serial1.setup(115200, { tx: B6, rx : B7 });
wifi = require("ESP8266WiFi_0v25").connect(Serial1, function(err) {
if (err) throw err;
console.log("Connecting to WiFi");
wifi.connect(WIFI_NAME, WIFI_KEY, function(err) {
if (err) throw err;
onConnected();
});
});
}
/*
// For Espruino WiFi, use the following code
function onInit() {
wifi = require("EspruinoWiFi");
console.log("Connecting to WiFi");
wifi.connect(WIFI_NAME, { password : WIFI_KEY }, function(err) {
if (err) {
console.log("Connection error: "+err);
return;
}
onConnected();
});
}
*/
function onConnected() {
console.log("Connected");
setInterval(sendDweet, 10000);
}
function sendDweet() {
var str = E.getTemperature().toFixed(2);
console.log("Sending "+str);
var url = "http://dweet.io/dweet/for/espruino_tmp?temp="+str;
require("http").get(url, function(res) { });
}