Ultrasonic Sensor and Bolt Wifi Module Project

I am trying to build a very simple project. I want to use Ultrasonic sensor to measure distance. To do so, I connected the Ultrasonic sensor with Bolt Wifi Module. I am facing issues so your help will be appreciated.
A python code that should trigger the sensor to measure the distance and return the value. I will use this value to calculate the distance accurately(I am assuming sensor gives values and not distance). Once calculated, I will print the distance on screen (or python console).
Next, I want to plot the distance on the graph but the value returned by this sensor is not the distance so need a way to convert this value to distance before plotting.
Presently, I am using Bolt Cloud, but I am open to other Cloud platforms for solution too.

My Attempted Solution:
I tried coding this, here is my python code:

import requests, time, math, json
from boltiot import Bolt
import conf2 as conf #my Configuration File

data = [] #Empty list for storing sensor values…
mybolt = Bolt(conf.bolt_api_key, conf.device_id) #My Bolt

#Function:Get Sensor Value
def get_sv():

	response = mybolt.digitalRead(2)
	data = json.loads(response)
	if data["success"]!=1:
		print("Request Failed")
		return -999
	duration = int(data["value"])
	distance= duration*0.034/2;
	return distance
except Exception as e:
	print("Something went wrong")
	return -999

while True:
sensor_value = get_sv()
print("Sensor value is = ",sensor_value)

if sensor_value == -999:
	print("Request unsuccessful.Skipping...")

if(sensor_value <= conf.threshold):
	print("Alert: Accident Occured")
	message = "Crashed! " + "The current sensor value is: " + str(sensor_value)


my JS Code on Bolt Cloud is:
setChartTitle(‘Obstacle Distance’);
setAxisName(‘Time Stamp’, ‘Distance’);
plotChart(‘time_stamp’, ‘distance’);

Please feel free to clear any ambiguity. You help is greatly appreciated, thanks in advance :slight_smile

For seeing the value in distance you have already written the code Distance = (Time x SpeedOfSound) / 2
and for showing that distance in graph again you have to use that formula in JS or HTML file for reflecting the distance in km/m/cm etc.

Hi @ayushsingh425
In the above code digitalread doesn’t give the duration of pulse.It just gives the voltage of pulse.
correct me if I am wrong.If I am right can you help me how to get duration of pulse in python?