-1

I want to create a digital scale and view it's readings live in my website. I am using a nodemcu for this purpose. I have created a small program that reads the data from a hx711 amp which is connected to 2 loadcells. Now I want to take that data and send it to a database server and then pull the data into my website. I have searched a lot and followed a lot of tutorials but cannot understand how to get the data from the loadcell to the database. Here is my code that can read the loadcells :

#include "HX711.h"
#define calibration_factor 895000 //random value, i can adjust it later
#define DOUT D1
#define CLK D2

HX711 scale(DOUT, CLK);

void setup(){
  Serial.begin(115200);
  Serial.println("Claibrate");
  scale.set_scale(calibration_factor);
  scale.tare();
  Serial.println("OK");
}

void loop(){
  Serial.print("Reading");
  Serial.print(scale.get_units(), 3);
  Serial.println("kg");
}

This is my first time doing a iot project so please help me somebody and also let me know if I missed out some vital info.

cray zeb
  • 1
  • 2
  • Could you clarify a couple of things please? 1) Do you really want/need lots of historic readings in a database, or do you just need the current reading available for your website? 2) Regarding the transmission from NodeMCU to the database, how frequently do you need to send the data and are you expecting to use WiFi? – Mark Setchell Nov 20 '20 at 07:58
  • I will be running this within a particular period of time, so once I stop the transmission I'll clear the database. I will be needing to send the data every 1/2 sec. Yes I am expecting use wifi. – cray zeb Nov 20 '20 at 08:35

1 Answers1

1

I'm not sure what the exact issue is here, or maybe you are just getting started, but here are a couple of suggestions:

  • if you want to store time series data, InfluxDB is nice and fast, simple and appropriate. So you would install InfluxDB ideally on your web-server host, or possibly on a PC or a Raspberry Pi somewhere on your network. Then send your readings from the NodeMCU with the InfluxDB client like this

  • you might like to use Redis which is extremely fast and lightweight. So you could run that on your web-server host, or some other PC or Raspberry Pi on your network and use a Redis client on NodeMCU to push the readings into a Redis LIST where your web-server could pick them up from. This is nice and easy because you can inject data into Redis and also read it straight from the command-line which is great for testing and debugging. Example here.

  • if you want to use some other database, you could use MQTT on your NodeMCU to send your readings to a broker, such as Mosquitto installed and running on your web-server host. You could then have a "bridge" that subscribes to the "weight" topic and when readings arrive, it could then push them into any database you like. Example here.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432