Jump to content

dekip

New Members
  • Posts

    8
  • Joined

  • Last visited

Posts posted by dekip

  1. Obviously not enough of data. My bad

    Idea is to have a device that will send some random string via GET. Say: 123gh5

    On server I query DB, check last ID, increment to one more and insert that incremented ID into DB. But also put together this ID and this string and insert that, too. Let's call it newID. I hope it is not too confusing.

    This ID in DB is INT type, and newID is VARCHAR. But on server, it just doesn't pass $z =  $x.$y;. It doesn't pass to inserting query.

     

    Say, this is GET request:

    somesite.com/index.php?upit=id&espID=12a456?id=12a456

    And on server:
     

    if ($_SERVER["REQUEST_METHOD"] == "GET") {
               $action = $_GET["upit"];
               if ($action == "id"){
                   $espID = $_GET["espID"];
                   $sql = mysqli_query($con,"SELECT * FROM autoSetup ORDER BY deviceID DESC LIMIT 1");
                   while($row = mysqli_fetch_array($sql,MYSQLI_ASSOC)){
                   $newID = $row["deviceID"] + 1;
                   }
               echo $newID;
               $IDID = $newID.$espID;
               mysqli_query($con,"INSERT INTO autoSetup (deviceID, espID, UID, date) VALUES ('$newID', '$espID',$IDID, now())");
               }
    
    }

    You can see here it is a part of a ESP MCU system I build.

    So deviceID is INT, espID and UID are VARCHAR.

  2. Thank you!

    I get this and it is clear to me.

    Quote

    S0100111W 00000010 s                 // this line says it is 0100111 I2C address, and 00000010 here last 0 says it is 0 port
    S0100111R 11101011-s                    // this line says it is 0100111 I2C address, and 11101011 are bits I need to put in a specific field in db
    S0100111W 00000010 11101111 s // this line I don't need
    S0100111W 00000010 s
    S0100111R 11101111-s
    S0100111W 00000010 11111111 s
    S0100111W 00000011 s
    S0100111R 10111100-s
    S0100111W 00000011 10111101 s
    S0100111W 00000011 s
    S0100111R 10111101-s
    S0100111

    However, there are some other things I would need help.

    As I point it above...

    I should check first two lines, if on both first set of bits are 0100111, than according to last 0 or 1 on the first line second set, take from second line last set of bits.

    Let's say, if we take 4th and 5th rows, if on those rows I2C address is the one declared somewhere above is the one I need, than take those 11101111 and put in 0 field.

    In 7th and 8th there is 1, so 10111100 should go into field 1.

    That array with 3 sets of bits has following s, and is a problem or maybe not. It might be good for a delimiter as it is after every two lines of sets.

     

    I messed up with this a week or so, and couldn't make any move, until you helped me. :)


     

  3. This one did the trick. Thank you!

    I really appreciate your help, but it is nothing if I don't understand what is happening here. Working solution is nice, but understanding is much better.

     

    while (($p1 = strpos($str, 'S', $p2)) !== false) {
                    $p2 = strpos($str, 's', $p1);
                    if ($p2===false) {                                     // add this check
                        $p2 = strlen($str);
                            }
                            echo substr($str, $p1, $p2-$p1+1) . '<br>';
                       }

    Row 1:

    Finding the first occurrence of an S in $str and if it is not false, than...

    Row 2:

    Get the length until an s occurs.

    Row 3:

    This I don't get quite good

    Row 4:

    Return the length of a $str

    Row 6:

    Return part of a $str from $p1 (start), to a $p2-$p1+1 (end).

    Please correct me where I am wrong.

     

     

  4. The main goal is to cut these numbers:
     

    Quote

     

    S0100111W 00000010 s

    S0100111R 11101011-s

    S0100111W 00000010 11101111 s

    S0100111W 00000010 s

    S0100111R 11101111-s

    S0100111W 00000010 11111111 s

    S0100111W 00000011 s

    S0100111R 10111100-s

    S0100111W 00000011 10111101 s

    S0100111W 00000011 s

    S0100111R 10111101-s

    S0100111

     

    And to process send them to some other tables, etc.

    But, these numbers are close to these:
     

    Quote

     

    S0100111W 00000010 s <-if here is 0

    S0100111R 11101011-s      <-than this 11101011 is going to some other table

    S0100111W 00000010 11101111 s <-this is not important

    S0100111W 00000010 s

    S0100111R 11101111-s

    S0100111W 00000010 11111111 s

    S0100111W 00000011 s <-if here is 1

    S0100111R 10111100-s      <-than this 10111100 is going to some other table

    S0100111W 00000011 10111101 s

    S0100111W 00000011 s

    S0100111R 10111101-s

    S0100111

     

    So where in these numbers last number is say 0, than I take set of numbers (byte array) just under it and do something.

     

    PS.

    Before everything, I have to check IF after this big S this byte array is 0100111. If not, just ignore.

     

    I hope I am a little bit clear. :)

  5. Let's say I have this string:

    Quote

    S0100111W 00000010 sS0100111R 11101011-sS0100111W 00000010 11101111 sS0100111W 00000010 sS0100111R 11101111-sS0100111W 00000010 11111111 sS0100111W 00000011 sS0100111R 10111100-sS0100111W 00000011 10111101 sS0100111W 00000011 sS0100111R 10111101-sS0100111

    I would like to make it like this:
     

    Quote

     

    S0100111W 00000010 s

    S0100111R 11101011-s

    S0100111W 00000010 11101111 s

    S0100111W 00000010 s

    S0100111R 11101111-s

    S0100111W 00000010 11111111 s

    S0100111W 00000011 s

    S0100111R 10111100-s

    S0100111W 00000011 10111101 s

    S0100111W 00000011 s

    S0100111R 10111101-sS0100111

     

    With this:

    Quote

        $p1 = $p2 = 0;
        $sql=mysqli_query($con, "SELECT * FROM table WHERE deviceID=1");
                while($row = mysqli_fetch_array($sql,MYSQLI_ASSOC)){
                    $str = $row["data"];
                    while (($p1 = strpos($str, 'S', $p2)) !== false) {
                         $p2 = strpos($str, 's', $p1);
                         echo substr($str, $p1, $p2-$p1+1) . '<br>';
                         }
                   }

    I get this:

    Quote

    S0100000W 10001000 s
    S0100000W 00001000 s
    S0100000W 10001000 s
    S0100000W 10000000 s
    S0100000W 10001000 s
    S0100000W 00001000 s
    S0100000W 00001000 s
    S0100000W 00001000 s
    S0100000W 10001000 s
    S0100000W 10000000 s
    S0100000W 10001000 s
    S0100000W 00001000 s

  6. :)

    This is the output from an I2C scanner. There should be bunch of 1 and 0. Not 2 or 3, though. :)

    The idea is to sort it somehow from S to s. Later to match it with some other stuff, and sort it again.

     

    For a start, I should sort, then count the length, later to match, and so on...

    Let's say I have a 11101011 on some place here, I should compare it with some other pattern, assign a number, and that number store in db.

  7. Hi all,

    I have some data in database which is stored something like this:

    Quote

    S1234567 1234567s S1234567 1234567s S1234567 1234567s S1234567 1234567s

    As you may notice there is a pattern. My goal is to extract this data and print it from S to s in a loop.
     

    Quote

     

    S1234567 1234567s

    S1234567 1234567s

    S1234567 1234567s

    S1234567 1234567s

    S1234567 1234567s

     

    Can someone help me with this? It should find S and print all to the s.

    Not sure what function would be best to use.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.