You are on page 1of 16

https://github.com/closebox73/Leonis.

git

Hi Folks,
I have the coretemp and it87 type chips and was using the method of lunch_box and
sparky
to get the temps in conky. After reading fphillips's post I started hunting
around in /sys/ and
playing with .conkrc. On my box:

${hwmon 0 temp 1} refers to /sys/class/hwmon/hwmon0/device/temp1_input


${hwmon 4 fan 1} refers to /sys/class/hwmon/hwmon4/device/fan4_input
So I now use $hwmon in .conkyrc which should preform a little better than execi and
sensors.

-----------------------------------------------------------------------------------
-------------------------------------------------------------
sensors esempio
-----------------------------------------------------------------------------------
-------------------------------------------------------------

coretemp-isa-0000
Adapter: ISA adapter
Core 0: +59.0°C (high = +80.0°C, crit = +100.0°C)

coretemp-isa-0001
Adapter: ISA adapter
Core 3: +57.0°C (high = +80.0°C, crit = +100.0°C)

coretemp-isa-0002
Adapter: ISA adapter
Core 1: +52.0°C (high = +80.0°C, crit = +100.0°C)

coretemp-isa-0003
Adapter: ISA adapter
Core 2: +53.0°C (high = +80.0°C, crit = +100.0°C)
[SNIP]
fan1: 1161 RPM (min = 10 RPM)
fan4: 2657 RPM (min = 0 RPM)
[SNIP]

-----------------------------------------------------------------------------------
-------------------------------------------------------------
sensors dell
-----------------------------------------------------------------------------------
-------------------------------------------------------------

dell_smm-isa-0000
Adapter: ISA adapter
Processor Fan: 3443 RPM (min = 0 RPM, max = 4818 RPM)
CPU: +55.0°C
Ambient: +49.0°C
Ambient: +51.0°C
GPU: +16.0°C
Other: +64.0°C

BAT0-acpi-0
Adapter: ACPI interface
in0: 12.42 V
curr1: 1000.00 uA

acpitz-acpi-0
Adapter: ACPI interface
temp1: +55.5°C (crit = +84.0°C)

-----------------------------------------------------------------------------------
-------------------------------------------------------------
ls /sys/class/hwmon

hwmon0 hwmon1 hwmon2 hwmon3 hwmon4

-----------------------------------------------------------------------------------
-------------------------------------------------------------
# ls /sys/class/hwmon/hwmon0

device name power subsystem uevent

name AC

-----------------------------------------------------------------------------------
-------------------------------------------------------------
# ls /sys/class/hwmon/hwmon1

device name power subsystem temp1_crit


temp1_input uevent

name acpitz
temp1_crit 84000
temp1_input 49500

-----------------------------------------------------------------------------------
-------------------------------------------------------------
# ls /sys/class/hwmon/hwmon2

curr1_input device in0_input name power subsystem uevent

name BAT0
in0_input 12409 12,4V
curr1_input 1

-----------------------------------------------------------------------------------
-------------------------------------------------------------
# ls /sys/class/hwmon/hwmon4

device fan1_label fan1_min name pwm1 temp1_input temp2_input


temp3_input temp4_input temp5_input uevent
fan1_input fan1_max fan1_target power subsystem temp1_label temp2_label
temp3_label temp4_label temp5_label

name dell_smm
fan1_label Processor Fan
fan1_min 0
fan1_input 2956
fan1_max 4818

temp1_label CPU
temp1_input 50000
temp2_label Ambient
temp2_input 45000

temp3_label Ambient
temp3_input 48000

temp4_label GPU
temp4_input 16000

temp5_label Other
temp5_input 62000

-----------------------------------------------------------------------------------
-------------------------------------------------------------
.conkyrc

