A
A
Andrey2018-01-04 12:22:49
linux
Andrey, 2018-01-04 12:22:49

Why can't I get data from Arduino in PHP?

There is a simple sketch for the test:

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.print(152);
  Serial.print("\n");
  delay(1000);
}

And there is a simple php script for the test:
<?php
  exec('stty -F /dev/ttyUSB0 cs8 9600  ignbrk -brkint -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts');

  $as = fopen('/dev/ttyUSB0', 'r+b');
  var_dump(fgets($as));
  fclose($as);

The problem is that var_dump returns false .
I set different flags for stty (I searched on the Internet and tried it, I thought there might be a problem in them).
The mode for fopen has also tried both read and read-write, both binary and non-binary.
I also found different composer libraries and separate classes, but they all use the same principle and, accordingly, also do not work.
Also, previously, a command was executed from the guide on the arduino off-site
sudo usermod -a -G dialout
for the current user and for the www-data user (for Apache).
PS OS Linux Mint, Arduino nano v3.0, PHP 7.1

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mors Superberg, 2018-01-04
@NooooN

You are a terrible person. In general, about your problem, there is something with setting up configs, I can’t tell you more precisely :(

V
vanyamba-electronics, 2018-01-06
@vanyamba-electronics

Try the options from this article Arduino Host Client in C (Linux)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question