I am unable to send data to my Arduino Uno

<html>
<head>
   <title>Pet Feeder</title>
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
   <style>
       .button {
           background-color: #4CAF50;
           border: none;
           color: white;
           padding: 10px 10px;
           text-align: center;
           text-decoration: none;
           display: inline-block;
           font-size: 12px;
           margin: 4px 2px;
           cursor: pointer;
           border-radius: 5px;
       }
   </style>
</head>
<body>
      <section id="userChoice">
        <label for="city_name">City Name:</label>
        <form class="pure-form">
           <input id="name" type="text"/>
              <br>
    <button class="button" type="submit">Submit</button>
        </form>
    </section> 
<script type="text/javascript">
var nameInput = document.getElementById('name');

document.querySelector('form.pure-form').addEventListener('submit', (e) => {

e.preventDefault();
name_of_city = nameInput.value.toLowerCase();

console.log(name_of_city)
 url = 'https://api.openweathermap.org/data/2.5/weather?q=' + name_of_city + '&appid=b9d1d2deb13fa4dc8e3c1cc6fc2c213c'
 async function fetchTest() {
  const response = await fetch(url);
  const movies = await response.json();
  // console.log(movies)
  return movies;
}

fetchTest().then(movies => {
 letter = movies.weather[0].main[0]
 console.log(letter)
 return letter;// fetched movies
  
  function send_Data(){
    serial_begin();
    cmd_serial_write(letter)
    console.log("done totally")
  }
  send_data();
  async function serial_begin(){
  const response = await fetch("https://cloud.boltiot.com/remote/"+"b9a20694-380e-40c0-addd-2939d7ab8df4"+"/serialBegin?baud=9600&deviceName="+"BOLT13168793");
  console.log("serial had begun")
}

  async function cmd_serial_write(letter){
  const response = await fetch("https://cloud.boltiot.com/remote/"+"b9a20694-380e-40c0-addd-2939d7ab8df4"+"/serialWrite?data="+letter+"&deviceName="+"BOLT13168793");
  console.log("wrote in arduino")
}

});

});

</script>
</body>
</html>```

I am unable to trigger the send_Data()
Can anyone help me in debugging this I am not able to debug at all 🥴. I am not able to send the fetched data

This is my Arduino Uno code which is connected to the boltIoT

Servo servo;
int SERVO_PIN = 9;    // The pin which the servo is attached to
void setup() {
 // put your setup code here, to run once:
 Serial.begin(9600);
 servo.attach(SERVO_PIN);
 servo.write(30); // Close the trapdoor when it first boots up
}
void loop() {
 // put your main code here, to run repeatedly:
 if(Serial.available()){
   char c = Serial.read();   // Read data sent by the cloud
   switch(c){
     case 'c' : servo.write(90);
     Serial.println("Closed Door");
                break;
     case 'd' : servo.write(120);
                break;  
     default : servo.write(30);
               break;
   }
 }
}```

> If anyone need more information to help me pls do reply here

There were few changes -

  1. You were returning the letter so it was going outside fetchTest() function, and value of fetechTest() was the letter. I removed the return statement, so that inside the function it can pass the variable letter.

  2. senddata() has 2 errors.
    a. declaration and definition typo errors.
    b. you were calling it before defining serial_begin() and cmd_serial_write()

<html>
<head>
   <title>City Weather by sciencearoundus27</title>
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
   <style>
       .button {
           background-color: #4CAF50;
           border: none;
           color: white;
           padding: 10px 10px;
           text-align: center;
           text-decoration: none;
           display: inline-block;
           font-size: 12px;
           margin: 4px 2px;
           cursor: pointer;
           border-radius: 5px;
       }
   </style>
</head>
<body>
      <section id="userChoice">
        <label for="city_name">City Name:</label>
        <form class="pure-form">
           <input id="name" type="text"/>
              <br>
            <button class="button" type="submit">Submit</button>
        </form>
      </section> 
<script type="text/javascript">

var nameInput = document.getElementById('name');

document.querySelector('form.pure-form').addEventListener('submit', (e) => {

    e.preventDefault();
    name_of_city = nameInput.value.toLowerCase();

    console.log(name_of_city)
     url = 'https://api.openweathermap.org/data/2.5/weather?q=' + name_of_city + '&appid=b9d1d2deb13fa4dc8e3c1cc6fc2c213c'
     async function fetchTest() {
      const response = await fetch(url);
      const movies = await response.json();
      // console.log(movies)
      return movies;
    }

    fetchTest().then(movies => {
         letter = movies.weather[0].main[0]
         console.log(letter)
        //return letter;// fetched movies
          
          function send_data(){
            serial_begin();
            cmd_serial_write(letter)
            console.log("done totally")
          }
          
          async function serial_begin(){
              const response = await fetch("https://cloud.boltiot.com/remote/"+"b9a20694-380e-40c0-addd-2939d7ab8df4"+"/serialBegin?baud=9600&deviceName="+"BOLT13168793");
              console.log("serial had begun")
            }

          async function cmd_serial_write(letter){
              const response = await fetch("https://cloud.boltiot.com/remote/"+"b9a20694-380e-40c0-addd-2939d7ab8df4"+"/serialWrite?data="+letter+"&deviceName="+"BOLT13168793");
              console.log("wrote in arduino")
            }
           send_data();
           alert("ok") 
    });
    

});


</script>
</body>
</html>
1 Like

thanks for your ans @akshayan.sinha all the website is running fine but I am not getting the output. what should I do

@akshayan.sinha thanks alot bro with minnor changes it is working fine

Can you mention what other changes you made?

I was about to suggest to add capitals letters in your arduino code too.

1 Like

yes that capital one and my servo is not working properly I changed it now it is working fine

1 Like

Once you are done, do share a working video on the forum !!