diff --git a/src/Meshcore.php b/src/Meshcore.php index 1ab0a21..066c01a 100644 --- a/src/Meshcore.php +++ b/src/Meshcore.php @@ -282,11 +282,24 @@ class Meshcore { */ public function sendBinaryRequest(string $request): mixed { CoreProtocol::writeFrame($this->serial, chr(CoreProtocol::CMD_SEND_BINARY_REQ) . $request); - $response = CoreProtocol::readFrame($this->serial); + + do { + $response = CoreProtocol::readFrame($this->serial); + + } + while( + ord($response) != CoreProtocol::RESP_CODE_SENT && + ord($response) != CoreProtocol::ERR_CODE_NOT_FOUND && + ord($response) != CoreProtocol::ERR_CODE_NOT_FOUND + ); return CoreParser::parseResponse($response); } + public function readFrame(): mixed { + return CoreProtocol::readFrame($this->serial); + } + /** * * @param string $tag @@ -305,7 +318,7 @@ class Meshcore { usleep(500000); } - while( (time() - $mark) < $timeout_ms ); + while( ((time() - $mark) * 1000) < $timeout_ms ); return false; } diff --git a/tests/getTelemetry.php b/tests/getTelemetry.php index 48dff52..10ecd3c 100644 --- a/tests/getTelemetry.php +++ b/tests/getTelemetry.php @@ -14,7 +14,12 @@ $mc = Meshcore::getInstance(); $x = $mc->appStart("get remote tele"); +$repeaters = ['Simpsonville 3810gvr1', 'Simpsonville im37r1']; + $contacts = $mc->getContacts(); + +echo "Found " . count($contacts) . " contacts\n"; +/* $idx = 1; foreach($contacts as $contact) { echo "(" . $idx++ . ") {$contact['contact_name']} [" . substr($contact['pub_key'], 0, 6) . "]\n"; @@ -22,25 +27,30 @@ foreach($contacts as $contact) { $choice = readline("\nPlease select contact to attempt remote login: "); $contact = $contacts[$choice - 1]; +*/ -echo "Using {$contact['contact_name']}\n"; +foreach($contacts as $contact) { + if( !in_array($contact['contact_name'], $repeaters) ) continue; -/* -if( !$mc->connected($contact['pub_key']) ) { - $password = readline("Password: "); + echo "Using {$contact['contact_name']}\n"; - $mc->login($contact['pub_key'], $password); + $req = base64_decode($contact['pub_key']) . chr(CoreProtocol::BINREQ_TELEMETRY); + + $result = $mc->sendBinaryRequest($req); + + if( !isset($result->tag) ) { + var_dump($result); + echo "sendBinaryRequest sent nothing??\n"; + continue; + } + + echo "Tag: {$result->tag}\n"; + + $msg = $mc->pollForMessage($result->tag); + + echo json_encode($msg->lpp) . "\n"; + + sleep(1); } - */ - -$req = base64_decode($contact['pub_key']) . chr(CoreProtocol::BINREQ_TELEMETRY); - -$result = $mc->sendBinaryRequest($req); - -echo "Tag: {$result->tag}\n"; - -$msg = $mc->pollForMessage($result->tag); - -print_r($msg); echo "Complete\n";