I'm thinking of saving the sensor data sent from Raspy on my PC in CSV format, but data.csv is created but no data is written.
By the way, the data I'm passing is comma-separated data (like 1, 2, 3.1, 4.2, 5.3)
I don't even know if there's a problem on the raspy side or php side.
I know it's a messy question, but if anyone knows anything about it, please let me know.
Data Transmitter (raspberrypi)
#!/usr/bin/env python
# -*-coding:utf-8-*-
import requests
import serial
import time
if__name__=='__main__':
gpio_seri=serial.Serial('/dev/ttyACM0',9600,timeout=10)
print(gpio_seri.portstr)
time.sleep(3)
while1:
gpio_seri.write('get')
time.sleep(1)
data=gpio_seri.readline()
print(data)
url="http://192.168.0.103:8080/test1.php/"
s=requests.session()
r=s.post(url,data)
Data Receiver (php)
<?php
$data1 = $_POST ['data'];
$filename = "data.csv";
$fp = fopen('data.csv', 'a');
$line=implode($data1);
fwrite($fp,$line."\n");
fclose($fp);
?>
Resolved
I changed it like the code below, and it was successful.
Thank you so much for your comments.
I changed the sender by referring to the comments.
In addition, I changed the write part of the receiver to current without using fwite
sender
#!/usr/bin/env python
# -*-coding:utf-8-*-
import requests
import serial
import time
if__name__=='__main__':
gpio_seri=serial.Serial('/dev/ttyACM0',9600,timeout=10)
print(gpio_seri.portstr)
time.sleep(3)
while1:
gpio_seri.write('get')
time.sleep(1)
bio_data=gpio_seri.readline()
print(bio_data)
url="http://192.168.0.103:8080/test1.php/"
response=requests.post(url,data={'bio_csv':bio_data})
Recipient
<?php
$data1 = $_POST ['bio_csv'];
echo$data1;
$file='test.csv';
$current=file_get_contents($file);
$current.=$data1;
file_put_contents($file,$current);
?>
581 PHP ssh2_scp_send fails to send files as intended
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
578 Understanding How to Configure Google API Key
610 GDB gets version error when attempting to debug with the Presense SDK (IDE)
912 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.