Python 在web服务器上以rasperrypi显示传感器值
您好,我想用raspberry pi向web服务器显示传感器值。 我使用称重传感器(传感器)和arduino测量重量。 我连接arduino和hc-06(蓝牙模块)将重量发送给raspberry pi。这是arduino和raspberrypi的代码 阿杜伊诺代码Python 在web服务器上以rasperrypi显示传感器值,python,bluetooth,arduino,raspberry-pi,Python,Bluetooth,Arduino,Raspberry Pi,您好,我想用raspberry pi向web服务器显示传感器值。 我使用称重传感器(传感器)和arduino测量重量。 我连接arduino和hc-06(蓝牙模块)将重量发送给raspberry pi。这是arduino和raspberrypi的代码 阿杜伊诺代码 #include <SoftwareSerial.h> #include "HX711.h" #define calibration_factor -7050.0 #define DAT 5 #define CLK 6
#include <SoftwareSerial.h>
#include "HX711.h"
#define calibration_factor -7050.0
#define DAT 5
#define CLK 6
SoftwareSerial bt(2,3);
HX711 scale(DAT,CLK);
void setup(){
bt.begin(9600);
scale.set_scale(calibration_factor);
scale.tare();
}
void loop(){
float h=scale.get_units();// pound(lb)
float i=0.454*scale.get_units();// kilogram(kg)
bt.print (String(h) +","+ String(i));
bt.print("\n");
delay(2000);
}
根据这些代码,我成功地通过蓝牙将重量从arduino发送到raspberrypi。所以我可以检查树莓的重量。我想在web服务器上显示重量。我构建了apache2、php、phpmyadmin和mariadb。如何在我构建的web服务器上显示权重???如果通过
在web服务器上显示权重
您指的是web应用程序,我建议使用带有WebSocket的nodejs来连续地将数据从服务器发送到客户端(theres)。这对我来说特别容易。如果您只想对即时权重值使用基本的http响应(如rest服务),则不能在python中使用。无论哪种方式,您都不需要apache2、php、phpmyadmin和mariadb。好吧,你也许可以用php来做,但是每个人都会因此而对你嗤之以鼻
import bluetooth
bd_addr="XX:XX:XX:XX:XX:XX" //MAC ADDRESS of HC-06
port=1
sock=bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sock.connect((bd_addr.port))
data=""
while 1:
try:
data +=sock.recv(1024)
data_end=data.fint('\n')
if data_end!=-1:
rec=data[:data_end]
print data
data=data[data_end+1:]
except KeyboardInterrupt:
break
soc.close()