${color1}CPU0:$color ${cpu cpu0}% ${cpubar cpu0 5,85}${alignr 10}${color2}${hwmon 0


temp 1}$alignr${color1}${cpugraph cpu0 32,120 104E8B FF7F50 -t}
${color1}CPU1:$color ${cpu cpu1}% ${cpubar cpu1 5,85}${alignr 10}${color2}${hwmon 2
temp 1}$alignr${color1}${cpugraph cpu1 32,120 104E8B FF7F50 -t}
${color1}CPU2:$color ${cpu cpu2}% ${cpubar cpu2 5,85}${alignr 10}${color2}${hwmon 3
temp 1}$alignr${color1}${cpugraph cpu2 32,120 104E8B FF7F50 -t}
${color1}CPU3:$color ${cpu cpu3}% ${cpubar cpu3 5,85}${alignr 10}${color2}${hwmon 1
temp 1}$alignr${color1}${cpugraph cpu3 32,120 104E8B FF7F50 -t}
${color1}Processor Fan :${color2}${hwmon 4 fan1} RPM
${color1}Processor Fan Max:${color2}${hwmon 4 fan1_max} RPM
-----------------------------------------------------------------------------------
-------------------------------------------------------------
ChatGPT :bash esempio di array
-----------------------------------------------------------------------------------
-------------------------------------------------------------

Sure! In bash, you can create arrays to store multiple values in a single variable.
Here's a simple example of how to declare, initialize, and access elements in an
array:

#!/bin/bash

# Declare an array
my_array=("apple" "banana" "orange" "grape")

# Access individual elements


echo "First element: ${my_array[0]}"
echo "Second element: ${my_array[1]}"
echo "Third element: ${my_array[2]}"
echo "Fourth element: ${my_array[3]}"

# Access all elements using a loop


echo "All elements:"
for item in "${my_array[@]}"
do
echo "$item"
done

Save the above code in a file (e.g., array_example.sh), and make sure it's
executable
(chmod +x array_example.sh). Then you can run it in your terminal:

bash array_example.sh
The output will be:

yaml

First element: apple


Second element: banana
Third element: orange
Fourth element: grape

All elements:

apple
banana
orange
grape

This is a basic example of how to work with arrays in bash. You can perform various
operations on arrays,
like adding elements, removing elements, updating values, and more.
Bash provides a lot of flexibility when working with arrays, making it a powerful
tool for shell scripting.

-----------------------------------------------------------------------------------
-------------------------------------------------------------
conky estrarre da un file text il secondo item di ogni riga dove gli items sono
separati da virgole
-----------------------------------------------------------------------------------
-------------------------------------------------------------

To extract the second item from each line of a text file where items are separated
by commas
(CSV format) using Conky, you can use the lua feature in Conky.
You'll need to read the file, split each line by commas, and then extract the
second item.
Here's an example of how you can achieve that:

Create a text file named city_id.txt with the content:

Vatican%20City,VA,6691831
Terracina,IT,6541893
Rocca%20di%20Papa,IT,3169181

apple,red
banana,yellow
orange,orange
grape,purple

Create a Conky configuration file (e.g., conky_config.lua) with the following


content:

conky.config = {
-- Other Conky configuration options here
-- ...
lua_load = 'city_id.txt',
lua_draw_hook_pre = 'extract_items',
}

function extract_items()
-- Read the content of the file
local file = io.open('city_id.txt', 'r')

for line in file:lines() do


-- Split the line by commas
local items = {}
for item in line:gmatch('([^,]+)') do
table.insert(items, item)
end

-- Check if the second item exists and print it


if #items >= 2 then
print(items[2])
end
end

file:close()
end

Replace 'path/to/extract_items.lua' and 'path/to/data.txt' with the actual paths to


the Lua script
and the data file, respectively.
Save both files and then run Conky with the following command:

conky -c conky_config.lua

This will display the second item from each line of the data.txt file on your Conky
output.

Please note that Conky is not the ideal tool for text processing tasks, and using
it for this purpose
might not be the most efficient solution. However, if you want to integrate this
task with your
existing Conky setup, the provided approach should work. For more complex text
processing tasks,
other scripting languages like Python or awk would be more suitable.

User and what i want print any items of every row ?


ChatGPT
If you want to print all the items from each line of the CSV file, you can modify
the Lua script in
the Conky configuration file to achieve that. Here's the updated conky_config.lua
file:

Assuming you have the same data.txt file as before:

apple,red
banana,yellow
orange,orange
grape,purple

