[SOLVED]Issue with sending data to webserver

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
rpi_nerd
Posts: 20
Joined: Sat Jul 29, 2017 2:05 pm

[SOLVED]Issue with sending data to webserver

Post by rpi_nerd » Fri Sep 01, 2017 11:19 pm

Murphy's law seems to strike again for me. My current project is simply sending some temperature data to my Pi with my Wemos D1 mini. I finally got everything working smoothly, or so I thought. After an hour or two of running a loop that reads the temp sensors and sends the readings to the webserver, it crashes with this error:

Code: Select all

File "esp8266temptest4.py", line 117, in go
File "esp8266temptest4.py", line 110, in send_data
File "urequests.py", line 104, in post
TypeError: unexpected keyword argument 'crc8'
my function that sends the temperature readings:

Code: Select all

def send_data():
		url = 'http://[webserveripaddress]/php/rsensor.php'
		headers = {'Content-Type': 'application/x-www-form-urlencoded'}
		datas = "data=" + str(basic_temp) + "&" + "data2=" + str(advanced_temp)
		urequests.post(url, data=datas, headers= headers)

Last edited by rpi_nerd on Thu Sep 07, 2017 11:48 am, edited 1 time in total.

fangis
Posts: 11
Joined: Mon Jul 24, 2017 11:03 pm

Re: Issue with sending data to webserver

Post by fangis » Sat Sep 02, 2017 12:47 am

It's funny, I think I had a similar, or the same problem, yesterday when I was trying to use urequests.
From what I have read, it looks like urequests leaves the connection open, it's up to you to close it, or the loop will keep opening sockets until it crashes.
What solves the problem so far to me is something like this:
r = urequests.get(data)
r.close()

rpi_nerd
Posts: 20
Joined: Sat Jul 29, 2017 2:05 pm

Re: Issue with sending data to webserver

Post by rpi_nerd » Sat Sep 02, 2017 2:57 am

Thanks for the suggestion, fangus. I'll have to give it a try. It finally crashed again but it now gave me a different error:

Code: Select all

File "esp8266temptest4.py", line 110, in send_data
NameError: local variable referenced before assignment
It's referring to the last line in my function in my OP.

rpi_nerd
Posts: 20
Joined: Sat Jul 29, 2017 2:05 pm

Re: [SOLVED]Issue with sending data to webserver

Post by rpi_nerd » Thu Sep 07, 2017 11:49 am

Fangus, your suggestion worked. It's been running for a few days now without any crashes.

Post Reply