-
-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Sensor Results from Serial (Arduino) #124
Comments
Euh, is the cronjob that is gathering the data once a minute on the same Pi as where my software is running... then there is a very easy way to do it. The following code could do it:
Then you are able to add an external sensor according to: https://github.com/theyosh/TerrariumPI/wiki/Remote-data Use in this example the following url: http://[Pi_IP:8090]/static/sensors.json#temperature1 for reading out one temperature sensor. I hope it is clear what I try to explain and helps you out |
Many Thanks I understand and follow completely. I tested the py script with the added lines in terminal and get: SyntaxError: Non-ASCII character '\x93' in file water.py on line 12, but no enco ding declared; see http://python.org/dev/peps/pep-0263/ for details some missing code or i'm placing the code in the wrong file. |
Works with edit below: with open("/home/pi/TerrariumPI/static/sensors.json","r+") as sensordata: sensordata.write('{"temperature1": %s, "distance": %s}' % (pieces[4],pieces[6])) |
Cool! my code was just to give an idea. So you should extend it so it contains all your sensors. And I think that is not that hard to do. |
Great work! Got that all sorted and working like a charm. Thanks for that I thought it would be a nightmare but it was quite easy. I was wondering if its easy enough to add more tanks,light etc in System environment? one more tank and that shows the level/Litre by default as well as / instead of when the sensor option is applied. I have a timer set for my pump to feed 15 on 15 off (works well but without Water Level/Distance indicator ) I have no refill needs in the way of automation not as yet anyway. |
No, at the moment my software is for a single terrarium system. Sorry, but it will be a lot more complicated when you want to control more devices. So for now, it will not be. But cool that adding data from an external analog device is working |
Thats fine I can deal with that.. |
Just did...
And it should be there... use 0 for closed and 1 for open |
I have made a quick and simple edit to profile.tpl adding a calendar widget from google using the url below and pasting it in just before footer: My Code: <iframe src="https://calendar.google.com/calendar/embed?showTitle=0&showPrint=0&showCalendars=0&showTz=0&height=600&wkst=2&hl=en_GB&bgcolor=%23FFFFFF&src=YOURCALENDARNAME%40gmail.com&color=%2329527A&ctz=Europe%2FLondon" style="border-width:0" width="100%" height="600" frameborder="0" scrolling="no"></iframe>
I changed the width to 100% to fit into browser window. Works really well and I can now set tasks/events/schedules etc.. Just have to remember to select the calendar you want to see in the setting page from google otherwise your tasks/events/schedules will not show up. Just wanted to share this with you as it was just so easy to do and you may like to use it. |
Clear browser cache... you have an old css file now loaded. In CSS the frame is 100% width and 400px height |
Thanks that worked and looks fab. I'll remember to do that if I ever edit css scripts again school boy error again lol. If you could help me please. I had this same issue since I installed the software about a month ago where the webcam dir gets full of jpg files and only shows a still shot on the front end. I have removed all files out the dir and refreshed to make sure the dir is still clear for a 1 min or so then refreshed / landed back on the webcam page. the dir is full up again to the exact file name ( de2b8d7f52f0d204cc7667a23b2a7902_tile_3_7_7.jpg ). it like the permissions are wrong and it cant stream some how? |
Euh... this is working like expected. The webcam is just a still image with zoom levels like google maps. That is all. There is no streaming. The webcam is update once a minute. Those files are correct, and will be refreshed every minute. I had explained before. Streaming is not an option due to needed CPU power. That will not be stable with all the sensors and timings Also, please do not start different issues here.. This issue is closed. Please open a new one when you have a problem. Also, try to see if there is not a closed issue that explains your problem. |
hello, I followed the procedure here above, I get my datas (Arduino) in a json from my python script, T °, distance, etc. By cons when I insert the path of the json as remote temperature sensor I have this error: 2018-04-04 22: 07: 59,000 - INFO - terrariumWrapper - Starting TerrariumPI server at location: http://192.168.1.61:8090 ... An idea ? |
Yes! This happens only during startup. The TerrariumPI webserver is the last part that is started. So the sensors are loaded before the webserver is loaded and cannot read the 'remote' data . And therefore, it will give a warning when you start the software, but in 30 seconds it should update normally and no errors should be given. |
Note... Not an Issue just a question..
I've managed put this py script together from another project (probably porly) to receive data from the arduino mega through serial with multiple sensors readings split into pieces on one line then received by the Raspberry PI 3 on usb port x and insert into a sql database. I would run this script once a minute through crobtab.
Hardware used for 2 water tanks:
Results from running Script in terminal:
1 46 40.70 24.50 17.56 2 47 41.60 24.00 19.50
Tank 1
40.70
Humidity_Distance_1
Tank 2
41.60
Humidity_Distance_2
Python Script:
#!/usr/bin/env python
import datetime
import serial
import time
import MySQLdb as mdb
arduino= serial.Serial("/dev/ttyUSB0")
arduino.baudrate=9600
data = arduino.readline()
pieces = data.split("\t")
now = datetime.datetime.now()
con= mdb.connect('localhost','root','XXXXXX','water');
with con:
cursor=con.cursor()
cursor.execute("INSERT INTO level (date_time,sensor,level,hum,temp) VALUES (%s,%s,%s,%s,%s)",(now,pieces[0],pieces[1],pieces[2],pieces[3]))
cursor.execute("INSERT INTO level (date_time,sensor,level,hum,temp) VALUES (%s,%s,%s,%s,%s)",(now,pieces[5],pieces[6],pieces[7],pieces[8]))
cursor.execute("INSERT INTO temp (date_time,sensor,temp) VALUES (%s,%s,%s)",(now,pieces[0],pieces[4]))
cursor.execute("INSERT INTO temp (date_time,sensor,temp) VALUES (%s,%s,%s)",(now,pieces[5],pieces[9]))
con.commit()
cursor.close()
print pieces[0],pieces[1],pieces[2],pieces[3],pieces[4],pieces[5],pieces[6],pieces[7],pieces[8],pieces[9]
Arduino Sketch:
// Include DHT Libraries from Adafruit
// Dependant upon Adafruit_Sensors Library
#include "DHT.h"
// Include NewPing Library
#include "NewPing.h"
// DS Library
#include <OneWire.h>
#include <DallasTemperature.h>
// Define Constants
#define DHTPIN_1 12 // DHT-22 Output Pin connection
#define DHTPIN_2 13 // DHT-22 Output Pin connection
#define DHTTYPE DHT22 // DHT Type is DHT 22 (AM2302)
#define TRIGGER_PIN_1 2
#define ECHO_PIN_1 3
#define TRIGGER_PIN_2 4
#define ECHO_PIN_2 5
#define MAX_DISTANCE 400
#define WATER_TEMP_1 6
#define WATER_TEMP_2 7
NewPing sonar1(TRIGGER_PIN_1, ECHO_PIN_1, MAX_DISTANCE);
NewPing sonar2(TRIGGER_PIN_2, ECHO_PIN_2, MAX_DISTANCE);
OneWire oneWire1(WATER_TEMP_1);
DallasTemperature watertemp1(&oneWire1);
OneWire oneWire2(WATER_TEMP_2);
DallasTemperature watertemp2(&oneWire2);
// Define Variables
float hum1; // Stores humidity value in percent
float temp1; // Stores temperature value in Celcius
float hum2; // Stores humidity value in percent
float temp2; // Stores temperature value in Celcius
float duration1; // Stores First HC-SR04 pulse duration value
float duration2; // Stores Second HC-SR04 pulse duration value
float distance1; // Stores calculated distance in cm for First Sensor
float distance2; // Stores calculated distance in cm for Second Sensor
int iterations = 5;
float Celcius1=0;
float Celcius2=0;
// Initialize DHT sensor for normal 16mhz Arduino
DHT dht1(DHTPIN_1, DHTTYPE);
DHT dht2(DHTPIN_2, DHTTYPE);
void setup() {
Serial.begin (9600);
dht1.begin();
dht2.begin();
watertemp1.begin();
watertemp2.begin();
}
void loop()
{
// Measure duration for first sensor
duration1 = sonar1.ping_median(iterations);
// Add a delay between sensor readings
delay(10);
// Measure duration for first sensor
duration2 = sonar2.ping_median(iterations);
delay(10); // Delay so DHT-22 sensor can stabalize
hum1 = dht1.readHumidity(); // Get Humidity value
temp1= dht1.readTemperature(); // Get Temperature value
hum2 = dht2.readHumidity(); // Get Humidity value
temp2= dht2.readTemperature(); // Get Temperature value
watertemp1.requestTemperatures();
Celcius1= watertemp1.getTempCByIndex(0);
watertemp2.requestTemperatures();
Celcius2= watertemp2.getTempCByIndex(0);
// Calculate the distances for both sensors
long t1 = 0, h1 = 0, hp1 = 0, t2 = 0, h2 = 0, hp2 = 0, hpL1 = 0, hpL2 = 0;
// Waiting for pulse
t1 = duration1 + (0.606 * temp1) + (0.0124 * hum1);
t2 = duration2 + (0.606 * temp2) + (0.0124 * hum2);
// Calculating distance 1
h1 = t1 / 10;
h1 = h1 - 50; // offset correction
h1 = 30 - h1; // water height, 0 - 50 cm
hp1 = 2 * h1; // distance in %, 0-100 %
hpL1 = hp1*100/70/2; // Letre based on 70 litres at 100%
// Calculating distance 2
h2 = t2 / 10;
h2 = h2 - 50; // offset correction
h2 = 30 - h2; // water height, 0 - 50 cm
hp2 = 2 * h2; // distance in %, 0-100 %
hpL2 = hp2*100/70/2; // Letre based on 70 litres at 100%
// Sending to computer
Serial.print("1");
Serial.print("\t"); // for splitting
Serial.print(hpL1);
Serial.print("\t"); // for splitting
Serial.print(hum1);
Serial.print("\t"); // for splitting
Serial.print(temp1);
Serial.print("\t"); // for splitting
Serial.print(Celcius1);
Serial.print("\t"); // for splitting
Serial.print("2");
Serial.print("\t"); // for splitting
Serial.print(hpL2);
Serial.print("\t"); // for splitting
Serial.print(hum2);
Serial.print("\t"); // for splitting
Serial.print(temp2);
Serial.print("\t"); // for splitting
Serial.print(Celcius2);
Serial.println(" ");
delay(1000);
}
My question:
I would like to be able to add a sensor from sensor setting page and select serial port(number), piece [number] with current setting already in place. I think this would really help add more hardware to this project.
ie..
The text was updated successfully, but these errors were encountered: