ve3sjk / SkyWeather-Python-3

Python3 Port of SkyWeather
1 stars 2 forks source link

Argument Error #1

Open pjockey opened 2 years ago

pjockey commented 2 years ago

I'm trying to get this weather station to run on your Python3 code and I get the following error:

Entering blynkInit debug mode: False
Traceback (most recent call last):
  File "SkyWeather.py", line 1570, in <module>
    pclogging.log(pclogging.INFO, __name__, "SkyWeather Startup Version"+config.SWVERSION )
  File "/home/pi/SkyWeather-Python-3/pclogging.py", line 54, in log
    con = mdb.connect(config.MySQL_Address, config.MySQL_User, config.MySQL_Password, config.MySQL_Database2);
TypeError: __init__() takes 1 positional argument but 5 were given
pi@SkyWeather:~/SkyWeather-Python-3 $ 
ve3sjk commented 2 years ago

I have not really worked much on the code in awhile this code may be outdated to what is currently running on my Pi4.

You may also need to rename your working folder to just SDL_Pi_SkyWeather

I may also need to dump the file and folder permission file from my working unit, not sure if there is a way to create a script to do that perhaps someone reading this can provide some help on that part.

I also currently start it with python and not python3 command.

Did you make a conflocal.py file and setup your database for pclogging, in my case i am using MySQL on another computer running Ubuntu server so this is what that section looks like in my local config file of course change the password and user to whatever is setup on your system. Most of my data goes into enviro1 which is a custom database i may be able to export the structure although i am not sure.

This is the config section for logging.

#MySQL Logging and Password Information enable_MySQL_Logging = True MySQL_Password = "xxxxxxx" MySQL_Address = "192.168.1.207" MySQL_User = "xxxx" MySQL_Database = "enviro1" MySQL_Database2 = "SkyWeather"

pjockey commented 2 years ago

Here is the section of my conflocal.py. I've tried different database files names and nothing seems to work. I'm still getting the same error. Renamed the main directory to SDL_Pi_SkyWeather as well.

Your python is probably set to default to python3, hence the "python" command. Mine won't start with the plain python command.

#MySQL Logging and Password Information
enable_MySQL_Logging = True
MySQL_Password = ""
MySQL_Address = "192.168.1.238"
MySQL_User = ""
MySQL_Database = "SkyWeather"
MySQL_Database2 = "SkyWeather"
pjockey commented 2 years ago

k, making slow progress. The previous errors seemed to have been proper access to the mysql program, re-ran sudo mysql_secure_installation and allowing remote access, since it technically is using ssh/vnc.

Now, I had to add a couple of items to the conflocal.py file to show them as a config item.

MP503_Present = False WatchDog_Present = False

Now I'm getting an error and I'm very sure it has to do with mysql. One of the schemas is missing a table item called Tanks_log. Not sure how to add this, but I will poke around.

Weather Sampling
----------------- 
trying database
Connected to database:
query=INSERT INTO Tanks_Log(T, TT, T1, T2, T3, T4 ) VALUES (CURRENT_TIMESTAMP,30.11, 68.76, 52.23, 0.00, 0.00)
Error 1146: Table 'SkyWeather.Tanks_Log' doesn't exist
--Sending Data to WeatherUnderground--
success

I'm not getting any reading for the wind either. Any thoughts on that?

Thanks

Scott

ve3sjk commented 2 years ago

I am sending data to two different databases, it uses the default Skyweather for functions in the software the required it to run but i had a custom database already made that uses a lot more sensors and functions.

If you want to use it you will need to add that as below for database and database2

<#MySQL Logging and Password Information enable_MySQL_Logging = True MySQL_Password = "xxxxx" MySQL_Address = "192.168.1.207" MySQL_User = "xxxxx" MySQL_Database = "enviro1" MySQL_Database2 = "SkyWeather">

Give it the same permissions as the stock one.

I also use "root" on my system and not stock that needs SU all the time.

I am not sure it will work but i added below a custom export of the structure on my enviro1 database, i did not included the data since i have at least 5 years of it making it pretty hefty for transfer, in my case the database is on a different server and not one the raspberry Pi running skyweather. I used the PHPadmin custom export to make the file.

enviro1.zip

Some of the tables are not used by skyweather in the database i have a mega2560 with my own software on it running a multitude of other sensors also sending to the database as well using the SQLconnector library.

Try testWeatherRack.py for your wind speed, are you seeing the direction if not you may have the connectors backwards on the skyweather board for the weather rack and rain bucket if you are using it.

You also need wires on the weather out jack JP3 to the inputs of the raspberry pi

<#WeatherRack anemometerPin = 13 rainPin = 6>

pjockey commented 2 years ago

I have the confre local.py setup the sme as you shown below.

#MySQL Logging and Password Information
enable_MySQL_Logging = True
MySQL_Password = ""
MySQL_Address = "127.0.0.1"
MySQL_User = ""
MySQL_Database = "enviro1"
#MySQL_Database2 = "SkyWeather"

I had to comment out the last line as it throws up all kinds of errors about the the mysql database. With it commented out, it seems to work very well. There are database errors that thrown up every once an a while and I think it is because there are no tables in the enviro1 database, but are in the SkyWeather.

