Skip to content

I added a reset after a certain number of connection attempts. #6

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

Merged
merged 9 commits into from
Feb 19, 2019

Conversation

makermelissa
Copy link
Collaborator

This is to address #5.

@ladyada
Copy link
Member

ladyada commented Feb 18, 2019

looks ok stylistic, if jerry wants to try it!

@jerryneedell
Copy link
Contributor

I'll try it -- it will only help if _esp_is_connected goes False -- I' don't know if that was the case.
may be a few hours before I can setup and start a test -- then typically 12 hours before a failure...

@makermelissa
Copy link
Collaborator Author

Yeah, if we notice it's happening in the get portion of it, we can move it. I was just trying to keep it clean and you mentioned it hit the connection error portion when you did experience the error.

@jerryneedell
Copy link
Contributor

jerryneedell commented Feb 18, 2019

it was just looping gin the "get" loop and failing very quickly -- I don think it was attempting to reconnect.
I do have some time so I can set up a test

@makermelissa
Copy link
Collaborator Author

I found an error in my code and just pushed again.

@jerryneedell
Copy link
Contributor

jerryneedell commented Feb 18, 2019

was the error you fixed causing this -- I get it sometimes -- then it works on reboot

uto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
ESP32 SPI webclient test
Fetching json from https://api.thingspeak.com/channels/1417/feeds.json?results=1
Failed to connect, retrying
('No such ssid', b'Needell Airport')
Traceback (most recent call last):
 File "code.py", line 50, in <module>
 File "code.py", line 41, in <module>
 File "adafruit_esp32spi/adafruit_esp32spi_wifimanager.py", line 105, in get
 File "adafruit_esp32spi/adafruit_esp32spi_wifimanager.py", line 90, in connect
 File "adafruit_esp32spi/adafruit_esp32spi_wifimanager.py", line 86, in connect
TypeError: unsupported types for __ge__: 'int', 'Pin'

@makermelissa
Copy link
Collaborator Author

Yeah, please try again. I found that too and already pushed the fix.

@jerryneedell
Copy link
Contributor

actually -- it already failed as in my original case so the reset is not helping where it is

