/*
Sketch which publishes temperature data from a DS1820 sensor to a MQTT topic.
This sketch goes in deep sleep mode once the temperature has been sent to the MQTT
topic and wakes up periodically (configure SLEEP_DELAY_IN_SECONDS accordingly).
Hookup guide:
- connect D0 pin to RST pin in order to enable the ESP8266 to wake up periodically
- DS18B20:
+ connect VCC (3.3V) to the appropriate DS18B20 pin (VDD)
+ connect GND to the appopriate DS18B20 pin (GND)
+ connect D4 to the DS18B20 data pin (DQ)
+ connect a 4.7K resistor between DQ and VCC.
*/
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Streaming.h>
#define SLEEP_DELAY_IN_SECONDS 30
#define ONE_WIRE_BUS D4 // DS18B20 pin
const char* ssid = "<YOUR_WIFI_NETWORK>";
const char* password = "<YOUR_WIFI_PASSWORD>";
const char* mqtt_server = "<MQTT_BROKER_IP_ADDRESS>";
const char* mqtt_username = "<MQTT_BROKER_USERNAME>";
const char* mqtt_password = "<MQTT_BROKER_PASSWORD>";
const char* mqtt_topic = "sensors/test/temperature";
WiFiClient espClient;
PubSubClient client(espClient);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
char temperatureString[6];
void setup() {
// setup serial port
Serial.begin(115200);
// setup WiFi
setup_wifi();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
// setup OneWire bus
DS18B20.begin();
}
void setup_wifi() {
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println();
}
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
if (client.connect("ESP8266Client", mqtt_username, mqtt_password)) {
Serial.println("connected");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
float getTemperature() {
Serial << "Requesting DS18B20 temperature..." << endl;
float temp;
do {
DS18B20.requestTemperatures();
temp = DS18B20.getTempCByIndex(0);
delay(100);
} while (temp == 85.0 || temp == (-127.0));
return temp;
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
float temperature = getTemperature();
// convert temperature to a string with two digits before the comma and 2 digits for precision
dtostrf(temperature, 2, 2, temperatureString);
// send temperature to the serial console
Serial << "Sending temperature: " << temperatureString << endl;
// send temperature to the MQTT topic
client.publish(mqtt_topic, temperatureString);
Serial << "Closing MQTT connection..." << endl;
client.disconnect();
Serial << "Closing WiFi connection..." << endl;
WiFi.disconnect();
delay(100);
Serial << "Entering deep sleep mode for " << SLEEP_DELAY_IN_SECONDS << " seconds..." << endl;
ESP.deepSleep(SLEEP_DELAY_IN_SECONDS * 1000000, WAKE_RF_DEFAULT);
//ESP.deepSleep(10 * 1000, WAKE_NO_RFCAL);
delay(500); // wait for deep sleep to happen
}
/*
* Your Stylesheet
*
* This stylesheet is loaded when Atom starts up and is reloaded automatically
* when it is changed and saved.
*
* Add your own CSS or Less to fully customize Atom.
* If you are unfamiliar with Less, you can read more about it here:
* http://lesscss.org
*/
/*
* Examples
* (To see them, uncomment and save)
*/
// style the background color of the tree view
.tree-view {
// background-color: whitesmoke;
}
// style the background and foreground colors on the atom-text-editor-element itself
atom-text-editor {
// color: white;
// background-color: hsl(180, 24%, 12%);
}
// style UI elements inside atom-text-editor
atom-text-editor .cursor {
// border-color: red;
}
snippets.json
# snippets.json (not found)
snippets.cson
# Your snippets
#
# Atom snippets allow you to enter a simple prefix in the editor and hit tab to
# expand the prefix into a larger code block with templated values.
#
# You can create a new snippet in this file by typing "snip" and then hitting
# tab.
#
# An example CoffeeScript snippet to expand log to console.log:
#
# '.source.coffee':
# 'Console log':
# 'prefix': 'log'
# 'body': 'console.log $1'
#
# Each scope (e.g. '.source.coffee' above) can only be declared once.
#
# This file uses CoffeeScript Object Notation (CSON).
# If you are unfamiliar with CSON, you can read more about it in the
# Atom Flight Manual:
# http://flight-manual.atom.io/using-atom/sections/basic-customization/#_cson
".text.html":
"di":
"prefix": "di"
"body": '''
<!-- begin $1 -->
<div class="$1">
$2
</div>
<!-- end $1 -->
'''
# Your keymap
#
# Atom keymaps work similarly to style sheets. Just as style sheets use
# selectors to apply styles to elements, Atom keymaps use selectors to associate
# keystrokes with events in specific contexts. Unlike style sheets however,
# each selector can only be declared once.
#
# You can create a new keybinding in this file by typing "key" and then hitting
# tab.
#
# Here's an example taken from Atom's built-in keymap:
#
# 'atom-text-editor':
# 'enter': 'editor:newline'
#
# 'atom-workspace':
# 'ctrl-shift-p': 'core:move-up'
# 'ctrl-p': 'core:move-down'
#
# You can find more information about keymaps in these guides:
# * http://flight-manual.atom.io/using-atom/sections/basic-customization/#_customizing_keybindings
# * http://flight-manual.atom.io/behind-atom/sections/keymaps-in-depth/
#
# If you're having trouble with your keybindings not working, try the
# Keybinding Resolver: `Cmd+.` on macOS and `Ctrl+.` on other platforms. See the
# Debugging Guide for more information:
# * http://flight-manual.atom.io/hacking-atom/sections/debugging/#check-the-keybindings
#
# This file uses CoffeeScript Object Notation (CSON).
# If you are unfamiliar with CSON, you can read more about it in the
# Atom Flight Manual:
# http://flight-manual.atom.io/using-atom/sections/basic-customization/#_cson
'atom-workspace':
'cmd-shift-up': 'editor:move-line-up'
'cmd-shift-down': 'editor:move-line-down'
'atom-text-editor[data-grammar="source js jsx"]:not([mini])':
'tab': 'emmet:expand-abbreviation-with-tab'
'atom-workspace atom-pane':
'ctrl-alt--': 'user:insert-em-dash'
'.platform-win32 atom-text-editor':
'ctrl-alt-.': 'user:insert-elquo'
'alt-w': 'emmet:wrap-with-abbreviation'
'ctrl-shift-m': 'markdown-preview:toggle' # ХЗ отчего это не работает сразу...
'.platform-darwin atom-text-editor:not([mini])':
"shift-cmd-'": 'emmet:update-tag'
"shift-cmd-;": 'emmet:remove-tag'
'alt-w': 'emmet:wrap-with-abbreviation'
init.coffee
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
# console.log "Saved! #{editor.getPath()}"
_readme.md
# _readme.md (not found)
_atom.io
Настройки Atom. Синхронизация между несколькими устройствами.
Смотри плагин sync-settings, чтобы забрать себе все эти настройки. Или можно скачать эти файлы и заменить у себя в ~/.atom/
### Keybase proof
I hereby claim:
* I am kotp on github.
* I am kotp (https://keybase.io/kotp) on keybase.
* I have a public key ASAZ-2QjHxmrp0drjwUoaSzV7bXnawAQN94aXJuRAbsQpgo
To claim this, I am signing this object:
```json
{
"body": {
"key": {
"eldest_kid": "012019fb64231f19aba7476b8f0528692cd5edb5e76b001037de1a5c9b9101bb10a60a",
"host": "keybase.io",
"kid": "012019fb64231f19aba7476b8f0528692cd5edb5e76b001037de1a5c9b9101bb10a60a",
"uid": "5b7c67faedafe6d7b4085f3d372b9d00",
"username": "kotp"
},
"service": {
"name": "github",
"username": "kotp"
},
"type": "web_service_binding",
"version": 1
},
"client": {
"name": "keybase.io go client",
"version": "1.0.18"
},
"ctime": 1487185827,
"expire_in": 504576000,
"merkle_root": {
"ctime": 1487185808,
"hash": "daa6e21ac718801557b0ad29bb8151ba1d3bd0153bab58ad20d75fe5064f45575029e42893cf2f1778f0208b55eca4110926ed062baf7e340b50cd2efea88224",
"seqno": 893390
},
"prev": "3713244c275878cbd043e26183e854a6488fae268cbbe670025e09efaddff5a5",
"seqno": 18,
"tag": "signature"
}
```
with the key [ASAZ-2QjHxmrp0drjwUoaSzV7bXnawAQN94aXJuRAbsQpgo](https://keybase.io/kotp), yielding the signature:
```
hKRib2R5hqhkZ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NSIsInNlcW5vIjoxOCwidGFnIjoic2lnbmF0dXJlIn2jc2lnxEDGeOgSktBTVmnU/55YjgvoxIZVrGZwzRW2UWF+XtGRzYG1wYE7I3jXTGnEH3zCDSJN1NaCySW46blw5X/tYrgAqHNpZ190eXBlIKRoYXNogqR0eXBlCKV2YWx1ZcQg+1BCFHsQRkdoHodTin/EdzXO46t2BS2AVNXZ1ZeKanKjdGFnzQICp3ZlcnNpb24B
```
And finally, I am proving ownership of the github account by posting this as a gist.
### My publicly-auditable identity:
https://keybase.io/kotp
### From the command line:
Consider the [keybase command line program](https://keybase.io/download).
```bash
# look me up
keybase id kotp
```
# Hello world
"Hello world!" print
# Factorial
factorial := method(n, if(n == 1, 1, n * factorial(n - 1)))
99 bottles of beer
bottle := method(i,
if(i == 0, return "no more bottles")
if(i == 1, return "1 bottle")
return "" .. i .. " bottles"
)
for(i, 99, 1,
writeln(current, " of beer on the wall, ", current, " of beer,\n",
"take one down, pass it around,\n",
bottle(i - 1), " of beer on the wall.\n")
)
# Create a simple object and show how to use it
Account := Object clone
Account balance := 0
Account deposit := method(v, balance = balance + v)
Account withdraw := method(v, balance = balance - v)
Account show := method(
writeln("Account balance: $", balance)
)
myAccount := Account clone
myAccount show
"Depositing $10\n" print
myAccount deposit(10)
myAccount show
# Concurrency example - the following will print "112233"
o1 := Object clone
o1 test := method(for(n, 1, 3, n print; yield))
o2 := o1 clone
// @ means send an asynchronous message
o1 @test; o2 @test
// wait for the messages to get processed
while(Scheduler activeActorCount > 1, yield)
# Look up a class/prototype given its name as a string
Lobby getSlot("PrototypeName")
# Execute a method given its name as a string
anObject perform("SomeMethodName", arg1, arg2)
# Find out if a method with a given name (again a string) exists
anObject hasSlot("SomeMethodName")
# Given an arbitrary reference to a class/prototype, instantiate it
newInstance := objectRef clone
# Add a method to a primitive
Number double := method(self * 2)
1 double
==> 2
# Subclass a primitive
MyList := List clone // Same as creating an instance
# Iterate through an inheritance hierarchy
Object printAllSlots := method(
self slotNames foreach(i, slotName,
writeln(slotName)
if(self hasSlot("proto"), self proto printAllSlots
)
)
Object printAllSlots
# Implement a generic proxy
Proxy = Object clone
Proxy forward := method(
methodName := thisMessage name
args := thisMessage argsEvaluatedIn(sender)
// When an unrecognized message is received,
// this method will be invoked.
// Do what you like with the message here -
// such as send it over a network, etc.
)
# Implement a singleton
Foo := Object clone
Foo clone := Foo
# Print the source code of a method
myMethod := method(return testing(1+2+3))
getSlot("myMethod") code print
==> "return(testing(1+(2)+(3)))"
# Add an operator method to an object
MyObject := Object clone
MyObject setSlot("+", method(n, write("adding ", n, "\n")))
MyObject + 123
==> "adding 123"
# Mixins and Aspects
a := Object clone
Mix := Object clone
Mix logData := Buffer clone
Mix init := method(logData = logData clone)
Mix log := method(s, logData append(s))
a parent := Mix clone // Now a also inherits the state and behavior of Mix
b := Object clone
b parent := Mix clone // Now multiple objects use it so it's an "aspect"
# An auto source file importer
Object searchPaths = List clone add(launchPath)
Object forward := method(
methodName := thisMessage name
if (methodName characterAt(0) isUpperCase,
searchPaths foreach(i, searchPath,
fileName := searchPath appendPath(methodName .. ".io")
sourceFile := File clone setPath(fileName)
if (sourceFile exists) then (
Lobby doFile(path)
return Lobby getSlot(methodName)
)
)
)
raiseException("Importer", "Could not find slot for " .. methodName)
)
# A simple whois client
whois := method(host,
socket := Socket clone setHostName("rs.internic.net") setPort(43)
socket connect write(host, "\n")
while(socket readNextChunk, nil) // socket read auto yields to other coroutines
return socket readBuffer
)
# An echo server
Echo := Object clone
Echo handleSocket := method(socket,
while(socket isOpen,
if(socket read, socket write(socket readBuffer))
socket readBuffer empty
)
)
EchoServer := Server clone setPort(8456)
EchoServer handleSocket := method(socket,
Echo clone @handleSocket(socket)
// async message so it's handled in separate coroutine
)
EchoServer start
The live website API (which has a live link to the website platform) makes the full power of the award-winning Rijksmuseum website directly accessible to a large group of developers. Searching the collection is one activity that offers a wide range of interesting options. The same is true of the “explore the collection” pages, the Rijksstudio users’ collections, and the tiled images used to zoom in to tight close-ups of works of art. Calendar information is also available, for example. The JSON-based service is so simple that, in no time at all, you can build something that makes use of the Rijksmuseum’s rich and attractive content.
The Rijksmuseum API (Application Programming Interface) is a new, state-of-the-art service for application developers. The Rijksmuseum offers the API to make its collection (as well as other content and high resolution images) available for use in apps or web applications, for example.
http://rijksmuseum.github.io/