Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
live updated json file
#1
Dear Python forum!

I've read quite a bit on how to extract data into a json file but the majority of the documentations found online will only save static data or data you yourself have added by hand.

I have decided to complicate my life a bit and use python to do my project since I had a raspberry pi lying around with a bluetooth I thought might as well....let me explain.

I'm using my Arduino to gather temperature data and via bluetooth send it to my pi.

#! /usr/bin/python
import serial
import datetime
ser = serial.Serial('/dev/rfcomm0' , 9600)
print(ser.name)
print("Connected")



while True:

    now = datetime.datetime.now()
    ser_bytes = ser.readline()
    print (now.strftime("%Y-%m-%d %H:%M:%S, ")), ser_bytes
Eventually I'd like to load this into a database and make a plot that is visible on a website where the x is the time and y is the temperature.

In order to achieve this first I have to somehow save whatever numbers I'm getting in the while function. My initial idea was to just save it as a txt file like this:

nohup python -u temp.py &
This would work but eventually the file would get too big and probably not the nicest way to solve this problem, so I have to somehow limit the number of lines allowed in the database.

After a bit of research I found out saving it to CSV or JSON would be a lot more desirable but no documentation I've read so far uses the variables as inputs into the JSON or CSV file. I've done quite a few attempts but I was unsuccessful.

As I am new to this and got nobody else to ask I'd appreciate any help.

Sorry for an entry level question and thanks if you have read through it.

Sincerely,
Nyanpasu
Reply


Messages In This Thread
live updated json file - by Nyanpasu - Aug-22-2020, 07:51 AM
RE: live updated json file - by ndc85430 - Aug-22-2020, 11:33 AM
RE: live updated json file - by Nyanpasu - Aug-22-2020, 04:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  encrypt data in json file help jacksfrustration 1 239 Mar-28-2024, 05:16 PM
Last Post: deanhystad
  parse json field from csv file lebossejames 4 772 Nov-14-2023, 11:34 PM
Last Post: snippsat
  Python Script to convert Json to CSV file chvsnarayana 8 2,554 Apr-26-2023, 10:31 PM
Last Post: DeaD_EyE
  Loop through json file and reset values [SOLVED] AlphaInc 2 2,153 Apr-06-2023, 11:15 AM
Last Post: AlphaInc
  Mysql Workbench table not updated CatBall 2 1,124 Feb-13-2023, 05:37 PM
Last Post: CatBall
  Converting a json file to a dataframe with rows and columns eyavuz21 13 4,558 Jan-29-2023, 03:59 PM
Last Post: eyavuz21
  validate large json file with millions of records in batches herobpv 3 1,286 Dec-10-2022, 10:36 PM
Last Post: bowlofred
  Writing to json file ebolisa 1 1,017 Jul-17-2022, 04:51 PM
Last Post: deanhystad
  Trying to parse only 3 key values from json file cubangt 8 3,505 Jul-16-2022, 02:05 PM
Last Post: deanhystad
  Initializing, reading and updating a large JSON file medatib531 0 1,801 Mar-10-2022, 07:58 PM
Last Post: medatib531

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020