Skip to content

Instantly share code, notes, and snippets.

@c4r-gists
c4r-gists / main.cpp
Last active April 12, 2021 19:38
Connecting a DHT11 sensor to the cloud with an ESP8266-based board
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <Cloud4RPi.h>
#include "DHT.h"
#ifndef LED_BUILTIN
#define LED_BUILTIN 2
#endif
#define DHTPIN 2 // Digital pin connected to the DHT sensor
@c4r-gists
c4r-gists / service_install.sh
Last active August 29, 2019 14:57
Cloud4RRi service installation script for Debian-based systems (http://docs.cloud4rpi.io/start/rpi/#installing-as-a-service)
#!/bin/bash
readonly PYTHON_PATH=/usr/bin/python3
readonly SERVICE_NAME=cloud4rpi
quit_on_error() {
test "0" = $? || {
exit 1
}
}
@c4r-gists
c4r-gists / coffee-pump.py
Created March 15, 2019 12:29
Water level control on RaspberryPi using HCSR04 sensor
import sys
import traceback
import time
import json
from urllib.request import Request, urlopen
from urllib.error import URLError, HTTPError
import RPi.GPIO as GPIO
import cloud4rpi
from hcsr04sensor import sensor
@c4r-gists
c4r-gists / ds18b20.py
Created July 20, 2018 12:15
DS18B20-Fahrenheit
# -*- coding: utf-8 -*-
# The DS18B20 sensor should be connected as follows:
#
# / GND |────────────> GND
# | DATA |─────────┬──> GPIO4
# \ VCC |─┬─[4k7]─┘
# └──────────> 5V
# DS18B20 (bottom view)
#
@c4r-gists
c4r-gists / main.cpp
Created February 19, 2018 12:44
pio-nodeMCU-MQTT
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <Cloud4RPi.h>
const String deviceToken = "__YOUR__DEVICE_TOKEN__";
char wifiSSID[] = "__SSID__";
char wifiPassword[] = "__PASSWORD__";
void ensureWiFiConnection();
# -*- coding: utf-8 -*-
from time import sleep
from socket import gethostname
import cloud4rpi
# Put your device token here. To get the token,
# sign up at https://cloud4rpi.io and create a device.
DEVICE_TOKEN = '__YOUR_DEVICE_TOKEN__'
@c4r-gists
c4r-gists / minimal.py
Last active February 7, 2018 11:30
Minimal example of Cloud4RPi client library usage on python
# -*- coding: utf-8 -*-
from time import sleep
import sys
import cloud4rpi
# these functions will be called by device when sending data
def room_temp():
return 25
@c4r-gists
c4r-gists / DHT22.py
Last active February 7, 2018 11:25
How to send temperature and humidity using DHT22(11) sensor
# -*- coding: utf-8 -*-
import sys
import time
import cloud4rpi
import rpi
import Adafruit_DHT
# Put your device token here. To get the token,
# sign up at https://cloud4rpi.io and create a device.