Influxdb is a time series database, you have to provide a time if you want to use Influx.
Can you add a timestamp before you send it to node-red?
And while you are at it send the data as a json string.
Influxdb is a time series database, you have to provide a time if you want to use Influx.
Can you add a timestamp before you send it to node-red?
And while you are at it send the data as a json string.
Thanks Colin.
Yes, I'm looking at whether grafana can use the number of data points as the x-axis instead of time as the x-axis. But I haven't found a solution yet, do you have any suggestions?
I really don't know how to convert the data to json before entering node red?
I receive data via bluetooth, and then output to node red through the serial port. The Bluetooth interval is about 10ms, 10 samples are transmitted each time, 100 times per second (exactly 1000 samples in total), and the data sampling rate is 1kSPS. Can I receive data through Bluetooth and give each sample a time stamp, just like new Date()-i (i from 0 to 9) ten times a cycle corresponds to bluetooth passing 10 times of sampling data each time.
Instead of sending the string
7.5, 23.2, 5.0, 27
send the string
{"ch1": 7.5, "ch2": 23.2, "ch3":5.0, "ch4": 27}
Then you can read that whole string in the serial node and feed it directly into a JSON node which will convert it directly to a javascript object ready for adding into the message to be sent to Influx.
It depends on what device you are doing that on, and whether it knows the current time.
My sampling rate is 1000 times per second, and the sampling interval of each of the four channel data is 1ms. Because of the Bluetooth transmission problem, I need to send ten sampling values to the host computer, and then to node red through the serial port. The ten sampling values are in the same ms, which is the key to my problem.
Thank you for adding a timestamp reminder before entering node red. My idea is to return the current system tick value (get_HALtick) for each sample before Bluetooth transmission, which is how long the system has been running in ms, and then combine it with node red. Form a timestamp (but I don't know how to combine my timestamp, because using new data() will introduce the time of Bluetooth transmission).
In fact, what I want is that the time difference of each array is 1ms. I think this can be realized in node red. For example, the timestamp of the first array[1000] is from 1ms to 1000ms, and the timestamp of the second array[1000] is from 1001ms to 2000ms and then keep going...(
I think this is more feasible)
But I don't know how to code it...
Thanks again.
If you start with a known time in a variable called lastTime, then you can add 1 millisecond to that using
const nextTime = new Date( lastTime .getTime() + 1)
or if you have startTime and want to add n milliseconds to it then
const thisTime = new Date(startTime.getTime() + n)
In that case all you need to do is to add one to it each time. In a function node
let count = context.get("count") || 0
count = count +1
context.set("count", count)
msg.payload = count
return msg
I don't see what good that is going to do you though
[{"id":"b0d5b0b4b0ccc0c0","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":3120,"wires":[["23e195269765726a"]]},{"id":"23e195269765726a","type":"function","z":"bdd7be38.d3b55","name":"Counter","func":"let count = context.get(\"count\") || 0\ncount = count + 1\ncontext.set(\"count\", count)\nmsg.payload = count\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":3120,"wires":[["45f5d379f8b9c733"]]},{"id":"45f5d379f8b9c733","type":"debug","z":"bdd7be38.d3b55","name":"debug 65","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":460,"y":3120,"wires":[]}]
My expression is wrong here. What I want to say is that I transmit an array of 1000 elements per second, and the element timestamp interval is 1ms. I don’t know why influxDB only has data at the beginning, and then no data
Do you mean that you pass one seconds worth of data into influx, with timestamps from 0 to 1000 milliseconds, then you do the same thing again (with timestamps 0 1000 again? If so then you will just keep overwriting that 1 seconds worth of information. Timestamps from 0 to 1000 are effectively the first second of the year 1970.
I really didn't pay attention to whether 0ms to 1000ms are repeated, but I remember that it can be added all the time. For example, the first array is 0 to 999ms, and the second array is 1000 to 1999ms. Another point is that if the data is overwritten, the data should be displayed repeatedly in the last second, but no data will be displayed when I refresh. In fact, the data initially displayed will change over time, such as the second minute, the fifth minute, and so on. Is there any problem if I give time stamps manually?
Send the data going into influx into a debug node and show us what you get for two consecutive messages. Expand enough of the start of each message so we can see what is there. Also show us what you see in grafana
I tried it again this morning and I see that I have succeeded. Although I don't know what caused my problem last night.
I really appreciate your help and the platform node red
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.