-
PROHARDVER!
Amit érdemes tudni a Raspberry Pi-kről:
A legelső változat 2012-ben jelent meg. Pici, olcsó és nagyon alacsony fogyasztású, hobby-célú kártyagép. Felépítése ARM alapú, nem PC-architektúra, hanem kb. egy régi mobilhoz hasonló. Nagyon sok mindenre használható! A Linux-nak és a magas eladási mennyiségnek köszönhetően jelentős fejlesztőtáborral rendelkezik.
Új hozzászólás Aktív témák
-
D@reeo
aktív tag
Üdv
Kezdek belebolondulni ebbe a hőmérős projectbe.
Elméletileg minden a helyén van, de az adatbázisba mégse menti le mért értékeket.
pollSensors.py (itt a 38. sorban kell a nonce = nonce.encode('utf-8'), különben hibát dob, de lehet, hogy pont e miatt nem menti le az adatbázisba)import requests
import hashlib
import time
#Dont forget to fill in PASSWORD and URL TO saveTemp (twice) in this file
sensorids = ["28-00000509be8b", "28-00000535993e"]
avgtemperatures = []
for sensor in range(len(sensorids)):
temperatures = []
for polltime in range(0,3):
text = '';
while text.split("\n")[0].find("YES") == -1:
# Open the file that we viewed earlier so that python can see what is in it. Replace the serial number as before.
tfile = open("/sys/bus/w1/devices/"+ sensorids[sensor] +"/w1_slave")
# Read all of the text in the file.
text = tfile.read()
# Close the file now that the text has been read.
tfile.close()
time.sleep(1)
# Split the text with new lines (\n) and select the second line.
secondline = text.split("\n")[1]
# Split the line into words, referring to the spaces, and select the 10th word (counting from 0).
temperaturedata = secondline.split(" ")[9]
# The first two characters are "t=", so get rid of those and convert the temperature from a string to a number.
temperature = float(temperaturedata[2:])
# Put the decimal point in the right place and display it.
temperatures.append(temperature / 1000)
avgtemperatures.append(sum(temperatures) / float(len(temperatures)))
print avgtemperatures[0]
print avgtemperatures[1]
session = requests.Session()
nonce = session.get(url='http://localhost/saveTemp.php?step=nonce').text
nonce = nonce.encode('utf-8')
response = hashlib.sha256(nonce + 'root' + str(avgtemperatures[0]) + str(avgtemperatures[1])).hexdigest()
post_data = {'response':response, 'temp1':avgtemperatures[0], 'temp2': avgtemperatures[1]}
post_request = session.post(url='http://localhost/saveTemp.php', data=post_data)
if post_request.status_code == 200 :
print post_request.textsaveThemp.php
<?php
// set the defines here, and the mysqli info on line 24
// make sure you have an temps table with floats for temp1 and temp2 and created_at (timestamp)
// make sure you have an alerts table with floats for avgtemp1 and avgtemp2, open (boolean, default: true) and created_at (timestamp)
define("PASSWORD","root");
session_start();
$mysqli = initDB();
if($_GET['step'] == 'nonce') {
getNonce();
} else if (isset($_POST['response']) && isset($_POST['temp1']) && isset($_POST['temp2'])) {
checkAuthenticationResponce();
processEntry($mysqli);
}
$mysqli->close();
function initDB() {
$mysqli = new mysqli("localhost", "root", "root", "temp");
/* check connection */
if ($mysqli->connect_errno) {
header("HTTP/1.0 500 Internal Server Error");
exit();
}
return $mysqli;
}
function checkAuthenticationResponce() {
if(!isset($_SESSION['tempNonce']) || hash('sha256', $_SESSION['tempNonce'] . PASSWORD . $_POST['temp1'] . $_POST['temp2']) != $_POST['response']) {
header("HTTP/1.0 401 Authorization Required");
exit;
} else {
unset($_SESSION['tempNonce']);
}
}
function getNonce() {
$_SESSION['tempNonce'] = hash('sha256', '1321421412412452354235325' . time());
echo $_SESSION['tempNonce'];
}
function processEntry($mysqli) {
$temp1 = floatval($_POST['temp1']);
$temp2 = floatval($_POST['temp2']);
$stmt = $mysqli->prepare("INSERT INTO temps (temp1, temp2) VALUES(?,?)");
$stmt->bind_param('dd', $temp1, $temp2);
if ($stmt->execute() === true) {
echo "added";
} else {
header("HTTP/1.0 500 Internal Server Error");
}
}
?>Ha kézzel viszek be értékeket, akkor azokat kirajzolja a grafilonra. Ha kézzel futtatom a var/www/pollSensors.py-t, akkor kiírja a 2 értéket, de az adatbázisba nem menti le.
mysql user: localhost,root, rootAdatbázis szerkezet:
-- phpMyAdmin SQL Dump
-- version 3.4.11.1deb2+deb7u1
-- http://www.phpmyadmin.net
--
-- Hoszt: localhost
-- Létrehozás ideje: 2015. febr. 08. 19:38
-- Szerver verzió: 5.5.41
-- PHP verzió: 5.4.36-0+deb7u3
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Adatbázis: `temp`
--
-- --------------------------------------------------------
--
-- Tábla szerkezet: `temps`
--
CREATE TABLE IF NOT EXISTS `temps` (
`temp1` float NOT NULL,
`temp2` float NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- A tábla adatainak kiíratása `temps`
--
INSERT INTO `temps` (`temp1`, `temp2`, `created_at`) VALUES
(21, 11, '2015-02-08 12:59:35'),
(41, 61, '2015-02-08 12:59:51');
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;Mi a francnak nem menti le az adatbázisba az értékeket? Köszi
Új hozzászólás Aktív témák
- Honor Magic6 Pro - kör közepén számok
- Milyen billentyűzetet vegyek?
- Elemlámpa, zseblámpa
- AMD GPU-k jövője - amit tudni vélünk
- Adobe Photoshop
- iPhone topik
- Diablo II: Classic és Resurrected
- Audi, Cupra, Seat, Skoda, Volkswagen topik
- A Galaxy S26-tal együtt késik a One UI 8.5
- Futás, futópályák
- További aktív témák...
- Dell Optiplex 3080 micro, i3-10105T (4 mag, 8 szál), 8GB RAM, 256GB SSD, Bővíthető
- i5 9600K GEFORCE RTX 2060 6GB DDR6 16GB RAM Gamer PC
- Intel Core i9-9900K, Gigabyte Z390 AORUS Master, Noctua NH-D15
- Ryzen 7 kezdő 1080p játszós konfig + 27" LG IPS LED monitor!
- ÚJ ASUS CORE I5 14400F Gamer MAX PC 10X4.6GHz 32GB DDR5 1.0TB SSD NVIDIA RTX 3060TI 8GB DDR6 2ÉV GAR
- GYÖNYÖRŰ iPhone 13 128GB Starlight -1 ÉV GARANCIA - Kártyafüggetlen, MS3437, 100% Akkumulátor
- Okosóra felvásárlás!! Samsung Galaxy Watch 5 Pro, Samsung Galaxy Watch 6 Classic
- BESZÁMÍTÁS! Gigabyte H610M i5 12400F 32GB DDR4 512GB SSD RTX 3070 8GB Zalman Z1 PLUS A-Data 750W
- ÚJ ASUS ROG Hyperion GR701 E-ATX RGB Gépház
- Számlás!Windows 10 Pro 11 Pro,Windows 10 Home 11 Home, Office 2016,2019,2021 ,Vírusirtok,Mac
Állásajánlatok
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest
Cég: Promenade Publishing House Kft.
Város: Budapest

wassermann

