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
#2
It would help to see how you're attempting to write the values into whatever file. It really shouldn't be that hard.
Reply
#3
Managed to use lists instead and solve the issue. Now I can work with the data.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  parse json field from csv file lebossejames 4 668 Nov-14-2023, 11:34 PM
Last Post: snippsat
  Python Script to convert Json to CSV file chvsnarayana 8 2,344 Apr-26-2023, 10:31 PM
Last Post: DeaD_EyE
  Loop through json file and reset values [SOLVED] AlphaInc 2 1,960 Apr-06-2023, 11:15 AM
Last Post: AlphaInc
  Mysql Workbench table not updated CatBall 2 1,045 Feb-13-2023, 05:37 PM
Last Post: CatBall
  Converting a json file to a dataframe with rows and columns eyavuz21 13 4,164 Jan-29-2023, 03:59 PM
Last Post: eyavuz21
  validate large json file with millions of records in batches herobpv 3 1,221 Dec-10-2022, 10:36 PM
Last Post: bowlofred
  Writing to json file ebolisa 1 970 Jul-17-2022, 04:51 PM
Last Post: deanhystad
  Trying to parse only 3 key values from json file cubangt 8 3,337 Jul-16-2022, 02:05 PM
Last Post: deanhystad
  Initializing, reading and updating a large JSON file medatib531 0 1,723 Mar-10-2022, 07:58 PM
Last Post: medatib531
Question How do I skipkeys on json file read to python dictionary? BrandonKastning 3 1,829 Mar-08-2022, 09:34 PM
Last Post: BrandonKastning

Forum Jump:

User Panel Messages

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