Update the conky_config.lua file with the following content:

conky.config = {
-- Other Conky configuration options here
-- ...
lua_load = 'path/to/extract_items.lua',
lua_draw_hook_pre = 'extract_items',
}
function extract_items()
-- Read the content of the file
local file = io.open('path/to/data.txt', 'r') -- Replace with the actual path
to the data file
if not file then return end

for line in file:lines() do


-- Split the line by commas
local items = {}
for item in line:gmatch('([^,]+)') do
table.insert(items, item)
end

-- Print all items


for i, item in ipairs(items) do
print(item)
end
end

file:close()
end

Replace 'path/to/extract_items.lua' and 'path/to/data.txt' with the actual paths to


the Lua script
and the data file, respectively.

Save both files and then run Conky with the following command:

conky -c conky_config.lua

This will display all the items from each line of the data.txt file on your Conky
output:

apple
red
banana
yellow
orange
orange
grape
purple

Each item will be printed on a separate line.


This way, you can access and display all the items from every row in the CSV file.

User ok i can print item of same row togheter on th same display row ?

ChatGPT Yes, you can print the items of the same row together on the same display
row in Conky.
To achieve that, you need to concatenate the items of each row before printing
them.
Here's the updated conky_config.lua file to display the items of each row together
on the same
row in Conky:

Assuming you have the same data.txt file as before:

apple,red
banana,yellow
orange,orange
grape,purple

Update the conky_config.lua file with the following content:

conky.config = {
-- Other Conky configuration options here
-- ...
lua_load = 'path/to/extract_items.lua', -- Replace with the actual path to the
lua script
lua_draw_hook_pre = 'extract_items',
}

function extract_items()
-- Read the content of the file
local file = io.open('path/to/data.txt', 'r') -- Replace with the actual path
to the data file
if not file then return end

for line in file:lines() do


-- Split the line by commas and concatenate items
local items = {}
for item in line:gmatch('([^,]+)') do
table.insert(items, item)
end

-- Concatenate all items and print them together


local concatenated_items = table.concat(items, ' ')
print(concatenated_items)
end

file:close()
end

Replace 'path/to/extract_items.lua' and 'path/to/data.txt' with the actual paths to


the Lua script
and the data file, respectively.

Save both files and then run Conky with the following command:

conky -c conky_config.lua

This will display the items of each row together on the same row in your Conky
output:

Copy code
apple red
banana yellow
orange orange
grape purple

Each row will be printed on a separate line, but the items of each row will be
displayed together
with a space between them. This way, the items of the same row will be shown on the
same display
row in Conky.

User and what if i want return only the select item of a selected row ?
ChatGPT If you want to return only a selected item from a specific row in the CSV
file,
you can modify the Lua script in the Conky configuration to achieve that. Here's
how you can do it:

Assuming you have the same data.txt file as before:

apple,red
banana,yellow
orange,orange
grape,purple

Update the conky_config.lua file with the following content:

conky.config = {
-- Other Conky configuration options here
-- ...
lua_load = 'path/to/extract_item.lua', -- Replace with the actual path to the
lua script
lua_draw_hook_pre = 'extract_item',
}

function extract_item()
-- Read the content of the file
local file = io.open('path/to/data.txt', 'r') -- Replace with the actual path
to the data file
if not file then return end

-- Set the row number and the item index you want to extract
local selected_row = 2 -- Change this to the row number you want (1-based
index)
local selected_item_index = 2 -- Change this to the item index you want to
extract (1-based index)

local row_counter = 0
for line in file:lines() do
row_counter = row_counter + 1

-- Check if it's the selected row


if row_counter == selected_row then
-- Split the line by commas
local items = {}
for item in line:gmatch('([^,]+)') do
table.insert(items, item)
end

-- Check if the selected item index is valid


if selected_item_index >= 1 and selected_item_index <= #items then
-- Print the selected item
print(items[selected_item_index])
else
print("Invalid item index for the selected row.")
end

break -- Exit the loop once the selected row is found


end
end
file:close()
end

Replace 'path/to/extract_item.lua' and 'path/to/data.txt' with the actual paths to


