in progress…
https://github.com/G1Tech/youTubeStream/blob/master/prometheus-bme280-v2.ino
Add your new user to the sudo group
sudo usermod -aG sudo g1
Update the apt package index & Upgrade all current program package
sudo apt-get update
sudo apt-get upgrade
Install packages to allow apt to use a repository over HTTPS:
sudo apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common
Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/raspbian/gpg | sudo apt-key add -
look up the name of your linux distribution
lsb_release -cs
Setup the Docker Repo.
sudo su
echo "deb [arch=armhf] https://download.docker.com/linux/raspbian buster stable" > /etc/apt/sources.list.d/docker.list
exit
Update the apt package index.
sudo apt-get update
Install the latest version of Docker Engine – Community and containerd without AUFS
sudo apt-get install --no-install-recommends docker-ce docker-ce-cli containerd.io
Show Docker Version
sudo docker version
Verify that Docker Engine – Community is installed correctly by running the hello-world image.
sudo docker run hello-world
Give the ‘g1’ user the ability to run Docker.
sudo usermod -aG docker g1
Create one new user for node_exporter
sudo useradd --no-create-home --shell /bin/false node_exporter
download file
cd ~
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-armv7.tar.gz
unpack archive
tar xvf node_exporter-0.18.1.linux-armv7.tar.gz
copy files and directories
sudo cp node_exporter-0.18.1.linux-armv7/node_exporter /usr/local/bin
sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter
finally, delete files and directory from your home
rm -rf node_exporter-0.18.1.linux-armv7.tar.gz node_exporter-0.18.1.linux-armv7
create a new systemd service file.
sudo nano /etc/systemd/system/node_exporter.service
[Unit] Description=Node Exporter Wants=network-online.target After=network-online.target [Service] User=node_exporter Group=node_exporter Type=simple ExecStart=/usr/local/bin/node_exporter [Install] WantedBy=multi-user.target
then reload systemd, start service and check status.
sudo systemctl daemon-reload
sudo systemctl start node_exporter
sudo systemctl enable node_exporter
change configuration in a file with named prometheus.yml:
sudo nano /etc/prometheus/prometheus.yml
global: scrape_interval: 15s scrape_configs: - job_name: 'prometheus' scrape_interval: 5s static_configs: - targets: ['localhost:9090'] - job_name: 'node_exporter' scrape_interval: 5s static_configs: - targets: ['localhost:9100']
Restart prometheus and check status.
sudo systemctl restart prometheus
sudo systemctl status prometheus
For check node_exporter, enter in the Expression field, node_memory_MemAvailable/1024/1024 and then press the Execute button.
then in console enter free -h
sudo apt-get update
sudo apt-get upgrade
sudo raspi-config
sudo apt-get install motion
sudo nano /etc/motion/motion.conf
... daemon on ... stream_port 8081 ... stream_localhost off ... width 640 ... height 480 ... framerate 25 ...
sudo nano /etc/default/motion
... start_motion_daemon=yes ...
sudo service motion restart
Prometheus is a leading open-source monitoring solution with alerting functional. By default, Prometetheus export only itself metrics and need aditioanl module for accept more information. You can finde more information on: https://prometheus.io/
We need one new user for prometeus service without home directory and shell access.
sudo useradd --no-create-home --shell /bin/false prometheus
according linux best practise create two directorise, one for configuration and other for data.
sudo mkdir /etc/prometheus
sudo mkdir /var/lib/prometheus
and set new user and group ownership
sudo chown prometheus:prometheus /etc/prometheus
sudo chown prometheus:prometheus /var/lib/prometheus
Before download, find the latest stable verion on Prometeus download page. At this time it’s: prometheus-2.12.0.linux-armv7.tar.gz
download file and compere checksum:
cd ~
wget https://github.com/prometheus/prometheus/releases/download/v2.12.0/prometheus-2.12.0.linux-armv7.tar.gz
sha256sum prometheus-2.12.0.linux-armv7.tar.gz
if checksume match than unpack archive:
tar xvf prometheus-2.12.0.linux-armv7.tar.gz
copy files and directories
sudo cp prometheus-2.12.0.linux-armv7/prometheus /usr/local/bin/
sudo cp prometheus-2.12.0.linux-armv7/promtool /usr/local/bin/
sudo cp -r prometheus-2.12.0.linux-armv7/consoles /etc/prometheus
sudo cp -r prometheus-2.12.0.linux-armv7/console_libraries /etc/prometheus
and set the user and group ownership
sudo chown prometheus:prometheus /usr/local/bin/prometheus
sudo chown prometheus:prometheus /usr/local/bin/promtool
sudo chown -R prometheus:prometheus /etc/prometheus/consoles
sudo chown -R prometheus:prometheus /etc/prometheus/console_libraries
finally, delete files and directory from your home
rm -rf prometheus-2.12.0.linux-armv7.tar.gz prometheus-2.12.0.linux-armv7
Create configuration in a file with named prometheus.yml:
sudo nano /etc/prometheus/prometheus.yml
Prometheus config file /etc/prometheus/prometheus.yml
Important: Prometheus configuration file uses the YAML format, don’t user tabs!
global: scrape_interval: 15s scrape_configs: - job_name: 'prometheus' scrape_interval: 5s static_configs: - targets: ['localhost:9090']
set the user and group ownership
sudo chown prometheus:prometheus /etc/prometheus/prometheus.yml
create a new systemd service file.
sudo nano /etc/systemd/system/prometheus.service
add following data into the file: /etc/systemd/system/prometheus.service
[Unit] Description=Prometheus Wants=network-online.target After=network-online.target [Service] User=prometheus Group=prometheus Type=simple ExecStart=/usr/local/bin/prometheus \ --config.file /etc/prometheus/prometheus.yml \ --storage.tsdb.path /var/lib/prometheus/ \ --web.console.templates=/etc/prometheus/consoles \ --web.console.libraries=/etc/prometheus/console_libraries [Install] WantedBy=multi-user.target
then reload systemd,
sudo systemctl daemon-reload
start service,
sudo systemctl start prometheus
check status,
sudo systemctl status prometheus
and after successful running enable the service to start on boot
sudo systemctl enable prometheus
find out your IP address
ifconfig
open link in browser
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
#include <Wire.h> #include <SPI.h> #include <Adafruit_Sensor.h> #include <Adafruit_BME280.h> #include <PubSubClient.h> #include <ESP8266WiFi.h> #define WIFI_AP "" #define WIFI_PASSWORD "" #define TOKEN "" char thingsboardServer[] = ""; WiFiClient wifiClient; Adafruit_BME280 bme; PubSubClient client(wifiClient); int status = WL_IDLE_STATUS; unsigned long lastSend; void setup() { Serial.begin(115200); bme.begin(); delay(10); InitWiFi(); client.setServer( thingsboardServer, 1883 ); lastSend = 0; } void loop() { if ( !client.connected() ) { reconnect(); } if ( millis() - lastSend > 1000 ) { // Update and send only after 1 seconds getAndSendData(); lastSend = millis(); } client.loop(); } void getAndSendData() { Serial.print("getAndSendData: "); float h = bme.readHumidity(); float t = bme.readTemperature(); float p = bme.readPressure()*0.007500617; String temperature = String(t); String humidity = String(h); String pressure = String(p); // Just debug messages Serial.print( temperature ); Serial.print( ", " ); Serial.print( pressure ); Serial.print( ", " ); Serial.println( humidity ); // Prepare a JSON payload string String payload = "{"; payload += "\"temperature\":"; payload += temperature; payload += ","; payload += "\"pressure\":"; payload += pressure; payload += ","; payload += "\"humidity\":"; payload += humidity; payload += "}"; char attributes[100]; payload.toCharArray( attributes, 100 ); client.publish( "v1/devices/me/telemetry", attributes ); Serial.println( attributes ); } void InitWiFi() { Serial.println("Connecting to AP ..."); // attempt to connect to WiFi network WiFi.begin(WIFI_AP, WIFI_PASSWORD); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("Connected to AP"); } void reconnect() { // Loop until we're reconnected while (!client.connected()) { status = WiFi.status(); if ( status != WL_CONNECTED) { WiFi.begin(WIFI_AP, WIFI_PASSWORD); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("Connected to AP"); } Serial.print("Connecting to ThingsBoard node ..."); // Attempt to connect (clientId, username, password) if ( client.connect("ESP8266 Device", TOKEN, NULL) ) { Serial.println( "[DONE]" ); } else { Serial.print( "[FAILED] [ rc = " ); Serial.print( client.state() ); Serial.println( " : retrying in 5 seconds]" ); // Wait 5 seconds before retrying delay( 5000 ); } } } |
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 |
#include <Wire.h> #include <LiquidCrystal_I2C.h> #include "Adafruit_SI1145.h" Adafruit_SI1145 uv = Adafruit_SI1145(); LiquidCrystal_I2C lcd(0x3F,20,4); void setup() { lcd.init(); Serial.begin(9600); if (! uv.begin()) { Serial.println("Didn't find Si1145"); while (1); } Serial.println("OK!"); } void loop() { Serial.println("==================="); Serial.print("Vis: "); Serial.println(uv.readVisible()); Serial.print("IR: "); Serial.println(uv.readIR()); Serial.print("UV: "); Serial.println(uv.readUV()/100.0); lcd.backlight(); lcd.setCursor(0,0); lcd.print("Vis: "); lcd.setCursor(5,0); lcd.print(uv.readVisible()); lcd.setCursor(0,1); lcd.print("IR: "); lcd.setCursor(5,1); lcd.print(uv.readIR()); lcd.setCursor(0,2); lcd.print("UV: "); lcd.setCursor(5,2); lcd.print(uv.readUV()/100.0); delay(1000); } |
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
#include <WiFi.h> #include <Wire.h> const char* ssid = "SSID"; const char* password = ""; const char * hostDomain = "api.openweathermap.org"; const int hostPort = 80; WiFiClient client; void setup() { Serial.begin(9600); delay(100); 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 requestURL(const char * host, uint8_t port) { Serial.println("Connecting to domain: " + String(host)); if (!client.connect(host, port)) { Serial.println("connection failed"); return; } Serial.println("Connected!"); client.println("GET /data/2.5/weather?id=6167865&APPID=9cXXXXXX0c150XXXX768ab17960aaadf HTTP/1.1"); client.print("Host: api.openweathermap.org\r\n"); client.print("Connection: close\r\n\r\n"); unsigned long timeout = millis(); while (client.available() == 0) { if (millis() - timeout > 1000) { Serial.println(">>> Client Timeout !"); client.stop(); return; } } // Read all the lines of the reply from server and print them to Serial while (client.available()) { String line = client.readStringUntil('\r'); Serial.print(line); } Serial.println(); Serial.println("closing connection"); client.stop(); } void loop() { Serial.println(); requestURL(hostDomain, hostPort); delay(30000); } |
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
#include <WiFi.h> #include <Wire.h> #include <ArduinoJson.h> const char* ssid = "SSID"; const char* password = ""; const char * hostDomain = "api.openweathermap.org"; const int hostPort = 80; String line; WiFiClient client; void setup() { Serial.begin(9600); delay(100); 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 requestURL(const char * host, uint8_t port) { Serial.println("Connecting to domain: " + String(host)); if (!client.connect(host, port)) { Serial.println("connection failed"); return; } Serial.println("Connected!"); client.println("GET /data/2.5/weather?id=6167865&APPID=XXXXXXXXXXXXXX5f5768ab17960aaadf&units=metric HTTP/1.1"); client.print("Host: api.openweathermap.org\r\n"); client.print("Connection: close\r\n\r\n"); unsigned long timeout = millis(); while (client.available() == 0) { if (millis() - timeout > 1000) { Serial.println(">>> Client Timeout !"); client.stop(); return; } } // Read all the lines of the reply from server and print them to Serial while (client.available()) { line = client.readStringUntil('\r'); } Serial.println(); Serial.println("closing connection"); client.stop(); } void parseJSON(String weather) { StaticJsonBuffer<3000> jsonBuffer; JsonObject& root = jsonBuffer.parseObject(weather); if (!root.success()) { Serial.print("ParseObject() failed"); } String name = root["name"]; Serial.print("name: "); Serial.println(name); float temp = root["main"]["temp"]; Serial.print("temp: "); Serial.print(temp); Serial.println(" C"); float temp_min = root["main"]["temp_min"]; Serial.print("temp_min: "); Serial.print(temp_min); Serial.println(" C"); float temp_max = root["main"]["temp_max"]; Serial.print("temp_max: "); Serial.print(temp_max); Serial.println(" C"); float pressure = root["main"]["pressure"]; Serial.print("pressure: "); Serial.print(pressure); Serial.println(" mmHg"); float humidity = root["main"]["humidity"]; Serial.print("humidity: "); Serial.print(humidity); Serial.println(" %"); } void loop() { Serial.println(); requestURL(hostDomain, hostPort); Serial.print(line); Serial.println(); Serial.println("-------------"); Serial.println(); parseJSON(line); delay(30000); } |
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 46 47 48 49 50 51 |
#include <ESP8266WiFi.h> // Include the ESP8266 Library #include "ThingSpeak.h" // Include the ThingSpeak library WiFiClient client; const char* ssid = "SSID"; // Enter your WiFi network name const char* password = "PASSWD"; // Enter your WiFi password unsigned long myChannelNumber = 237783; const char * myWriteAPIKey = "WRITE_API"; const char * myReadAPIKey = "READ_API"; void setup() { Serial.begin(9600); // Get ready for serial communications and display the connetion status delay(100); Serial.println(); Serial.println(); Serial.print("Connecting to WiFi network - "); 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()); ThingSpeak.begin(client); } void loop() { int potentiometerValue = analogRead(A0); ThingSpeak.writeField(myChannelNumber, 1, potentiometerValue, myWriteAPIKey); int readField = ThingSpeak.readFloatField(myChannelNumber, 1, myReadAPIKey); Serial.print("Current potentiometer value is: "); Serial.println(readField); delay(16000); } |
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
#include <WiFi.h> #include <Wire.h> #include <Adafruit_Sensor.h> #include <Adafruit_BME280.h> #define SEALEVELPRESSURE_HPA (1013.25) const char* ssid = "SSID"; const char* password = "PASS"; const char * hostDomain = "api.thingspeak.com"; const int hostPort = 80; String myWriteAPIKey = "YNYD7OQXR8SZVF6U"; WiFiClient client; Adafruit_BME280 bme; float bmeTemperature = 0; float bmePressure = 0; float bmeHumidity =0; void setup() { Serial.begin(9600); delay(100); if (!bme.begin()) { Serial.println("Could not find a valid BME280 sensor, check wiring!"); while (1); } Serial.println(); 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 requestURL(const char * host, uint8_t port, float Temperature, float Pressure, float Humidity) { Serial.println("Connecting to domain: " + String(host)); if (!client.connect(host, port)) { Serial.println("connection failed"); return; } Serial.println("Connected!"); // This will send the request to the server String getStr = myWriteAPIKey; getStr +="&field1="; getStr += String(Temperature); getStr +="&field2="; getStr += String(Pressure); getStr +="&field3="; getStr += String(Humidity); getStr += "\r\n\r\n"; Serial.println(getStr); client.print("GET /update HTTP/1.1\n"); client.print("Host: api.thingspeak.com\n"); client.print("Connection: close\n"); client.print("X-THINGSPEAKAPIKEY: "+myWriteAPIKey+"\n"); client.print("Content-Type: application/x-www-form-urlencoded\n"); client.print("Content-Length: "); client.print(getStr.length()); client.print("\n\n"); client.print(getStr); unsigned long timeout = millis(); while (client.available() == 0) { if (millis() - timeout > 5000) { Serial.println(">>> Client Timeout !"); client.stop(); return; } } // Read all the lines of the reply from server and print them to Serial while (client.available()) { String line = client.readStringUntil('\r'); Serial.print(line); } Serial.println(); Serial.println("closing connection"); client.stop(); } void loop() { bmeTemperature = bme.readTemperature(); bmePressure = bme.readPressure()*0.007500617; bmeHumidity = bme.readHumidity(); Serial.print("Temperature = "); Serial.print(bmeTemperature); Serial.println(" *C"); Serial.print("Pressure = "); Serial.print(bmePressure); Serial.println(" hPa"); Serial.print("Humidity = "); Serial.print(bmeHumidity); Serial.println(" %"); Serial.println(); requestURL(hostDomain, hostPort, bmeTemperature, bmePressure, bmeHumidity); delay(60000); } |
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
#include <ESP8266WiFi.h> #include <WiFiClient.h> #include <ESP8266WebServer.h> #include <ESP8266mDNS.h> MDNSResponder mdns; ESP8266WebServer server(80); // Replace with your network credentials const char* ssid = ""; const char* password = ""; String webPage = ""; int test_pin = 16; void setup(void){ webPage += "<!DOCTYPE HTML> <html> <head> <title>G1Tech: ESP8266 Web Server</title>"; webPage += "<style type=\"text/css\">"; webPage += ".label {display: inline; padding: .2em .6em .3em; font-size: 75%; font-weight: 700; line-height: 1; color: #fff; text-align: center; white-space: nowrap; vertical-align: baseline; border-radius: .25em;}"; webPage += ".label-default {background-color: #777;}"; webPage += ".btn {background-color: #4CAF50; border: none; color: white; padding: 16px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; -webkit-transition-duration: 0.4s; transition-duration: 0.4s; cursor: pointer;}"; webPage += ".btn-on {background-color: white; color: black; border: 2px solid #4CAF50;}"; webPage += ".btn-on:hover {background-color: #4CAF50; color: white;}"; webPage += ".btn-off {background-color: white; color: black; border: 2px solid #f44336;}"; webPage += ".btn-off:hover {background-color: #f44336; color: white;}"; webPage += "</style> </head> <body>"; webPage += "<h1>G1Tech: ESP8266 Web Server</h1><h1><p class=\"label label-default\">LED #16 </p><p><a href=\"LEDOn\"><button class=\"btn btn-on\">ON</button></a> <a href=\"LEDOff\"><button class=\"btn btn-off\" >OFF</button></a></p></h1></body></html>"; pinMode(test_pin, OUTPUT); digitalWrite(test_pin, LOW); delay(1000); Serial.begin(9600); WiFi.begin(ssid, password); Serial.println(""); // Wait for connection while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); if (mdns.begin("esp8266", WiFi.localIP())) { Serial.println("MDNS responder started"); } server.on("/", [](){ server.send(200, "text/html", webPage); }); server.on("/LEDOn", [](){ server.send(200, "text/html", webPage); digitalWrite(test_pin, LOW); Serial.println(digitalRead(test_pin)); delay(1000); }); server.on("/LEDOff", [](){ server.send(200, "text/html", webPage); digitalWrite(test_pin, HIGH); Serial.println(digitalRead(test_pin)); delay(1000); }); server.begin(); Serial.println("HTTP server started"); } void loop(void){ server.handleClient(); } |