Hello,
I would like to create an automatic daily export of several variables.
So I coded this (on a simple button for the moment):
import system
def runAction(self, event):
# Chemin du tag à exporter
tag_path = "[default]Station Météo/Temperature"
tag_name = "Temperature" # Nom du tag pour l'export
# Récupérer l'historique des données sur 1 heure
tag_history = system.tag.queryTagHistory(
paths=[tag_path],
startDate=system.date.addMinutes(system.date.now(), -60),
endDate=system.date.now(),
returnSize=10,
aggregationMode=None,
perPoint=True,
database="DB_Septèmes"
)
# Vérifier si des données sont récupérées
if tag_history.rowCount == 0:
system.util.getLogger("ExportFTP").info("Aucune donnée trouvée pour ce tag.")
return
# Construire les données à exporter
csv_content = "Timestamp," + tag_name + " (Valeur)\n"
for row in range(tag_history.rowCount):
timestamp = system.date.format(tag_history.getValueAt(row, 0), "yyyy-MM-dd HH:mm:ss")
value = tag_history.getValueAt(row, 1)
csv_content += "{},{}\n".format(timestamp, value)
# Définir le chemin du fichier CSV
file_path = "C:\\Export_ODP\\historique_1h.csv"
# Vérifier et créer le dossier si nécessaire
if not system.file.fileExists("C:\\Export_ODP"):
system.file.mkdir("C:\\Export_ODP")
# Écrire dans le fichier CSV
system.file.writeFile(file_path, csv_content.encode('utf-8'))
system.util.getLogger("ExportFTP").info("Exportation CSV terminée. Fichier créé : " + file_path)
But here is the result:
Timestamp,Temperature (Valeur)
2025-02-20 13:29:22,None
2025-02-20 13:35:22,None
2025-02-20 13:41:22,None
2025-02-20 13:47:22,None
2025-02-20 13:53:22,None
2025-02-20 13:59:22,None
2025-02-20 14:05:22,None
2025-02-20 14:11:22,None
2025-02-20 14:17:22,None
2025-02-20 14:23:22,None
I have the impression that it works, but that the data cannot be retrieved. ‘None’
The data is still available when I display it in a PowerGraph
I try with this path [default]Station Météo/Temperature
, but also the complete path that I use in my Powerchart histprov:DB_Septèmes:/drv:ignition-ign-srv-septemes:default:/tag:station météo/temperature
Thank you in advance for your help. Have a nice day!