// const response = [ // { // "id": 446929723, // "library_name": "DHT20", // "hw_config": { // "protocol": "I2C", // "pin_connection_from_hw_to_arduino": { // "arduino_mega": [["SDA", "21"], ["SCL", "21"]], // "arduino_uno": [["SDA", "A4"], ["SCL", "A5"]], // } // }, // "usage_patterns": { // "DHT20": [ // "DHT20.begin DHT20.lastRead DHT20.read DHT20.getHumidity DHT20.getTemperature", // "DHT20.begin DHT20.read DHT20.getHumidity DHT20.getTemperature", // "DHT20.begin DHT20.read DHT20.getHumidity" // ], // "DHT12": [ // "DHT12.begin", // "DHT12.begin DHT12.lastRead DHT12.read DHT12.getHumidity DHT12.getTemperature", // "DHT12.begin DHT12.read DHT12.getHumidity DHT12.getTemperature" // ] // }, // "Sensor Type": "Sensors", // "Github URL": "https://github.com/RobTillaart/DHT20", // "Description": "Arduino library for I2C DHT20 temperature and humidity sensor." // }, // { // "id": 255120181, // "library_name": "DHT12", // "hw_config": { // "protocol": "I2C", // "pin_connection_from_hw_to_arduino": { // "arduino_mega": [["SDA", "20"], ["SCL", "21"]], // "arduino_uno": [["SDA", "A4"], ["SCL", "A5"]], // } // }, // "usage_patterns": { // "DHT12": [ // "DHT12.begin", // "DHT12.begin DHT12.lastRead DHT12.read DHT12.getHumidity DHT12.getTemperature", // "DHT12.begin DHT12.read DHT12.getHumidity DHT12.getTemperature" // ] // }, // "Sensor Type": "Sensors", // "Github URL": "https://github.com/RobTillaart/DHT12", // "Description": "Arduino library for I2C DHT12 temperature and humidity sensor." // } // ]; //display the pop up with more information function onClickMore(string){ document.getElementById(string).style.display ='block'; } //hide the pop up with more information function onOut(string){ document.getElementById(string).style.display ='none'; } async function getResponse(url, user_query){ try { let final_url = url + '?user_query=' + user_query console.log(final_url) let predictions = await fetch(final_url); console.log(predictions) if (predictions.status == 200){ return predictions.json() } else{ document.getElementById("spinner").style.display = 'none'; let error_msg = "Error, return code: " + predictions.status alert(error_msg); } } catch (error) { document.getElementById("spinner").style.display = 'none'; console.log("error") console.log(error) let error_msg = "Error, return code: " + predictions.status alert(error_msg); } } //when retrieve is clicked async function onSubmit(){ document.getElementById("spinner").style.display = 'none'; document.getElementById("spinner").style.display = 'block'; document.getElementById("main-parent").innerHTML = ''; let user_query = document.getElementById("exampleFormControlInput1").value // let url_query = "http://10.27.32.183:8111/predict" if (user_query != ''){ document.getElementById("spinner").style.display = 'block'; let url_query = "/predict" let predictions = await getResponse(url_query, user_query) document.getElementById("spinner").style.display = 'none'; // document.getElementById("grey-container").className = 'album py-5 bg-light'; let response = predictions['predictions'] //loop through number of results html = '' var w = 0 for(let i=0; i < response.length; i++){ html += '
'; html += '
'; html += '
'; // library name and description html += '
'; html += '
'+ response[i]["library_name"] +'
'; html += '

'+ response[i]["Description"] +'

'; html += '
'; // end library name and description // group button bottom (View GitHub and See Usage Patterns and Configs) html += ''; html += '
'; html += '
'; // end card group button html += '
'; } //append the html to the container document.getElementById("main-parent").innerHTML = (html); html2 = '

Back to top

'; //append footer to allow going back to the top document.getElementById("footer").innerHTML = (html2); } else { document.getElementById("spinner").style.display = 'none'; } }