在rasperrypi中的web服务器上显示传感器值

2024-04-18 23:18:22 发布

您现在位置:Python中文网/ 问答频道 /正文

您好,我想显示传感器值的网络服务器在树莓皮。 我用称重传感器(传感器)和arduino来测量重量。 我连接arduino和hc-06(蓝牙模块)将重量发送给raspberry pi。这是arduino和raspberrypi的代码。你知道吗

arduino代码

#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);
}

raspberrypi代码(python)

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()

根据这些代码,我成功地通过蓝牙将重量从arduino发送到raspberrypi。所以我可以检查树莓末的重量。我想在网络服务器上显示重量。我构建了apache2、php、phpmyadmin和mariadb。如何在我构建的web服务器上显示权重??你知道吗


Tags: 代码服务器data传感器arduinoendsockbluetooth
1条回答
网友
1楼 · 发布于 2024-04-18 23:18:22

如果您所说的display weight on web server是指web应用程序,我建议使用带有websockets的nodejs来连续地将数据从服务器发送到客户端(有bluetooth module for nodejs)。使用express特别容易。如果您只需要立即权重值的基本http响应(如rest服务),那么在python中不能使用SimpleHTTPServer。不管怎样,你都不需要apache2、php、phpmyadmin和mariadb。好吧,你也许可以用php来实现,但是每个人都会为此而对你嗤之以鼻。你知道吗

相关问题 更多 >