Programare

Array-ul bidimensional are problemele de care ziceai. Îți trebuie o structură un pic mai dinamică, cu ce ziceam mai sus.

Fă debug într-un buffer pe care-l scrii către UART doar când s-a terminat rândul. La fel, cu o coadă cu mesaje de lungime variabilă. Și poți pune un prefix pe rând ca să știi de unde vine.
 
Am nevoie de o formula de calcul a rasaritului si apusului soarelui pentru o locatie fixa, aplicabil in ash pe busybox, deci fara sinus, tangente, diametrul discului soarelui si alte chestii. Ceva simplu, doar + - * / si cu precizie +/- jumatate de ora.

PS:
Si sa fie ceva local, nu grep prin cine-stie-ce site!
 
Păi îți generezi o tabelă de sin/cos într-un fișier, că toată lumea consideră sin/cos ca fiind funcții "normale". Sau folosești bc.
 
Bai, da' ce ma enerveaza aia care scriu 2 linii de cod intr-o functie si dupa aia apeleaza functia intr-un singur loc. Eventual mai si pun functia intr-un alt fisier!!! :bash:
[/rant]
 
N-ai intrat tu în Node js, unde pentru o funcție de 2 rânduri sunt în stare să facă o bibilotecă pe care s-o descarci de pe net. Un build de-așa ceva descarcă măcar câteva mii de fișiere.
 
Folosesc PHP ca sa automatizez completarea unui formular online. Formularul are sute de campuri de completat si totul se face prin JS => POST.
Pana acum am folosit varianta cu deschis conexiunea (+negociere TLS), POST, inchis conexiunea, deschis conexiunea... etc.
Este enervant de lent. Merge cam cu 2 POST-uri / secunda. Trimiterea tuturor datelor dureaza vreo juma' de ora. Dar merge.

Incerc sa scriu o functie care sa refoloseasca o conexiune persistenta.
FAIL! :capu: Primesc header-ul raspunsului, scrie in el Content-Length, dar datele nu mai ajung. Moare acolo.
Ia testati si voi si ziceti-mi daca va merge.

Code:
$host='www.google.com';

function M95HttpConn(){
global $host,$conn;
if(is_resource($conn)) fclose($conn);    //Close previous $conn if still open.
echo("\r\nOpening HTTPS connection... ");
$conn=fsockopen('tls://'.$host,443,$errno,$err,5);    //Open new connection
if(!$conn){    //Check success
  echo("\r\nWarning! Server connection failed on first try. Error was $errno:$err\r\n");
  $conn=fsockopen('tls://'.$host,443,$errno,$err,5);}
if(!$conn)exit("\r\nError! Server connection failed on retry. Error was $errno:$err\r\n");
echo("OK.");
stream_set_timeout($conn,5,0);}    //Set read-write timeout.

