Professional Documents
Culture Documents
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:
-----------------------------------------------------------------------------------
-------------------------------------------------------------
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
-----------------------------------------------------------------------------------
-------------------------------------------------------------
# ls /sys/class/hwmon/hwmon0
name AC
-----------------------------------------------------------------------------------
-------------------------------------------------------------
# ls /sys/class/hwmon/hwmon1
name acpitz
temp1_crit 84000
temp1_input 49500
-----------------------------------------------------------------------------------
-------------------------------------------------------------
# ls /sys/class/hwmon/hwmon2
name BAT0
in0_input 12409 12,4V
curr1_input 1
-----------------------------------------------------------------------------------
-------------------------------------------------------------
# ls /sys/class/hwmon/hwmon4
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
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")
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
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:
Vatican%20City,VA,6691831
Terracina,IT,6541893
Rocca%20di%20Papa,IT,3169181
apple,red
banana,yellow
orange,orange
grape,purple
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')
file:close()
end
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.
apple,red
banana,yellow
orange,orange
grape,purple
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
file:close()
end
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
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:
apple,red
banana,yellow
orange,orange
grape,purple
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
file:close()
end
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:
apple,red
banana,yellow
orange,orange
grape,purple
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
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.
-----------------------------------------------------------------------------------
------------------------------------------------------------
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):
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:
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=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.
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>
WiFiClient client;
// 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";
String text;
int jsonend = 0;
boolean startJson = false;
int status = WL_IDLE_STATUS;
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();
}
}
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;
}
}
Serial.println();
}
}
// 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);
}
}
}
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:
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.
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