Fetching json from https://api.thingspeak.com/channels/1417/feeds.json?results=1
{'channel': {'id': 1417, 'latitude': '40.5', 'name': 'CheerLights', 'longitude':
 '-80.22', 'updated_at': '2018-07-20T01:05:15Z', 'description': 'CheerLights is 
an \u201cInternet of Things\u201d project created by Hans Scharler that allows p
eople\u2019s lights all across the world to synchronize to one color set by Twit
ter. This is a way to connect physical things with social networking experiences
.', 'last_entry_id': 533101, 'field2': 'CheerLights HEX Color', 'field1': 'Last 
CheerLights Command', 'created_at': '2011-12-01T03:30:04Z'}, 'feeds': [{'created
_at': '2019-02-18T17:14:11Z', 'field2': '#FFA500', 'field1': 'orange', 'entry_id
': 533101}]}
[{'created_at': '2019-02-18T17:14:11Z', 'field2': '#FFA500', 'field1': 'orange',
 'entry_id': 533101}]
{'created_at': '2019-02-18T17:14:11Z', 'field2': '#FFA500', 'field1': 'orange', 
'entry_id': 533101}
#FFA500
Fetching json from https://api.thingspeak.com/channels/1417/feeds.json?results=1
Failed to get data, retrying
 Failed to request hostname
Fetching json from https://api.thingspeak.com/channels/1417/feeds.json?results=1
Failed to get data, retrying
 Failed to request hostname
Fetching json from https://api.thingspeak.com/channels/1417/feeds.json?results=1
Failed to get data, retrying

@makermelissa
Copy link
Collaborator Author

Ok, I'll refactor.

@makermelissa
Copy link
Collaborator Author

Ok, try again @jerryneedell. It seems to be working on my end.

@jerryneedell
Copy link
Contributor

your note says you added it to get and post, but I only see it in get...

@makermelissa
Copy link
Collaborator Author

That's odd. let me try pushing again...

@makermelissa
Copy link
Collaborator Author

I hadn't hit save after adding it to post.

@jerryneedell
Copy link
Contributor

ok - started a new test -- I am a bit concerned the attempts=1 is too strict, especially for the connect test - mine often fails on the first try but works on the second - it did work even after failing and resetting when I started this test so it may be OK.

@makermelissa
Copy link
Collaborator Author

Just pass it something bigger on init.

@jerryneedell
Copy link
Contributor

sure -- that's fine if you want 1 for the default, just checking. test is running -- hopefully it with generate an error soon.... or maybe not...

@jerryneedell
Copy link
Contributor

well -- this failed and did not recover as it did for my example -- not sure why

#800080
Fetching json from https://api.thingspeak.com/channels/1417/feeds.json?results=1
{'channel': {'id': 1417, 'latitude': '40.5', 'name': 'CheerLights', 'longitude': '-80.22', 'updated_at': '2018-07-20T01:05
:15Z', 'description': 'CheerLights is an \u201cInternet of Things\u201d project created by Hans Scharler that allows peopl
e\u2019s lights all across the world to synchronize to one color set by Twitter. This is a way to connect physical things 
with social networking experiences.', 'last_entry_id': 533104, 'field2': 'CheerLights HEX Color', 'field1': 'Last CheerLig
hts Command', 'created_at': '2011-12-01T03:30:04Z'}, 'feeds': [{'created_at': '2019-02-18T19:47:28Z', 'field2': '#800080',
 'field1': 'purple', 'entry_id': 533104}]}
[{'created_at': '2019-02-18T19:47:28Z', 'field2': '#800080', 'field1': 'purple', 'entry_id': 533104}]
{'created_at': '2019-02-18T19:47:28Z', 'field2': '#800080', 'field1': 'purple', 'entry_id': 533104}
#800080
Fetching json from https://api.thingspeak.com/channels/1417/feeds.json?results=1
Resetting ESP32
 ESP32 timed out on SPI select
Resetting ESP32
 Failed to request hostname
Resetting ESP32
 Failed to request hostname
Resetting ESP32
 Failed to request hostname
Resetting ESP32
 Failed to request hostname
Resetting ESP32
 Failed to request hostname
Resetting ESP32

@jerryneedell
Copy link
Contributor

jerryneedell commented Feb 18, 2019

restarting the test I ran last night with current released library and my fix in example again -- to see if it fails/recovers cleanly again

@makermelissa
Copy link
Collaborator Author

Thanks Jerry, I’ll give it another go when I get a chance a little later.

@jerryneedell
Copy link
Contributor

No rush -- thanks for trying to make it better ... -- my test is still running -- never fails when yo want it to...

@jerryneedell
Copy link
Contributor

FYI - I was able to reproduce my original example, catching the error in esp32spi_cheerlights.py in the “get” loop and issuing the RESET before the “continue”. It actually occurred twice during this run and recovered both times. This is with currently released library, not with this PR.

Fetching json from https://api.thingspeak.com/channels/1417/feeds.json?results=1
Failed to get data, retrying
 Expected 01 but got 00
RESET ESP
Fetching json from https://api.thingspeak.com/channels/1417/feeds.json?results=1
Failed to connect, retrying
 ('No such ssid', b'Needell Airport')
{'channel': {'id': 1417, 'latitude': '40.5', 'name': 'CheerLights', 'longitude': '-80.22', 'updated_at': '2018-07-20T01:05:15Z', 'description': 'CheerLights is an \u201cInternet of Things\u201d project created by Hans Scharler that allows people\u2019s lights all across the world to synchronize to one color set by Twitter. This is a way to connect physical things with social networking experiences.', 'last_entry_id': 533122, 'field2': 'CheerLights HEX Color', 'field1': 'Last CheerLights Command', 'created_at': '2011-12-01T03:30:04Z'}, 'feeds': [{'created_at': '2019-02-18T23:55:07Z', 'field2': '#800080', 'field1': 'purple', 'entry_id': 533122}]}
[{'created_at': '2019-02-18T23:55:07Z', 'field2': '#800080', 'field1': 'purple', 'entry_id': 533122}]
{'created_at': '2019-02-18T23:55:07Z', 'field2': '#800080', 'field1': 'purple', 'entry_id': 533122}
#800080

@makermelissa
Copy link
Collaborator Author

Ok, I basically threw the try/except block around the code inside the get function and put some print messages before each line so I can try to determine which is causing the failure. I'm pretty sure I know what's up, but not quite sure why my changes didn't work, so I'm trying a different approach.

@jerryneedell
Copy link
Contributor

@makermelissa Although it would be great to know what causes the error, I think the main thing is to catch them and be able to resume normal operation afterwards. This is why I just dealt with it in the "user code".

@makermelissa
Copy link
Collaborator Author

makermelissa commented Feb 19, 2019

Yeah, I may end up doing that. This is what I woke up to this morning for my thing running all night:

Getting Value
Error Getting
 Timed out waiting for SPI char
RESET ESP
Traceback (most recent call last):
  File "code.py", line 50, in <module>
  File "code.py", line 42, in <module>
AttributeError: 'NoneType' object has no attribute 'json'

What that means is because the error was handled within the function, None was passed back.

Since the errors seem so varied I'm more inclined to go with your method.

@makermelissa
Copy link
Collaborator Author

Ok, I went ahead and removed the attempts code from the get/post functions, left it in place for connections (but changed it to a default of 2), added a reset function to the wifi, which really just calls the esp reset (in case we want some additional handling in the future), and added the wifi reset to the examples.

@jerryneedell
Copy link
Contributor

Looks good - I'll runs some tests with it this afternoon/evening

@jerryneedell
Copy link
Contributor

Worked great!

#FDF5E6
Fetching json from https://api.thingspeak.com/channels/1417/feeds.json?results=1
{'channel': {'id': 1417, 'latitude': '40.5', 'name': 'CheerLights', 'longitude': '-80.22', 'updated_at': '2018-07-20T01:05
:15Z', 'description': 'CheerLights is an \u201cInternet of Things\u201d project created by Hans Scharler that allows peopl
e\u2019s lights all across the world to synchronize to one color set by Twitter. This is a way to connect physical things 
with social networking experiences.', 'last_entry_id': 533184, 'field2': 'CheerLights HEX Color', 'field1': 'Last CheerLig
hts Command', 'created_at': '2011-12-01T03:30:04Z'}, 'feeds': [{'created_at': '2019-02-19T19:00:37Z', 'field2': '#FDF5E6',
 'field1': 'oldlace', 'entry_id': 533184}]}