the Lua script
and the data file, respectively.

Modify the selected_row and selected_item_index variables to specify the row number
and the
item index you want to extract.
Both of these variables are 1-based indices, meaning the first row and item have an
index of 1,
the second has an index of 2, and so on.

Save both files and then run Conky with the following command:

conky -c conky_config.lua

This will return the selected item from the specified row in your Conky output.
For example, if you set selected_row to 2 and selected_item_index to 2, the output
will be:

yellow

This will return the second item from the second row of the data.txt file.
You can change the selected_row and selected_item_index variables as needed to
extract
different items from different rows.

-----------------------------------------------------------------------------------
------------------------------------------------------------

ESP8266 Weather Forecaster


In this post you’re going to build a weather forecaster with an ESP8266.

This project was written by Emmanuel Odunlade and edited by Rui Santos.

I hate being out on a rainy day without an umbrella and I’m pretty sure it’s the
same for everyone else.

Often, the weather widget on our smartphones displays the weather forecast but when
you’re in a hurry you forget to pay attention to it.

So, it would be nice to have a device hanging at the back of the door which reminds
you to leave your house with an umbrella on a day where it might rain. This device
tells you the weather forecast with a change in the LED color. This device wouldn’t
have an alarm neither a screen, just a few LEDs that would fit naturally into your
environment.

Parts required
Here’s a complete list of the components you need for this project (click the links
below to find the best price at Maker Advisor):

ESP8266 12-E – read Best ESP8266 Wi-Fi Development Boards


4x LEDs (different colors to represent different weather conditions)
4x Resistors (220 or 330 ohms should do the trick)
Breadboard
Jumper wires
You can use the preceding links or go directly to MakerAdvisor.com/tools to find
all the parts for your projects at the best price!

Open Weather Map


This project is based on the Open Weather Map API, so it’s necessary to sign up on
their platform and obtain an API key before we get down to putting together the
schematics and writing the code.

OpenWeatherMap’s free plan provides everything you need for thins example. To use
the API you need an API key, known as the APIID. To get an APIID:

Open a browser and go to OpenWeatherMap


Press the Sign up button and create a free account
Once your account is created, you’ll be presented with a dashboard that contains
several tabs (see figure below)
Select the API Keys tab and copy your unique Key

This is a unique key you need to pull information from the site. Copy and paste
this key somewhere, you’ll need it in a moment.

To pull information on weather in your chosen location, enter the following URL
with the sections in curly brackets replaced with your chosen location information
and your unique API key:

http://api.openweathermap.org/data/2.5/forecast?q={your city},{your country


code}&APPID={your API Key}&mode=json&units=metric&cnt=2
Replace {your city} with the city you want data for, {your country code} with the
country code for that city, and {your API key} with your unique API key we found
previously. For example, our API URL for the town of Porto in Portugal, after
replacing with the details, would be:

http://api.openweathermap.org/data/2.5/forecast?
q=Porto,PT&APPID=801d2603e9f2e1c70e042e4------&mode=json&units=metric&cnt=2
Note: more information on using the API to get weather information is available
here.

Copy your URL into your browser and it should give you a bunch of information that
corresponds to your local weather forecast information.

Keep your unique API key safe and we can then move to the code section.

Installing the ArduinoJson library


For this project you need to install the ArduinoJson library in your Arduino IDE
that allows you to Decode and Encode JSON with Arduino or ESP8266. Follow these
next steps:

Click here to download the ArduinoJson. You should have a .zip folder in your
Downloads folder
Unzip the .zip folder and you should get ArduinoJson-master folder
Rename your folder from ArduinoJson-master to ArduinoJson
Move the ArduinoJson folder to your Arduino IDE installation libraries folder
Finally, re-open your Arduino IDE
Uploading code
Having the ESP8266 add-on for the Arduino IDE installed (how to Install the ESP8266
Board in Arduino IDE), go to Tools and select “NodeMCU (ESP-12E Module)”.

Copy the following code to your Arduino IDE and upload it to your ESP8266 board.

Go through the code to add your SSID, password, city, country code and Open Weather
Map API key.

