As the title suggests, I have a code that runs perfectly on my laptop. It connects to my solar inverter, grabs the information, and writes(appends) them to a CSV file.
When I run the same code through ssh on raspberry Pi, it runs without the error most of the time, however, it does not write(append) to the CSV file.
the code is as follow:
import json import urllib.request import csv # api call path = 'MY IP/solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&DeviceID=1&DataCollection=CommonInverterData' # Initialising the values, if there is an error, these would be reported. PAC = 'Nan' #Eenrgy generated @ this moment with urllib.request.urlopen(path) as url: data = json.loads(url.read().decode()) # reading json file json_keys = [x for x in data.keys()] head = data[json_keys] # getting the content of the head timestamp = head['Timestamp'] # Reading Time date = timestamp[:timestamp.index('T')] #the date time = timestamp[timestamp.index('T')+1: timestamp.index('+')] #the hour body = data[json_keys] # Body has only 'Data' in it body = body['Data'] # Getting the content of the Data in the Body PAC = body['PAC']['Value'] #Eenrgy generated @ this moment otpt_lst = [time, PAC] with open(str(date)+'.csv', 'a', newline='') as csvfile: slr_wrtr = csv.writer(csvfile, delimiter=',') slr_wrtr.writerow(otpt_lst)
Both are running in Python3, the python3 in my machine is more recent, in RBpi it is 3.5.8, and on my machine, it is 3.7.4. The way I set it up is, I am using RBpi to be SMB. I use my laptop to access the folder in External HDD attached to rbpi.
When I run the code on the attached HDD in my machine, I never ran into problems. when I do so on the RBPI, sometimes I get issues, not being able to read timestamp, etc, which are strange but fine for now.
Regardless, the main issue is when rbpi finishes executing the code, if it is successful, it does not write to the CSV file.
I have checked my permissions on the folder, and I have drwx access. I have tried to write instead of append, changed the filename, etc.
A sample of the JSON file I am reading from is http://www.filedropper.com/getinverterrealtimedatacgi
Appreciate it if someone can point me in the right direction on how to troubleshoot this, please.