Urequests problem (multiple Post) with google docs/forms

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
MoustachedBird
Posts: 6
Joined: Mon Sep 09, 2019 7:12 am

Re: Convert arduino code to esp8266 micropython (google sheets without IFTTT) or suggestion

Post by MoustachedBird » Sat Sep 14, 2019 4:38 am

pythoncoder wrote:
Thu Sep 12, 2019 7:30 am
Is it possible that Google impose some form of throttling?
After trying some time i got it partially. I say "partially" because i have to do a random get-request after the post-request; i don't know why it works, but it works (in this way i can send data to Google Forms every second approximately, or maybe less) :shock: . I guess the problem is that the esp8266 can't close the connection with Google Forms and it gets stuck when it tries to do a new post-request, if this were the problem, i don't know how to fix it in another way, any suggestions? The complete code is here:

Code: Select all

ssid = 'my_network'
password = 'my_password'

import urequests

def do_connect():
    import network
    sta_if = network.WLAN(network.STA_IF)
    if not sta_if.isconnected():
        print('connecting to network...')
        sta_if.active(True)
        sta_if.connect(ssid, password)
        while not sta_if.isconnected():
            pass
    print('network config:', sta_if.ifconfig())


def main():
    do_connect()
    print ("CONNECTED")
    url = 'url_of_my_google_form'
    form_data = 'entry.61639300=example'   #have to change the entry
    user_agent = {'Content-Type': 'application/x-www-form-urlencoded'}
    while True:
        response = urequests.post(url, data=form_data, headers=user_agent)
        print ("DATA HAVE BEEN SENT")
        response.close
        print("TRYING TO SEND ANOTHER ONE...")
	response = urequests.get("http://micropython.org/ks/test.html")  #<------ RANDOM URL, I DON'T KNOW WHY THIS CODE WORKS CORRECTLY IN THIS WAY
	print("RANDOM GET:")
        print(response.text)
        response.close
        
    
if __name__ == '__main__':
    main()
Thank you for your time guys. Also i've tried with this code before but it DOESN'T WORK. Without the random get-request, it gets stuck after one or two times of posting:

Code: Select all

while True:
        response = urequests.post(url, data=form_data, headers=user_agent)
        print ("DATA HAVE BEEN SENT")
        response.close
        print("TRYING TO SEND ANOTHER ONE...")

Post Reply