serialRead() on server gives command timed out

My bolt is connected via UART to arduino. When I do SerialRead via browser it returns the value correctly but when I serialRead() via the server it shows command timed out. I have even tried an http request via the server but it shows command timed out. serialWrite() is successfully done by the server.

Hi @jazib980,

For the serialRead() function via the Python code, did you add an ending character for the code to check for?

serialRead(), should be used in the following manner

serialRead(‘10’)

If you are using the BoltIoT-Arduino-Helper library, then there is no issue. But if you are using the Serial object in the Arduino code, please ensure that you are using Serial.println function in your Arduino code.

Hey! @vinayak.joshi, yeah I used serialRead(‘10’) in the pyhton code.

In am using the bolt arduino helper library

#include <BoltDeviceCredentials.h>
#include <BoltIoT-Arduino-Helper.h>
#include <MPU6050_tockn.h>
#include <Wire.h>

MPU6050 mpu6050(Wire);

void setup() {
  boltiot.Begin(Serial);
  boltiot.setCommandString("GetData",getData);
  Wire.begin();
  mpu6050.begin();
  mpu6050.calcGyroOffsets(true);
}

String getData(String *data){
  String a="";
  a=a+String(mpu6050.getAccX())+",";
  a=a+String(mpu6050.getAccY())+",";
  a=a+String(mpu6050.getAccZ())+",";
  a=a+String(mpu6050.getAngleX())+",";
  a=a+String(mpu6050.getAngleY())+",";
  a=a+String(mpu6050.getAngleZ());
  return a;
}

void loop() {
  mpu6050.update();
  boltiot.handleCommand();
  delay(500);
}

The python code first serial writes get data (And the data gets printed on the arduino serial monitor) but bolt is unable to read it and shows timed out.

Hi @jazib980:

Your code seems to be fine.

For the command timed out issue, I just realized that it cannot be an issue with your Arduino code.
The issue comes in if, your Bolt WiFi module goes offline almost immediately before or after you make the API call.

This can happen if you are printing a lot of data into the Serial port of the Bolt WiFi module.

Try breaking down your “getData” function into functions which returns only part of the data. like “getAccXData”, and see if that works for you.

Also, I am certain you are already doing this, but are you using serialWrite(“GetData”) before calling the serialRead function? If not please use the serialWrite function and then go for the serialRead fucntion.

1 Like

@vinayak.joshi yeah I used the serialWrite function.

You may have identified the problem because when I used the serialWR function from the browser it gave device offline and the cloud dashboard showed it offline even though bolt had green led on, I will try sending individual values to the module.

1 Like

@vinayak.joshi Nop, still the same problem

When I used API SerialWrite and SerialRead seperately it read the value but Using the SerialWR made bolt go offline again

Hi @jazib980,

We will look into what is causing this issue.

For now, you could try using serialWR in your URL instead of serialRead.
This way, you can make 1 single API call (don’t use serialWrite), and check if the system works for you or not.