BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Arduino UNO results offline when connected via USB to local server

Hello, I’m trying to connect my Arduino UNO to the Blynk app to control 5 MG995 servos with an Adafruit 16-Channel Servo Shield… for a robotic arm. To do this I’m using my Raspberry pi 3B+ as a local server, the Arduino is connected to it via USB.

The local server is online and I can access the Blynk app, the problem is that the blynk-ser.sh keeps reconnecting every 3 seconds, I can’t figure out if i configured the .sh file with the wrong port for the local server address or if it’s something else that i didn’t specify in the Arduino code.

This is what i see on my Raspberry local server when I try to run the file blynk-ser.sh:

When I stop blynk-ser.sh to open the serial monitor on the Arduino IDE I see that the arduino is printing the auth token over and over again…

This is the code that I’m using on my Arduino UNO:
For the Adafruit shield I’m using this library: Adafruit_PWMServoDriver.h


#define BLYNK_PRINT SwSerial

#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX
#include <BlynkSimpleStream.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

#define BASE 0
#define HEIGHT 1
#define LENGTH 2
#define GRIP 3
#define CLAW 4

float base_init = 1540;
float height_init = 550;
float length_init = 1740;
float grip_init = 1350;
float claw_init = 1000;
 
float SERVOFREQ = 50;
float pulseconstant;

char auth[] = "XXXXXXXXXXXXXXXXXXXXX";

int moveBASE = 0;
int moveHEIGHT = 0;
int moveLENGTH = 0;
int moveGRIP = 0;
int moveCLAW = 0;

void setup()
{
  // Debug console
  SwSerial.begin(9600);

  // Blynk will work through Serial
  // Do not read or write this serial manually in your sketch
  Serial.begin(9600);
  Blynk.begin(Serial, auth);

  pulseconstant = (1000000/SERVOFREQ)/4096;
  
  pwm.begin();
  pwm.setPWMFreq(SERVOFREQ);
  
  servoWrite(BASE, base_init);
  servoWrite(HEIGHT, height_init);
  servoWrite(LENGTH, length_init);
  servoWrite(GRIP, grip_init);
  servoWrite(CLAW, claw_init);
}

void loop()
{
  Blynk.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
  pwm.setPWM(BASE, 0, moveBASE);
  pwm.setPWM(HEIGHT, 0, moveHEIGHT);
  pwm.setPWM(LENGTH, 0, moveLENGTH);
  pwm.setPWM(GRIP, 0, moveGRIP);
  pwm.setPWM(CLAW, 0, moveCLAW);
}

void servoWrite(uint8_t n, float pulse) {
  float pulsetick = pulse/pulseconstant;
  pwm.setPWM(n, 0, pulsetick);
}

BLYNK_WRITE(V0) // slider using Virtual Pin V0 between 0 and 4096
{
  moveBASE = param.asInt();
}

BLYNK_WRITE(V1) // slider using Virtual Pin V1 between 0 and 4096
{
  moveHEIGHT = param.asInt();
}

BLYNK_WRITE(V2) // slider using Virtual Pin V2 between 0 and 4096
{
  moveLENGTH = param.asInt();
}

BLYNK_WRITE(V3) // slider using Virtual Pin V3 between 0 and 4096
{
  moveGRIP = param.asInt();
}

BLYNK_WRITE(V4) // slider using Virtual Pin V4 between 0 and 4096
{
  moveCLAW = param.asInt();
}

I would have expected the port to be 9443 rather than 443

If the Pi is also then server then maybe the IP address should be the loopback IP?

Do you have an FTDI connected to your SoftwareSerial port, and if so what does it say?

Pete.

Thank you for helping me.
I also tried with port 9443 and the loopback address, it manages to connect successfully but it gives me an error regarding the SSL connection:

Connecting: FILE:/dev/ttyACM0,raw,echo=0,clocal=1,cs8,nonblock=1,b9600 <-> openssl-connect:127.0.0.1:9443,cafile=/home/pi/Arduino/libraries/blynk-library-master/scripts/certs/server.crt,nodelay
2020/04/05 01:03:58 socat[3446] N opening character device “/dev/ttyACM0” for reading and writing
2020/04/05 01:03:58 socat[3446] N opening connection to AF=2 127.0.0.1:9443
2020/04/05 01:03:58 socat[3446] N successfully connected from local address AF=2 127.0.0.1:48280
2020/04/05 01:03:58 socat[3446] E SSL_connect(): error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
2020/04/05 01:03:58 socat[3446] N exit(1)
Reconnecting in 3s…

This is how the blynk-ser.sh file looks:

Actually I don’t have an FTDI cable :grimacing:

For the USB link, I belive port 8080 was what is to be used in the script. As it is a direct USB link between the Arduino and RPi, there is no need for SSL

1 Like

With the port 8080 configured in the blynk-ser.sh file the SSL error is gone but I’m again in this loop:

Connecting: FILE:/dev/ttyACM0,raw,echo=0,clocal=1,cs8,nonblock=1,b9600 <-> openssl-connect:127.0.0.1:8080,cafile=/home/pi/Arduino/libraries/blynk-library-master/scripts/certs/server.crt,nodelay
2020/04/05 02:30:22 socat[3703] N opening character device “/dev/ttyACM0” for reading and writing
2020/04/05 02:30:22 socat[3703] N opening connection to AF=2 127.0.0.1:8080
2020/04/05 02:30:22 socat[3703] N successfully connected from local address AF=2 127.0.0.1:41680
2020/04/05 02:30:22 socat[3703] E SSL_connect(): Success
2020/04/05 02:30:22 socat[3703] N exit(1)
Reconnecting in 3s…

Since I have the Blynk library installed also in my Windows 10 PC, I modified the blynk-ser.bat file to connect to the address of my Raspberry pi local Blynk server 192.168.1.28:8080 and it works now!

My Arduino UNO is now online via USB and i can move all the servo motors… It’s still not clear to me why the file blynk-ser.sh on my local server gives me problems with the connection :thinking: the addresses and the ports declared in both the files are the same

Try changing this “local IP” to the actual IP of your RPi :thinking:

I’ve tryied with 192.168.1.28:8080, 127.0.0.1:8080 and also with raspberrypi.local:8080…

This is the output when i configure blynk-ser.sh with 192.168.1.28 :man_shrugging:

Maybe I should try to reinstall the library… I don’t really know what to do at this point.

Ok so, I reinstalled again the library and I got the bash file working with these settings:

Working_blynk-ser

This is the output:

Resetting device /dev/ttyACM0…
Warning: Server connection may be insecure!
[ Press Ctrl+C to exit ]
Connecting: FILE:/dev/ttyACM0,raw,echo=0,clocal=1,cs8,nonblock=1,b9600 <-> TCP:raspberrypi.local:8080,nodelay
2020/04/05 12:45:32 socat[2060] N opening character device “/dev/ttyACM0” for reading and writing
2020/04/05 12:45:32 socat[2060] N opening connection to AF=2 192.168.1.28:8080
2020/04/05 12:45:32 socat[2060] N successfully connected from local address AF=2 192.168.1.28:52846
2020/04/05 12:45:32 socat[2060] N starting data transfer loop with FDs [5,5] and [6,6]

Thanks GTT and PeteKnight for helping me with this.

1 Like