Place to put your Basic demos and examples

Moderator: Mmiscool

User avatar
By Daniel Saiz
#57629 Hello, i got this error :
Error at line 70: Failed to reach end of input expression, likely malformed input
with that code :
Code: Select allwget(yourdomain.com/examples/myscript.php?name=Peter&age=25)


the same with :
Code: Select allwget("yourdomain.com/examples/myscript.php?name=Peter&age=25")


This code does not return any errors,
Code: Select allsql="yourdomain.com/examples/myscript.php?name=Peter&age=25"
wget(sql)

But not insert any data in the database, only 0 for name and 0 for age,

this works :
Code: Select allwprint wget("yourdomain.com/examples/myscript.php?name=Peter&age=25")

and inserts in database in name peter and age 25, but every time called the funtion generates a line in the
browser and after while crashes the esp.
which it is the correct way to use the wget ?

thank you
User avatar
By TheWaldorfer
#59938 Here's an updated working example(ESP Basic 3.0.Alpha 65):

Note that the PIN number can be different (on my ESP it is actually 4 instead of 2)

ESP:

Code: Select allclearmem
cls
print "Hello"
dev = "ESP1"
mo = "Door/Window opened"
mc = "Door/Window closed"
st = 0
p = 2
st = io(pi,p)
print "ESP ist waiting for Pin " & p & " to change..."
interrupt p, [gpio]
Wait
[gpio]
nst = io(pi,p)
if nst = 0 then
   url = "192.168.178.23/esp/esppin.php?Action=Message&mfrom=" & dev & "&mto=System&mtype=1&mess=" & mo
   gosub [urlencode]
   print wget(url)
else
   url = "192.168.178.23/esp/esppin.php?Action=Message&mfrom=" & dev & "&mto=System&mtype=2&mess=" & mc
   gosub [urlencode]
   print wget(url)
end if
st = nst
wait

[urlencode]
url = replace(url," ", "+")
print url
return


PHP:

Code: Select all<?php

$host = "HostName";
$user = "DBUser";
$pw = "PW";
$db = "DBName";

$con = mysqli_connect($host,$user,$pw) or die(mysqli_error());
mysqli_select_db($con,$db) or die(mysqli_error());
mysqli_query($con,"SET CHARACTER SET utf8");
mysqli_query($con,"SET NAMES 'utf8'");

$action=$_GET["Action"];


switch ($action) {
   
   Case "Message":
       $mfrom=$_GET["mfrom"];
      $mto=$_GET["mto"];
      $mtype=$_GET["mtype"];
      $mess=$_GET["mess"];
   
      $r = mysqli_query($con, "Insert into mess (st, mfrom, mto, mtype, mess) VALUES ('I', '$mfrom', '$mto', '$mtype', '$mess')") or die(mysqli_error($con));
      
      print 'OK';
      break;
   
   
default:
      print json_encode ("Error: Function not defined ->" . $action);
}