Scheduling periodic uploads, good practice?
<p>I am sending a bunch of sensor readings from my raspberrypi to a hosted php+mysql database using 3g network.</p>

<p>To save bandwidth and energy, it <a href="http://stackoverflow.com/questions/15050761/post-request-to-php-mysql-using-pythons-requests">was recommended</a> that rather than uploading sensor readings every second,  I should only upload periodically i.e. say every 5 minutes. So i decided to collect the readings using JSON format to ease up the uploading POST process:</p>

<pre><code>&gt;&gt;&gt; import json
&gt;&gt;&gt; url = 'https://api.github.com/some/endpoint'
&gt;&gt;&gt; payload = {'some': 'data'}
</code></pre>

<p>I also set a timer using the timer2 module:</p>

<pre><code>&gt;&gt;&gt; timer2.apply_interval(msecs, fun, args, kwargs, priority=0)
</code></pre>

<p>Now fun is called every 5*3600*1000. In fun, I upload the payload and reset the payload content for next round of data collection :</p>

<pre><code>&gt;&gt;&gt; r = requests.post(url, data=json.dumps(payload))
</code></pre>

<hr>

<p>The question: </p>

<ul>
<li><p>Is it good practice to reset the contents of the variable payload from fun while it is collecting data from main thread?</p></li>
<li><p>Is there a better way of doing this?</p></li>
</ul>