/*
* Author: Emmanuel Odunlade
* Complete Project Details https://randomnerdtutorials.com
*/

#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>

// Replace with your SSID and password details


char ssid[] = "REPLACE_WITH_YOUR_SSID";
char pass[] = "REPLACE_WITH_YOUR_PASSWORD";

WiFiClient client;

// Open Weather Map API server name


const char server[] = "api.openweathermap.org";

// Replace the next line to match your city and 2 letter country code
String nameOfCity = "REPLACE_WITH_YOUR_CITY,REPLACE_WITH_YOUR_COUNTRY_CODE";
// How your nameOfCity variable would look like for Lagos on Nigeria
//String nameOfCity = "Lagos,NG";

// Replace the next line with your API Key


String apiKey = "REPLACE_WITH_YOUR_API_KEY";

String text;

int jsonend = 0;
boolean startJson = false;
int status = WL_IDLE_STATUS;

int rainLed = 2; // Indicates rain


int clearLed = 3; // Indicates clear sky or sunny
int snowLed = 4; // Indicates snow
int hailLed = 5; // Indicates hail

#define JSON_BUFF_DIMENSION 2500

unsigned long lastConnectionTime = 10 * 60 * 1000; // last time you connected


to the server, in milliseconds
const unsigned long postInterval = 10 * 60 * 1000; // posting interval of 10
minutes (10L * 1000L; 10 seconds delay for testing)

void setup() {
pinMode(clearLed, OUTPUT);
pinMode(rainLed, OUTPUT);
pinMode(snowLed, OUTPUT);
pinMode(hailLed, OUTPUT);
Serial.begin(9600);

text.reserve(JSON_BUFF_DIMENSION);
WiFi.begin(ssid,pass);
Serial.println("connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi Connected");
printWiFiStatus();
}

void loop() {
//OWM requires 10mins between request intervals
//check if 10mins has passed then conect again and pull
if (millis() - lastConnectionTime > postInterval) {
// note the time that the connection was made:
lastConnectionTime = millis();
makehttpRequest();
}
}

// print Wifi status


void printWiFiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());

// print your WiFi shield's IP address:


IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);

// print the received signal strength:


long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}

// to request data from OWM


void makehttpRequest() {
// close any connection before send a new request to allow client make connection
to server
client.stop();

// if there's a successful connection:


if (client.connect(server, 80)) {
// Serial.println("connecting...");
// send the HTTP PUT request:
client.println("GET /data/2.5/forecast?q=" + nameOfCity + "&APPID=" + apiKey +
"&mode=json&units=metric&cnt=2 HTTP/1.1");
client.println("Host: api.openweathermap.org");
client.println("User-Agent: ArduinoWiFi/1.1");
client.println("Connection: close");
client.println();

unsigned long timeout = millis();


while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> Client Timeout !");
client.stop();
return;
}
}

char c = 0;
while (client.available()) {
c = client.read();
// since json contains equal number of open and close curly brackets, this
means we can determine when a json is completely received by counting
// the open and close occurences,
//Serial.print(c);
if (c == '{') {
startJson = true; // set startJson true to indicate json message
has started
jsonend++;
}
if (c == '}') {
jsonend--;
}
if (startJson == true) {
text += c;
}
// if jsonend = 0 then we have have received equal number of curly braces
if (jsonend == 0 && startJson == true) {
parseJson(text.c_str()); // parse c string text in parseJson function
text = ""; // clear text string for the next time
startJson = false; // set startJson to false to indicate that a new
message has not yet started
}
}
}
else {
// if no connction was made:
Serial.println("connection failed");
return;
}
}

//to parse json data recieved from OWM


