Problems making Arduino serial connection with PHP

1

I'm trying to make a thermometer with PHP in Windows 10, and I'm capturing the data through an Arduino with the code:

#include <OneWire.h>

#include <DallasTemperature.h>

// Conectar o pino central dos sensores ao pino 10 do Arduino
#define ONE_WIRE_BUS 10

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);
DeviceAddress thermometerOne = { 0x28, 0xFF, 0x72, 0xC0, 0x62, 0x15, 0x01, 0x38 };
DeviceAddress thermometerTwo = { 0x28, 0xFF, 0xFA, 0x65, 0x72, 0x15, 0x02, 0x4D };

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(thermometerOne, 12);
  sensors.setResolution(thermometerTwo, 12);
}

void getTemp(){
  printTemperature(thermometerOne);
  Serial.print(" ");
  printTemperature(thermometerTwo);
}

void printTemperature(DeviceAddress deviceAddress)
{ 
  sensors.requestTemperatures();
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) 
  {
    Serial.print("Erro");
  } 
  else 
  {
    Serial.print(tempC, 4);
  }
}

void IDFuncao(String funcao){
 if (funcao == String("temp")){
  getTemp(); 
 }
}

void decodificaMensagem(String mensagem){
  int i;
  String funcao = "";
  for (i=1; i<=4; i++){
    funcao = funcao + String(mensagem[i]);
  }
  IDFuncao(funcao);
}

void loop(void)
{ 
  //Verificando se tem algo na Porta
  if (Serial.available() > 0){
    String mensagem = Serial.readString();
    String inicio = String(mensagem[0]);

    //Verificando se o que eu recebi começa com #
    if (inicio == String("#")){
      decodificaMensagem(mensagem);
    }
  }
}

I have already researched several ways to capture data in PHP like this using phpserial: PhP Serial

include 'PhpSerial.php';

$serial = new PhpSerial;

$serial->deviceSet("COM5");
$serial->confBaudRate(9600);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl("none");    

$serial->deviceOpen();

sleep (1);
$serial->sendMessage("#");

global $ler_serial;
$ler_serial = $serial->readPort();

$serial->deviceClose();

however, I get this message:

  Warning: Unable to open the device [...]

And doing:

$port = "COM5";
$fp = fopen($port, "r+b");
//sleep(1);
fwrite($fp,'#');
print_r($fp);
print_r(fgets($fp));
fclose($fp);

I get:

  

Warning: fopen (COM5): failed to open stream: Permission denied

A friend of mine who did the Arduino code, he said that I needed to send a '#' to the Arduino, as if it were a protocol, sending the '#', or not, the result is the same. p>

What can I do to receive the temperatures captured by Arduino?

    
asked by anonymous 06.09.2017 / 18:07

1 answer

0

This seems to indicate only that the COM5 port is not the correct port, or it is turned off, to check the correct port open the driver manager, then go to COM & LPT It should appear something like:

  

IfnothingappearsinPortas(COM&LPT)(orPortsCOM&LPTinsystemsinEnglish)itmeansthatthereissomeprobleminconnectingtheequipmentandmaybeitisinotherdevices,seeifthereissomethingtherewithanexclamationmarkonayellowicon,suchas:

  

Thismeansthatthereisamissingdriveronyoursystem,orthatthereisahardwarefailure.

IfyouareinPorts/Portsandareworkingnormally,butnottheportisdisplayedbetween(COM...)thenjustright-clickonitandclickProperties/p>

  

IfeverythingiscorrectandthereisnoyellowiconwithexclamationmarkthenyoucantesttheportusingsoftwarelikeHyperterminal,howeverthissoftwaredoesnotseemtoexistforWindows10(maybeitexistsonwindows-server),alternativelyyoucandownloadthe:

  • link

Open the program and click% with% > Set Up , or simply press Port Configuration , will open this window:

Look in the combox Port: , see if the port Alt+C appears, if it does not appear it is not connected, if it appears select it and click the next button called COM5 , if any error is a problem in the Hardware or problem in the configuration of the same.

    
06.09.2017 / 18:55