BarometerLightningGraph running now
trying database
before query
query=INSERT INTO PowerSystem(TimeStamp, batteryVoltage, batteryCurrent, solarVoltage, solarCurrent, loadVoltage, loadCurrent, batteryPower, solarPower, loadPower, batteryCharge) VALUES (UTC_TIMESTAMP (), 4.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000)
Connected to database:
Error 1146: Table 'enviro1.PowerSystem' doesn't exist
query=INSERT INTO Tanks_Log(T, TT, T1, T2, T3, T4 ) VALUES (CURRENT_TIMESTAMP,30.06, 69.85, 50.26, 0.00, 0.00)
query= SELECT T, TT, T1, T2 FROM Tanks_Log where  now() - interval 240 hour < T
count of t= 1525
--Sending Data to WeatherUnderground--
success

I don't know was is wrong with the second database.

The wind readings were all my fault. The unit is sitting on my work bench in the basement and is not attached to the wind reading cables. So I guess there would be not readings. I'm going to take it back outside this weekend see if I can keep it running.

ve3sjk commented 2 years ago

This is confusing me a bit from your error

Error 1146: Table 'enviro1.PowerSystem' doesn't exist

Since enviro1 does not contain a table called that the result of that command should end up in the original SkyWeather database and not enviro1.

You need to import the enviro.sql file in the zip i attached to last message this should create a separate database in MySQL called enviro1 with my tables in it.

You should see enviro1 and Skyweather database in the root of your MySQL like in the phpAdmin screenshots attached.

phpmyadminroot

SkyweatherDATA

This is my database below, it has a lot more tables as the mega2560 code i have can also be used for auto watering schedules and it keeps track of the amount of rainwater in my two 1000 gallon tanks, it has a webpage as well i added a couple of screenshots of it.

My intention is to eventually make it all one system although there are things i can do on the mega2560 and not the raspberry pi as its not a real time operation system.

enviro1DATA

Screenshots of Enviro1 web front end running as python file on my main Ubuntu web server machine.

enviro1web

enviro1_garage

enviro1_greenhouse

pjockey commented 2 years ago

Databases and tables in enviro1 and SkyWeather are shown below. These are the same as yours. Myphpadmin nor installed yet.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| SkyWeather         |
| WeatherPi          |
| enviro1            |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
6 rows in set (0.002 sec)
MariaDB [SkyWeather]> show tables;
+----------------------+
| Tables_in_SkyWeather |
+----------------------+
| PowerSystem          |
| Sunlight             |
| WeatherData          |
| systemlog            |
+----------------------+
4 rows in set (0.001 sec)
MariaDB [enviro1]> show tables;
+-------------------+
| Tables_in_enviro1 |
+-------------------+
| AS3935_Registers  |
| Arduino           |
| Baro              |
| CO2               |
| Camera            |
| Chem_Log          |
| Disturber         |
| Disturber_Log     |
| Email             |
| Geophys_Log       |
| Light             |
| Light_Schedule    |
| Lightning         |
| Lightning_Log     |
| Lightning_Update  |
| Noise             |
| Noise_Log         |
| Optics_Log        |
| RH                |
| Relays            |
| Sensors_Log       |
| TDS1              |
| TDS2              |
| Tank1             |
| Tank2             |
| Tank3             |
| Tank4             |
| TankTotal         |
| Tanks_Log         |
| Temp              |
| TempP0            |
| TempP1            |
| TempP2            |
| TempP3            |
| TempP4            |
| Temps_Log         |
| UVI_0             |
| Watering_Schedule |
| pH1               |
| pH2               |
+-------------------+
40 rows in set (0.002 sec)

Then I uncomment the line MySQL_Database2 = SkyWeather, add the config.MySQL_Database2into the pclogging.py and SkyWeather.py and when I run the script, I get the error below.

Error 2003: Can't connect to MySQL server on '192.168.1.238' ([Errno -8] Servname not supported for ai_socktype)
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 583, in connect
    **kwargs)
  File "/usr/lib/python3.7/socket.py", line 707, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib/python3.7/socket.py", line 748, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -8] Servname not supported for ai_socktype

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/SDL_Pi_SkyWeather/pclogging.py", line 54, in log
    con = mdb.connect(config.MySQL_Address, config.MySQL_User, config.MySQL_Password, config.MySQL_Database, config.MySQL_Database2);
  File "/usr/lib/python3/dist-packages/pymysql/__init__.py", line 94, in Connect
    return Connection(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 325, in __init__
    self.connect()
  File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 630, in connect
    raise exc
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '192.168.1.238' ([Errno -8] Servname not supported for ai_socktype)")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "SkyWeather.py", line 1571, in <module>
    pclogging.log(pclogging.INFO, __name__, "SkyWeather Startup Version"+config.SWVERSION )
  File "/home/pi/SDL_Pi_SkyWeather/pclogging.py", line 70, in log
    con.rollback()
UnboundLocalError: local variable 'con' referenced before assignment

You have a lot more sensors on your system than I do. I have the basic SkyWeather 1 connected to a SolarMax2.

pjockey commented 2 years ago

Went thru the code, python2 to python2, and made the python3 exactly the same as the previous. Cut back to the one mysql database and everything seems to work now.

Now to get it mounted and see if I can ssh into it.