function M95HttpReq($header,$data){
global $host,$conn;
$length=strlen($data);    //Measure data to send
if($length)$header.="\r\nContent-Length: ".$length;    //Set expected data length
unset($length);
$header.="\r\nConnection: keep-alive";    //Make connection persistent
if(!is_resource($conn)) M95HttpConn();    //(Re)Open if not available
M95SaveDebug("\r\n\r\nSending...\r\n".$header."\r\n\r\n".$data);
stream_set_blocking($conn,FALSE);    //Headers will be read line by line. Expecting to receive complete lines.
if(fwrite($conn,$header."\r\n\r\n".$data)==FALSE){
  echo("\r\nWarning! Server connection failed during send. Retrying.");
  M95HttpConn();    //Connection failed during send. Reopen.
  if(fwrite($conn,$header."\r\n\r\n".$data)==FALSE) exit("\r\nError! Server connection failed during send retry.");}
 
$timeout=time()+10;    //Set time limit 10s.
while(time()<$timeout){
  usleep(100);
  $t=fgets($conn);
  if(strlen($t)) var_dump($t);
  else echo(".");}

$header=<<<EOD
GET / HTTP/1.1
Host: $host
Accept: text/html
EOD;
$reply=M95HttpReq($header,'');unset($header);

La voi merge? Eu primesc header-ul, dar continutul paginii nu mai soseste.
 
Durează până testez, dar întrebarea este: ce face aplicația când îi trimiți mai multe câmpuri odată? Că majoritatea framework-urilur suportă așa ceva, chiar dacă nu e folosită metoda atunci când modifici un câmp.
 
N-am inteles absolut nimic din ce ai scris.
Ce aplicatie? E un php chior care ruleaza in consola.
Ce campuri sa trimit? Crapa la primul GET cand deschid pagina de login. Nu trimit mai multe campuri odata, ca nu-i multithread. Totul secvential.
Ce framework? Ce-s alea? E scris in Notepad.
Ce metoda? Nu folosesc clase, daca la asta te referi.

LE:
Ah, stai ca m-am prins; te referi la ce ruleaza pe server. Habar n-am si nu conteaza. Emulez ce ar face un browser. Dar cum ziceam: nici nu pot deschide pagina de login.
 
Last edited:
Eu ziceam cu metoda pe care o folosești acum să trimiți mai multe câmpuri în același request.
 
Nu trimit mai multe campuri in acelasi request. Trimit mai multe request-uri in aceeasi conexiune persistenta, secvential.
 
N-ai înțeles, e ok.

LE: Ce nu merge, mai exact? După ce am făcut codul să meargă (folosești niște chestii proprii de debug + nu era închisă o acoladă), am asta:

Code:
[miahi@ol-access ~]$ php < test.php

Opening HTTPS connection... OK.

Sending...
GET / HTTP/1.1
Host: www.google.com
Accept: text/html
Connection: keep-alive

............................................................................................................................................................................................................................................................................................................................................................................................string(17) "HTTP/1.1 200 OK
"
string(37) "Date: Fri, 02 Oct 2020 19:02:11 GMT
"
string(13) "Expires: -1
"
string(35) "Cache-Control: private, max-age=0
"
string(45) "Content-Type: text/html; charset=ISO-8859-1
"
string(69) "P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
"
string(13) "Server: gws
"
string(21) "X-XSS-Protection: 0
"
string(29) "X-Frame-Options: SAMEORIGIN
"
string(270) "Set-Cookie: NID=204=Xg4dmrgznFMspb-IAh7XqpzVqXKykj6R99idoTE4lXZEAomD4nS4AYNhrWWKYXN1KdRuAMIv_BQihdJaNoYSy9isxAsqSQGr26B65ksQmmy92j6SdyyB1E0G6KTdq43zRNv1jJRuSruxE03VBsf1TCl0zG0SKGq5_3PMNAXP18Q; expires=Sat, 03-Apr-2021 19:02:11 GMT; path=/; domain=.google.com; HttpOnly
"
string(230) "Alt-Svc: h3-Q050=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-27=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
"
string(21) "Accept-Ranges: none
"
string(23) "Vary: Accept-Encoding
"
string(28) "Transfer-Encoding: chunked
"
string(2) "
"
string(6) "4fa2
"
string(3237) "<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="ro"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>Google</title><script nonce="8Yastpiyt5q8j7UPxwCADg==">(function(){window.google={kEI:'M3l3X6CBCLmGjLsPqsKUmAo',kEXPI:'0,18167,183995,1151585,5662,730,224,5105,206,2415,789,10,1226,364,926,573,612,205,6,377,246,5,1354,648,3451,315,3,66,308,676,283,868,112,453,545,189,111,680,236,1118822,1197724,558,302680,26305,13677,4855,32692,16114,17444,1953,9287,9188,8384,4858,1362,9290,3027,4741,11028,2,1811,4998,7931,5297,2974,873,37,3562,7023,12445,2082,4517,1399,1379,921,2275,10,2794,1593,1279,2212,532,147,1103,840,517,1466,56,4258,312,1137,2,2063,606,2023,545,1232,522,1945,245,1984,93,329,1285,14,2927,2247,1812,1787,3227,1990,855,7,5599,469,6286,4455,641,6134,1405,338,4928,108,1456,1951,908,2,941,2614,2393,4,12,7458,1705,1570,3,346,230,970,865,4625,148,189,3313,2489,2251,5733,4,499,753,276,1696,608,1236,1,270,874,405,42,1818,2393,1510,281,2429,464,459,1555,4067,1036,1315,3,152,1956,298,874,1426,69,2103,312,200,2811,1753,690,1354,614,492,3414,1,335,519,912,564,689,431,30,468,835,1398,1153,138,1024,515,1556,990,52,1773,1012,245,1499,970,850,448,1,1006,638,665,829,46,16,68,360,115,2,567,583,333,92,64,453,1276,2,907,702,2361,55,744,611,986,698,1392,112,42,3,165,605,2,71,405,464,16,242,62,30,314,53,360,11,731,43,21,97,10,494,96,16,247,1786,1305,77,1615,685,130,802,90,176,248,107,231,4,8,433,301,57,275,185,447,1313,5752829,
[.....]
string(1183) "(function(){google.jl={dw:false,em:[],emw:false,lls:'default',pdt:0,snet:true,uwp:true};})();(function(){var pmc='{\x22d\x22:{},\x22sb_he\x22:{\x22agen\x22:true,\x22cgen\x22:true,\x22client\x22:\x22heirloom-hp\x22,\x22dh\x22:true,\x22dhqt\x22:true,\x22ds\x22:\x22\x22,\x22ffql\x22:\x22en\x22,\x22fl\x22:true,\x22host\x22:\x22google.com\x22,\x22isbh\x22:28,\x22jsonp\x22:true,\x22msgs\x22:{\x22cibl\x22:\x22&#536;terge&#539;i c&#259;utarea\x22,\x22dym\x22:\x22A&#539;i dorit s&#259; scrie&#539;i:\x22,\x22lcky\x22:\x22M&#259; simt norocos\x22,\x22lml\x22:\x22Afla&#539;i mai multe\x22,\x22oskt\x22:\x22Instrumente pentru introducere de text\x22,\x22psrc\x22:\x22Aceast&#259; c&#259;utare a fost eliminat&#259; din \\u003Ca href\x3d\\\x22/history\\\x22\\u003EIstoricul dvs. Web\\u003C/a\\u003E\x22,\x22psrl\x22:\x22Elimina&#539;i\x22,\x22sbit\x22:\x22C&#259;uta&#539;i dup&#259; imagine\x22,\x22srch\x22:\x22C&#259;utare Google\x22},\x22ovr\x22:{},\x22pq\x22:\x22\x22,\x22refpd\x22:true,\x22rfs\x22:[],\x22sbpl\x22:16,\x22sbpr\x22:16,\x22scd\x22:10,\x22stok\x22:\x22rkdEUnt86oArhu8OlBV36LvPQ3E\x22,\x22uhde\x22:false}}';google.pmc=JSON.parse(pmc);})();</script>        </body></html>
"
string(3) "0
"
string(2) "
"
.......................................................................................................................................................................................................................................
 
Last edited:
Asta e ce am rulat.

Code:
<?php

$host = 'www.google.com';

function M95HttpConn()
{
    global $host, $conn;
    if (is_resource($conn)) fclose($conn);    //Close previous $conn if still open.
    echo("\r\nOpening HTTPS connection... ");
    $conn = fsockopen('tls://' . $host, 443, $errno, $err, 5);    //Open new connection
    if (!$conn) {    //Check success
        echo("\r\nWarning! Server connection failed on first try. Error was $errno:$err\r\n");
        $conn = fsockopen('tls://' . $host, 443, $errno, $err, 5);
    }
    if (!$conn) exit("\r\nError! Server connection failed on retry. Error was $errno:$err\r\n");
    echo("OK.");
    stream_set_timeout($conn, 5, 0);
}    //Set read-write timeout.

function M95HttpReq($header, $data)
{
  global $host, $conn;
  $length = strlen($data);    //Measure data to send
  if ($length) $header .= "\r\nContent-Length: " . $length;    //Set expected data length
  unset($length);
  $header .= "\r\nConnection: keep-alive";    //Make connection persistent
  if (!is_resource($conn)) M95HttpConn();    //(Re)Open if not available
  echo ("\r\n\r\nSending...\r\n" . $header . "\r\n\r\n" . $data);
  stream_set_blocking($conn, FALSE);    //Headers will be read line by line. Expecting to receive complete lines.
  if (fwrite($conn, $header . "\r\n\r\n" . $data) == FALSE) {
    echo("\r\nWarning! Server connection failed during send. Retrying.");
    M95HttpConn();    //Connection failed during send. Reopen.
    if (fwrite($conn, $header . "\r\n\r\n" . $data) == FALSE) exit("\r\nError! Server connection failed during send retry.");
  }

  $timeout = time() + 10;    //Set time limit 10s.
  while (time() < $timeout) {
    usleep(100);
    $t = fgets($conn);
    if (strlen($t)) var_dump($t);
    else echo(".");
  }
}

$header=<<<EOD
GET / HTTP/1.1
Host: $host
Accept: text/html
EOD;

$reply = M95HttpReq($header, '');
unset($header);

?>
Code:
[miahi@ol-access ~]$ php -v
PHP 5.3.3 (cli) (built: Oct 31 2019 11:05:14)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
 
Gata. Merge. Multumesc!
Am gasit doua probleme. Se pierdea "Accept: text/html" pe undeva si in alta parte era un HEAD la care programul ramanea cu un Content-Length de la GET-ul anterior.
 
Mama, da' cat urasc OOP!
Se da o "chestie" definita asa:
Code:
bool I2CComponent::read_bytes(uint8_t address, uint8_t a_register, uint8_t *data, uint8_t len, uint32_t conversion) { blabla }
Iar in alt fisier care (cica) foloseste chestia de mai sus, gasesc asta:
Code:
uint8_t data[5];
... si undeva mai jos:
bool DHT12Component::read_data_(uint8_t *data) {
   if (!this->read_bytes(0, data, 5)) { blabla }
   more blabla
}
Cum se face ca are 5 parametri in definitie si numai 3 la apelare?!
 
Back
Top