No man is an island.
- Tim's Homestead Journal - Purchase a copy of Building a Better World in Your Backyard - Purchase 6 Decks of Permaculture Cards -
- Purchase 12x Decks of Permaculture Cards - Purchase a copy of the SKIP Book - Purchase 12x copies of Building a Better World in your Backyard
// import library for i2c pins on raspberry pi
const i2c = require('i2c-bus');
// import library to write to filesystem
var fs = require('fs');
// import library to connect to database/supabase
import { createClient } from '@supabase/supabase-js'
// declare sensor setting
const PORT_ADDR = 1;
const SENSOR_ADDR = 0x48; //0x49 or 0x4A or 0x4B also configurable via jumper on sensor
const TEMP_REG = 0x05;
// declare database/supabase settings
const dbURL = https://xyzcompany.supabase.co;
const dbKEY = ycyvbyvu2bbmn22nm;
//connect to database/supabase
const supabase = createClient(dbURL, dbKey);
// open connection to sensor/port using synchronous method
const i2c1 = i2c.openSync(PORT_ADDR);
// read the raw sensor data after connecting to the sensor address/etc
const rawData = i2c1.readWordSync(SENSOR_ADDR, TEMP_REG);
// print the sensor data after converting it to celsius
console.log(toCelsius(rawData));
// add data to file
fs.appendFile('myfile1.txt', toCelsius(rawData));
// add data to database/supabase
const { error } = await supabase.from('temperaturetable').insert({tempfield: toCelsius(rawData)});
// close out the connection to the sensor
i2c1.closeSync();
// or open connection to sensor/port using promise method
i2c.openPromisified(PORT_ADDR).
then(i2c1 => i2c1.readWord(SENSOR_ADDR, TEMP_REG).
then(rawData => console.log(toCelsius(rawData))).
then(rawData => fs.appendFile('myfile1.txt', toCelsius(rawData))).
then(rawData => const { error } = await supabase.from('temperaturetable').insert({tempfield: toCelsius(rawData)}).
then(_ => i2c1.close())
).catch(console.log);
// declare function to convert raw sensor data to celsius
const toCelsius = rawData => {
rawData = (rawData >> 8) + ((rawData & 0xff) << 8);
let celsius = rawData;
if (celsius < 0x8000) {
// Positive temperature
celsius = celsius / 128;
} else {
// Negative temperature; convert from 16-bit two's complement
celsius = (celsius - 0x10000) / 128;
}
return celsius;
};
Iterations are fine, we don't have to be perfect
My 2nd Location:Florida HardinessZone:10 AHS:10 GDD:8500 Rainfall:2in/mth winter, 8in/mth summer, Soil:Sand pH8 Flat
Iterations are fine, we don't have to be perfect
My 2nd Location:Florida HardinessZone:10 AHS:10 GDD:8500 Rainfall:2in/mth winter, 8in/mth summer, Soil:Sand pH8 Flat
S Bengi wrote:What about multiple temperature probes:
Inside Temp
Outside temp
Inside Ceiling temp (if temp high then open window, else if temp low then close window)
Inside Ground/Soil/Water/Thermal Battery Temp
Check Water Level (if level is low then add 1gallon of water)
I wonder if javaScript(node.js) could be used for the entire stack vs .py and .php and .js.
Growing tropical and sub-tropical fruits in the UK
YouTube: https://www.youtube.com/@PeterEntwistle
Life on a farm is a school of patience; you can't hurry the crops or make an ox in two days.
Henri Alain
Country oriented nerd with primary interests in alternate energy in particular solar. Dabble in gardening, trees, cob, soil building and a host of others.
C. Letellier wrote:
I2C bus stuff has a very limited distance to send and receive. So while you can do multiple sensors easily they must be close.
If looking to control motion, limit switches will likely be necessary.
Then a quick question. Why checking the temperature that often? Probably won't change significantly in less than 5 minutes and maybe every 10 or 15 minutes would be sufficient.
Mart Hale wrote:
With the price of a raspberry pi, I would not buy one unless I found one cheap, rather I would go with other options...
Winn Sawyer wrote:
Mart Hale wrote:
With the price of a raspberry pi, I would not buy one unless I found one cheap, rather I would go with other options...
The pi zero W is $15 ($16 if you want the header soldered on), I think that is a pretty decent price for this kind of usage. I would not get a full sized pi for this task, but I already had one from a previous project that I had given up on.
Life on a farm is a school of patience; you can't hurry the crops or make an ox in two days.
Henri Alain
Life on a farm is a school of patience; you can't hurry the crops or make an ox in two days.
Henri Alain
Life on a farm is a school of patience; you can't hurry the crops or make an ox in two days.
Henri Alain
Mart Hale wrote:https://espeasy.readthedocs.io/en/latest/Plugin/P004.html
This is the documentation I followed with the espeasy to get my temp sensors. The esp 32 at $5.00 was the direction I went. The first one took a couple days to figure out, but the next one took only a few minutes to program and get setup...
Winn Sawyer wrote:
Mart Hale wrote:https://espeasy.readthedocs.io/en/latest/Plugin/P004.html
This is the documentation I followed with the espeasy to get my temp sensors. The esp 32 at $5.00 was the direction I went. The first one took a couple days to figure out, but the next one took only a few minutes to program and get setup...
I just spent quite awhile browsing that website and the espessif website trying to understand just the very basic question of what operating system runs on the ESP devices, but couldn't find an answer. Do they run some version of linux with a shell you can log into? Do you need to have special software on another computer to control and program the device?
I think this kind of issue is always my barrier to most alternatives to raspberry pi, such as Arduino. I like that the pi is just a little fully functional computer that runs a version of an operating system I already know how to use (Debian). I don't have to figure out the basic "how to use it," I just need to figure out new ways to use it.
Life on a farm is a school of patience; you can't hurry the crops or make an ox in two days.
Henri Alain
I was born with webbed fish toes. This tiny ad is my only friend:
Freaky Cheap Heat - 2 hour movie - HD streaming
https://permies.com/wiki/238453/Freaky-Cheap-Heat-hour-movie
|