Hey Guys,
I have been working on a project where I have two MPX1050 hooked up to the imp. I’m using the relative pressure sensors to monitor the pressure in my water tanks. It works very well, but I have been running into issues with plotly. I can send data no problem to plotly and I can see my graph, no issues there. The issue comes after I have accumulated quite a bit of data, then out of nowhere plotly will just erase everything and start ploting the new data. I’m assuming this is a max data restriction on plotly’s end. I do have a paid profession version, so i don’t think that is it.
I’m running out of ideas. I have contacted plotly support but have not received a response as of yet.
For my end, I changed the sample rate to 5 seconds, going to try and accumulate a bunch of data really fast and see how much data plotly will take before it resets the graph.
I have attached my code for anyone that is interested. I cahnge my API code to “x” (I’m no expert when it comes to this stuff!)
Thanks!
Agent Code
`#require “Plotly.class.nut:1.0.1”
function getTime() {
local date = date(time()-25200, "u");
local sec = stringTime(date["sec"]);
local min = stringTime(date["min"]);
local hour = stringTime(date["hour"]);
local day = stringTime(date["day"]);
local month = date["month"] + 1;
local year = date["year"];
return year+"-"+month+"-"+day+" "+hour+":"+min+":"+sec;
}
// function to fix time string
function stringTime(num) {
if (num < 10)
return “0”+num;
else
return “”+num;
}
function postToPlotly(reading) {
local timestamp = getTime();
plot1.post([
{
“name” : “Tank 1”,
“x” : [timestamp],
“y” : [reading[“tank1”]]
}
{
“name” : “Tank 2”,
“x” : [timestamp],
“y” : [reading[“tank2”]]
}
{
“name” : “Max Level”,
“x” : [timestamp],
“y” : [“750”]
}
{
“name” : “Min Level”,
“x” : [timestamp],
“y” : [“140”]
}
]);
}
plot1 <- Plotly(“Jesstr”, “xxxxxxxxxx”, “Tank Level”, false, [“Tank 1”, “Tank 2”, “Max Level”, “Min Level”], function(error, response, decoded) {
device.on(“reading”, postToPlotly);
server.log("See plot at " + plot1.getUrl());
});`
Device Code
`// Device Code
// Establish a global variable to hold environmental data
data <- {}
data.tank1 <- 0
data.tank2 <- 0
// Configure the LED (on pin 2) as digital out with 0 start state
local led = hardware.pin5
led.configure(DIGITAL_OUT, 0)
// Configure pins for sensors
local tank1 = hardware.pin1
local tank2 = hardware.pin2
tank1.configure(ANALOG_IN)
tank2.configure(ANALOG_IN)
// This function will be called regularly to take the temperature
// and log it to the device’s agent
function getReadings()
{
// Flash the LED
flashLed()
// Read Tank Levels
local supplyVoltage = hardware.voltage()
local voltage1 = supplyVoltage * tank1.read() / 65535.0
local voltage2 = supplyVoltage * tank2.read() / 65535.0
local pressure1 = ((voltage1/supplyVoltage)-0.04)/0.09
local pressure2 = ((voltage2/supplyVoltage)-0.04)/0.09
local level1 = (pressure1*101.971621298)
local level2 = (pressure2*101.971621298)
data.tank1 = level1-3.43-0.0215
data.tank2 = level2-45.7+1.67
//Send the data to the agent
agent.send("reading", data)
// Put the imp to sleep for five minutes BUT
// only do so when impOS has done all it needs to
// do and has gone into an idle state
imp.onidle(function() { server.sleepfor(5) } )
}
function flashLed()
{
// Turn the LED on (write a HIGH value)
led.write(1)
// Pause for half a second
imp.sleep(0.5)
// Turn the LED off
led.write(0)
}
// it runs its device code afresh - ie. it does a warm boot
getReadings()`