void parseJson(const char * jsonString) {
//StaticJsonBuffer<4000> jsonBuffer;
const size_t bufferSize = 2*JSON_ARRAY_SIZE(1) + JSON_ARRAY_SIZE(2) +
4*JSON_OBJECT_SIZE(1) + 3*JSON_OBJECT_SIZE(2) + 3*JSON_OBJECT_SIZE(4) +
JSON_OBJECT_SIZE(5) + 2*JSON_OBJECT_SIZE(7) + 2*JSON_OBJECT_SIZE(8) + 720;
DynamicJsonBuffer jsonBuffer(bufferSize);

// FIND FIELDS IN JSON TREE


JsonObject& root = jsonBuffer.parseObject(jsonString);
if (!root.success()) {
Serial.println("parseObject() failed");
return;
}

JsonArray& list = root["list"];


JsonObject& nowT = list[0];
JsonObject& later = list[1];
// including temperature and humidity for those who may wish to hack it in

String city = root["city"]["name"];

float tempNow = nowT["main"]["temp"];


float humidityNow = nowT["main"]["humidity"];
String weatherNow = nowT["weather"][0]["description"];

float tempLater = later["main"]["temp"];


float humidityLater = later["main"]["humidity"];
String weatherLater = later["weather"][0]["description"];

// checking for four main weather possibilities


diffDataAction(weatherNow, weatherLater, "clear");
diffDataAction(weatherNow, weatherLater, "rain");
diffDataAction(weatherNow, weatherLater, "snow");
diffDataAction(weatherNow, weatherLater, "hail");

Serial.println();
}

//representing the data


void diffDataAction(String nowT, String later, String weatherType) {
int indexNow = nowT.indexOf(weatherType);
int indexLater = later.indexOf(weatherType);
// if weather type = rain, if the current weather does not contain the weather
type and the later message does, send notification
if (weatherType == "rain") {
if (indexNow == -1 && indexLater != -1) {
digitalWrite(rainLed,HIGH);
digitalWrite(clearLed,LOW);
digitalWrite(snowLed,LOW);
digitalWrite(hailLed,LOW);
Serial.println("Oh no! It is going to " + weatherType + " later! Predicted "
+ later);
}
}
// for snow
else if (weatherType == "snow") {
if (indexNow == -1 && indexLater != -1) {
digitalWrite(snowLed,HIGH);
digitalWrite(clearLed,LOW);
digitalWrite(rainLed,LOW);
digitalWrite(hailLed,LOW);
Serial.println("Oh no! It is going to " + weatherType + " later! Predicted "
+ later);
}

}
// can't remember last time I saw hail anywhere but just in case
else if (weatherType == "hail") {
if (indexNow == -1 && indexLater != -1) {
digitalWrite(hailLed,HIGH);
digitalWrite(clearLed,LOW);
digitalWrite(rainLed,LOW);
digitalWrite(snowLed,LOW);
Serial.println("Oh no! It is going to " + weatherType + " later! Predicted "
+ later);
}
}
// for clear sky, if the current weather does not contain the word clear and the
later message does, send notification that it will be sunny later
else {
if (indexNow == -1 && indexLater != -1) {
Serial.println("It is going to be sunny later! Predicted " + later);
digitalWrite(clearLed,HIGH);
digitalWrite(rainLed,LOW);
digitalWrite(snowLed,LOW);
digitalWrite(hailLed,LOW);
}
}
}

View raw code

Schematics
Wire your circuit accordingly to the schematic below:

Demonstration
The next figure describes what each LED indicates: (D2) Rain, (D3) Clear sky, (D4)
Snow and (D5) Hail:

Here’s a photo of the final circuit:

Wrapping up
Nowadays, the goal of computing is to create a natural user interface between man
and computers. We are looking to things like AR (Augmented Reality) to make that
reality, but the truth is we are all getting tired of constantly looking at our
phones and PCs for the tiniest piece of information.

I think having this project hanged somewhere around the house where you can easily
know the weather on your way out is extremely useful.

To take this project further, I may throw in a 3D printed enclosure with a battery
back up to make this look more neat. I will certainly share with you when that is
done.

Thanks for reading!

You might also like reading our Home Automation using ESP8266 eBook.

Build-Web-Servers-with-ESP32-and-ESP8266-eBook-2nd-Edition-500px-h
[eBook] Build Web Servers with ESP32 and ESP8266 (2nd Edition)
Build Web Server projects with the ESP32 and ESP8266 boards to control outputs and
monitor sensors remotely. Learn HTML, CSS, JavaScript and client-server
communication protocols DOWNLOAD »
Recommended Resources

You might also like