PyPortal Weather Station by John Park

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Tom_Henry
 
Posts: 350
Joined: Wed Aug 26, 2020 8:19 pm

PyPortal Weather Station by John Park

Post by Tom_Henry »

I have having a problem with the PyPortal Weather Station project by John Park.

Here is a link to my problem area:

https://learn.adafruit.com/pyportal-wea ... cuitpython

I followed John’s directions to do the following:

Copy the contents of the PyPortal_OpenWeather directory to your PyPortal's CIRCUITPY drive, and then be sure to rename the openweather.py file to code.py so it will automatically run when the PyPortal restarts.

Note: I have attached a copy of the code.py from the above.

When I run the CircuitPython code I get the following errors:


code.py output:

Traceback (most recent call last):
File "code.py", line 9, in <module>
File "adafruit_pyportal/__init__.py", line 33, in <module>
File "adafruit_pyportal/network.py", line 31, in <module>
File "adafruit_portalbase/network.py", line 40, in <module>
File "adafruit_portalbase/network.py", line 37, in <module>
File "secrets.py", line 12
SyntaxError: invalid syntax

Code done running.

I have no idea how to fix these Syntax Errors as they are inside a module that I have no access to.

How can I fix this project and make it work?

Thanks,

Tom Henry
Attachments
code.py
(2.38 KiB) Downloaded 1 time

User avatar
dastels
 
Posts: 15653
Joined: Tue Oct 20, 2015 3:22 pm

Re: PyPortal Weather Station by John Park

Post by dastels »

The syntax error is in your secrets.py.

Dave

User avatar
Tom_Henry
 
Posts: 350
Joined: Wed Aug 26, 2020 8:19 pm

Re: PyPortal Weather Station by John Park

Post by Tom_Henry »

Not sure why you are saying that my secrets.py file is causing the syntax problem.

I followed this format for the secrets.py file:

# This file is where you keep secret settings, passwords, and tokens!
# If you put them in the code you risk committing that info or sharing it

secrets = {
'ssid' : 'home ssid',
'password' : 'my password',
'timezone' : "America/New_York", # http://worldtimeapi.org/timezones
'github_token' : 'fawfj23rakjnfawiefa',
'hackaday_token' : 'h4xx0rs3kret',
}

I filled it all the information correctly.

So, where do you think my syntax error would be in the above?

Tom Henry

User avatar
Tom_Henry
 
Posts: 350
Joined: Wed Aug 26, 2020 8:19 pm

Re: PyPortal Weather Station by John Park

Post by Tom_Henry »

Actually I used this format for the secrets.py file:

secrets = {
'ssid' : 'your_wifi_ssid',
'password' : 'your_wifi_password',
'openweather_token' : '1234567890',
'aio_username' : '_your_aio_username_',
'aio_key' : '_your_big_huge_super_long_aio_key_'
}

Tom Henry

User avatar
dastels
 
Posts: 15653
Joined: Tue Oct 20, 2015 3:22 pm

Re: PyPortal Weather Station by John Park

Post by dastels »

From the backtrace, you seem to have a syntax error on (or sometimes around) line 12.

Code: Select all

File "secrets.py", line 12
SyntaxError: invalid syntax
However, neither of those examples have 12 lines...

File "adafruit_portalbase/network.py", line 37 is

Code: Select all

from secrets import secrets
So it would appear that you have a problem with your secrets.py file. Unfortunately it's not something you want to be posting for review.

Dave

User avatar
Tom_Henry
 
Posts: 350
Joined: Wed Aug 26, 2020 8:19 pm

Re: PyPortal Weather Station by John Park

Post by Tom_Henry »

I decided to redo do this whole project, and follow John Park’s directions exactly from this web page:

https://learn.adafruit.com/pyportal-wea ... cuitpython

I was wondering while I was doing this: Do anyone at Adafruit ever recheck the various projects to see if they still work? My experience has been that most projects work just fine but some don’t.

1. First of all, I deleted all the files from my PyPortal CIRCUITPY.

2. The secrets file is exactly like the attached secrets screenshot with my information.

3. Then I followed these directions:

Copy the contents of the PyPortal_OpenWeather directory to your PyPortal's CIRCUITPY drive, and then be sure to rename the openweather.py file to code.py so it will automatically run when the PyPortal restarts.

I have attached the following files and screenshots:

1. CIRCUIT.png: John Park’s suggested contents for this project.

2. Secrets.png: The format I used for the secrets.py file.

3. Tom_Henry.png: Screenshot of all the files in my CIRCUITPY PyPortal drive after copying the contents above per the web page.

4. Copy of the code.py file that was created from John Park’s openweather.py file.

Here is the code.py output after attempting to run the code.py file:


code.py output:

Traceback (most recent call last):
File "code.py", line 9, in <module>
File "adafruit_pyportal/__init__.py", line 33, in <module>
File "adafruit_pyportal/network.py", line 31, in <module>
File "adafruit_portalbase/network.py", line 40, in <module>
File "adafruit_portalbase/network.py", line 37, in <module>
File "secrets.py", line 5
SyntaxError: invalid syntax

Code done running.

I am just doing this to give feedback to Adafruit and John Park.

I have done several other PyPortal projects that just work.

This project clearly does NOT work.

If anyone has an update to these files, or suggestions on how to fix this project, I would certainly appreciate that.

Tom Henry
Attachments
Tom_Henry PyPortal.png
Tom_Henry PyPortal.png (153.12 KiB) Viewed 93 times
secrets.png
secrets.png (66.44 KiB) Viewed 93 times
CIRCUITPY.png
CIRCUITPY.png (411.08 KiB) Viewed 93 times

User avatar
dastels
 
Posts: 15653
Joined: Tue Oct 20, 2015 3:22 pm

Re: PyPortal Weather Station by John Park

Post by dastels »

Can you

Code: Select all

from secrets import secrets
directly in the REPL?

As for projects no longer working, I don't know if anyone is checking existing guides when new version of CircuitPython or the libraries are released. Both CircuitPython and the libraries evolve quickly and freely. The library modules are usually a bigger problem in this regard. You can always try versions of CircuitPython and library bundle that were used when the project was published.

That said, the backtrace clearly looks like it's complaining about the secrets file. One thing to check for are invisible characters or odd line endings. Try typing the secrets file by hand (copy/pasting the long keys), from scratch, starting simply and adding entries one by one.

Dave

User avatar
Tom_Henry
 
Posts: 350
Joined: Wed Aug 26, 2020 8:19 pm

Re: PyPortal Weather Station by John Park

Post by Tom_Henry »

Dave,

Thank You!

You never gave up on me and continued to focus on a problem with the secrets.py file.

Well, I did as you said, I typed up the secrets file one line at a time.

It worked!

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”