Comments (24)
This is the number of sensors for each class of sensors (temperature, temperature/humidity, co2, pressure). It's used mainly to identify settings by being used as an array index, such as sensor_t_activated[sensor]. Yes, the 1 is added for display purposes to the user (logs, web interface).
from mycodo.
You'll probably notice the daemon runs with many global variables. I've been trying to be better at moving away from globals. I've found ways to make many of them local, but there's probably a lot more that can be done. I started creating the daemon with all globals, so it's a slow process to fix some of my initial mistakes.
from mycodo.
Would renaming sensor
to sensor_id
make sense to you? That way it isn't confused with a sensor object or anything besides an index.
Yeah there are a LOT of globals. I've been trying to suss out whether they were there for GPIO pins or if it was a coding style. Sounds like it is a coding style that you'd like to move away from. Your code works and people seem to enjoy it. I hope you aren't worried about the style mistakes. 😄
from mycodo.
I agree, sensor_id
makes more sense. 788 matches for the word 'sensor' 😦
I have a lot of bad coding style habits. I don't mind criticism, as long as I can learn something. I'm sure there are a lot of armature mistakes throughout all my code. I used to care only about functionality, but I also wanted to share my code. So I realized there needs to be a balance between functionality and readability.
from mycodo.
I'll make a pull request for this. One moment.
Just 709 that are the full word and not in comments or literals.
from mycodo.
Hmm... be careful not to do a blind find/replace.
This looks like a bug:
def exposed_ReadCO2Sensor(self, pin, sensor):
logging.info("[Client command] Read CO2 Sensor %s from GPIO pin %s", sensor, pin)
if sensor == 'K30':
read_co2_sensor(sensor - 1)
return sensor_co2_read_co2
else:
return 'Invalid Sensor Name'
It checks wether sensor
is a string and then tries to do math on it.
from mycodo.
Oh, I see it now. That is rather odd.
from mycodo.
Should be:
def exposed_ReadCO2Sensor(self, pin, sensor):
logging.info("[Client command] Read CO2 Sensor %s from GPIO pin %s", sensor, pin)
read_co2_sensor(sensor - 1)
return sensor_co2_read_co2
from mycodo.
...Another bad use of a global.
from mycodo.
Actually, this is what it should be:
def exposed_ReadCO2Sensor(self, device, sensor):
logging.info("[Client command] Read %s CO2 Sensor %s", device, sensor)
if device == 'K30':
return read_co2_sensor(sensor - 1)
else:
return 'Invalid Sensor Name'
from mycodo.
Don't you mean.... sensor_id
? haha
from mycodo.
Haha. Yeah. I actually did use sensor_id
in the commit. There was a lot to fix in that small function.
from mycodo.
So looking at the fixed exposed_ReadCO2Sensor
I notice that instead of doing +1
in the log string you are -1
when passing it to the read_co2_sensor
function. This is worth raising because some of your code does this the other way around.
Is there a reason to treat the sensor_ids differently here?
from mycodo.
When going from the stored value, the index starts at 0, so 1 must be added when presented to the user, but when receiving as a user input, 1 must be subtracted to reach the appropriate value that is stored in the database.
from mycodo.
The exposed functions are used to execute code from the mycodo-client.py script. I suppose we could have the client script subtract 1 before calling exposed_ReadCO2Sensor
from mycodo.
I think that would be right. We want to make sure that abstraction layers don't mix. The 'core' should act consistently and if you make a user layer you talk to the core using that language. The DISPLAY may show other stuff. If the relays were distinguished by color (red relay, blue relay, etc.) we would still have use the numeric address internally but it would be up to the UI to convert that into red/blue/etc so that the human would know which one we were referring to.
It isn't wasteful to have something like this:
def exposed_ReadCO2Sensor(self, device, sensor):
"""
User facing function takes sensor_id as numbered on webpage.
"""
return readco2sensor(self, device, sensor - 1)
def readco2sensor(self,device, raw_sensor_id):
"""
Internal implementation of readco2sensor. May change over time or as sensors are added. Consistent internal notation
"""
logging.info("[Client command] Read %s CO2 Sensor %s", device, raw_sensor_id + 1)
if device == 'K30':
return read_co2_sensor(raw_sensor_id)
else:
return 'Invalid Sensor Name'
from mycodo.
Got all sensor functions created as per that template, but getting this error when I test one:
File "/var/www/mycodo/cgi-bin/mycodo.py", line 364, in exposed_ReadHTSensor
return readhtsensor(self, device, sensor_id - 1)
NameError: global name 'readhtsensor' is not defined
from mycodo.
Ah, think I need to call self.readhtsensor()
from mycodo.
yep that would do it. :)
from mycodo.
Success!
kiz@tango:www/mycodo$ ./cgi-bin/mycodo-client.py --sensorht DHT22 1 11/25/15 12:54 AM
2015 11 25 00 55 00 [Remote command] Read DHT22 HT sensor 1
2015 11 25 00 55 02 [Remote Command] Daemon Returned: Temperature: 25.9°C Humidity: 36.6%
from mycodo.
All finished. T, HT, CO2, and Press sensor querying from mycodo-client now working with the new functions.
from mycodo.
I'm going to have to start getting to bed earlier. I live on the east coast, so I'm a few hours ahead of you. Luckily it's a slow week and I can sleep in until noon, and I've thoroughly enjoyed the late-night programming sessions, but our schedules don't quite align. You may start to see me drop out around midnight EST, instead of 4am / 5am.
from mycodo.
Good. Sleep is good. haha :)
On Wed, Nov 25, 2015 at 2:57 PM, Kyle Gabriel [email protected]
wrote:
I'm going to have to start getting to bed earlier. I live on the east
coast, so I'm a few hours ahead of you. Luckily it's a slow week and I can
sleep in until noon, and I've thoroughly enjoyed the late-night programming
sessions, but our schedules don't quite align. You may start to see me
drop out around midnight EST, instead of 4am / 5am.—
Reply to this email directly or view it on GitHub
#57 (comment).
from mycodo.
Seems we've fully explored this topic. closing...
from mycodo.
Related Issues (20)
- sensors stop giving readings after an hour or two and wont reinitialize without a power cycle HOT 2
- urllib camera numpy issue HOT 21
- Permission denied when saving Conditional Controller Function HOT 4
- request to add Adafruit NeoKey 1x4 input board HOT 69
- Request to add DFRobot i2c DAC output module (0-10v) HOT 43
- PCF8575 activating multiple /wrong outputs on PCF8575 16 Channel Relay module HOT 11
- Add notes via API HOT 5
- Zigbee2MQTT Plugin for Mycodo HOT 3
- Bang-Bang controller hangs randomly. Can not acquire a measurement, but all inputs and calculation Functions are working with no errors. HOT 3
- issue with TCA9548a multiplexer HOT 6
- Python 3 code(v2.0) not showing output HOT 12
- Blank Widgets HOT 10
- mycodo ERROR - mycodo.influx - Unknown Influxdb version: HOT 3
- Action - Ramp Value
- add ability to copy a function
- Request to add DFRobot i2c Fermion: LWLP5000 Differential Pressure Sensor (±500pa)
- Allow setting the same output für PID Controller and PID Autotune
- request add Days Counter with advanced functions
- PID widgets display null instead of negative values HOT 12
- Volume Flow Rate in Gallons as well as Liters HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mycodo.