[{'created_at': '2019-02-19T19:00:37Z', 'field2': '#FDF5E6', 'field1': 'oldlace', 'entry_id': 533184}]
{'created_at': '2019-02-19T19:00:37Z', 'field2': '#FDF5E6', 'field1': 'oldlace', 'entry_id': 533184}
#FDF5E6
Fetching json from https://api.thingspeak.com/channels/1417/feeds.json?results=1
Failed to get data, retrying
 ESP32 timed out on SPI select
Fetching json from https://api.thingspeak.com/channels/1417/feeds.json?results=1
Failed to connect, retrying
 ('No such ssid', b'Needell Airport')
{'channel': {'id': 1417, 'latitude': '40.5', 'name': 'CheerLights', 'longitude': '-80.22', 'updated_at': '2018-07-20T01:05:15Z', 'description': 'CheerLights is an \u201cInternet of Things\u201d project created by Hans Scharler that allows people\u2019s lights all across the world to synchronize to one color set by Twitter. This is a way to connect physical things with social networking experiences.', 'last_entry_id': 533184, 'field2': 'CheerLights HEX Color', 'field1': 'Last CheerLights Command', 'created_at': '2011-12-01T03:30:04Z'}, 'feeds': [{'created_at': '2019-02-19T19:00:37Z', 'field2': '#FDF5E6', 'field1': 'oldlace', 'entry_id': 533184}]}
[{'created_at': '2019-02-19T19:00:37Z', 'field2': '#FDF5E6', 'field1': 'oldlace', 'entry_id': 533184}]
{'created_at': '2019-02-19T19:00:37Z', 'field2': '#FDF5E6', 'field1': 'oldlace', 'entry_id': 533184}
#FDF5E6

Copy link
Contributor

@jerryneedell jerryneedell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested cheerlights example and caught/recovered from errors. Have not see error on post example yet.

@makermelissa
Copy link
Collaborator Author

It should be the same if it does happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants