Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 21:05 27 Jul 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Webmite help...

Author Message
Malibu
Senior Member

Joined: 07/07/2018
Location: Australia
Posts: 169
Posted: 05:13am 18 Sep 2023
Copy link to clipboard 
Print this post

Ok, my brain has gone mushy trying to figure this out, and I'm in need of some help. I can't understand what's going on...

I won't bore you with the background, but I've loaded the Garden Controller system into the 'mite so I have a known, working base to start from (My own code was doing similar, that's why I loaded the Garden code).
Loading the index, there's no problems... click on 'Configure' and I get to the correct page (in this case, Schedule 1)
Clicking on 'Return to home page' and it does exactly that...

First up... It's the latest version of the Garden code, and the latest version of MM O/S.
Importantly, this problem ONLY seems to happen in Opera (also the latest version)

So, clicking on 'Configure', here's the data that is transferred -
  Quote  GET /config0.html HTTP/1.1
Host: 192.168.0.114
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 OPR/102.0.0.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
18-09-2023 14:29:42  Sending configuration page

...and the correct page comes up. All good so far...

If I click on 'Save Changes', this is the data that is transferred -
  Quote  Title=Test+Schedule&Enabled=on&StartDay=17&StartMonth=9&EndDay=17&EndMonth=10&RunDOW0=on&RunDays=&RunHours=0&RunMints=0&RunStart=Sw0&ValveR0=15&ValveR1=&ValveR2=&ValveR3=&ValveR4=&ValveR5=&ValveR6=&ValveR7=&RunIncrease=&TempThresh=&SubmitForm=+SAVE+CHANGES+
18-09-2023 14:30:40  Sending error 404 page not found

...and I get a 404 error in the browser.

It seems to be missing the "POST" part of the data, and I can't figure out why.

As I say, seems to only be Opera (I've tried Firefox, Waterfox, Edge and Chrome and they all work fine, resulting in the same Config page, with the notification it was Saved OK)

Am I missing something, or is Opera playing games with me?
John
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8684
Posted: 07:00am 18 Sep 2023
Copy link to clipboard 
Print this post

  Quote  Am I missing something, or is Opera playing games with me?


I think you have answered your own question

  Quote  As I say, seems to only be Opera (I've tried Firefox, Waterfox, Edge and Chrome and they all work fine,
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9204
Posted: 08:14am 18 Sep 2023
Copy link to clipboard 
Print this post

I still use Opera, but I am liking it less and less since they rebranded it "Opera One".  It DOES have some very nice features, but some instabiolity has crept into the mix in these latest versions that was not there before.

Simple answer - DON'T use Opera with the Webmite, use one of the others that you yourself have already confirmed work fine.

I also hate Opera's forced upgrade policy - VERY worthy of Microsoft....perhaps the developer of the forced updates in Windoze has gone to work for Opera One....

Even if you uninstall Opera and install an older version - that then works as you want - Opera auto-updates WITHOUT asking you if you want to, and there is no(easy) way to prevent that from happening.  So, if you have a buggy version of Opera One, it will always auto-update to it, weather you want that to happen or not.

It's crazy.  

There are ways to disable the auto-update, but it involves lots of hoop-jumping and even registry hacks to prevent Opera being able to find the update server, so the update attempts just fail - permanently - but the user should not have to go to that kind of extreme, if they just made it a damn check-box or switch in the settings or something.

....but I digress - and rant.....  
Smoke makes things work. When the smoke gets out, it stops!
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6027
Posted: 08:21am 18 Sep 2023
Copy link to clipboard 
Print this post

I've just switched to Brave. It seems to be rather good so far. I've not tried it with a Webmite, of course, as I don't have one. :)  Like most, it's based on the Chromium core so it should be ok.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Malibu
Senior Member

Joined: 07/07/2018
Location: Australia
Posts: 169
Posted: 08:25am 18 Sep 2023
Copy link to clipboard 
Print this post

No worries, but I'm not sure that's the answer...
What started me on this crusade was trying to do the same SORT of thing from a mobile phone with the those same results. I figured it was my coding (or, lack of) skills...
With a fresh install (latest version) of Firefox onto an iPhone (with latest O/S), the same results happen with the Garden code (I figure, it works, so it must be correct), as well as the code that I'm testing with.

I appreciate your input  
I'll keep beavering away and see what I can come up with.

Thanks for the reply  
John
 
Malibu
Senior Member

Joined: 07/07/2018
Location: Australia
Posts: 169
Posted: 08:30am 18 Sep 2023
Copy link to clipboard 
Print this post

  Quote  ....but I digress - and rant.....


Nope, not a problem... I have the same issues with Opera - AND iPhone

I'll check out Brave, maybe it'll 'play nice'  
John
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9204
Posted: 08:43am 18 Sep 2023
Copy link to clipboard 
Print this post

I'd forgotten about Brave.
I remember trying it a while back, and liked it so.....
Smoke makes things work. When the smoke gets out, it stops!
 
carlschneider
Senior Member

Joined: 04/08/2023
Location: South Africa
Posts: 148
Posted: 03:31pm 18 Sep 2023
Copy link to clipboard 
Print this post

I had similar issues with POST on Safari but worked fine on Chrome.

Wireshark showed the correct headers and payload.

Ended up writing my code to only use GET, which works reliably in Safari.

https://www.thebackshed.com/forum/ViewTopic.php?TID=16027&PID=209012#209012#209012
Edited 2023-09-19 01:35 by carlschneider
Cheers Carl                                                        
Retirement is tough on Hobbies without a day job
 
Malibu
Senior Member

Joined: 07/07/2018
Location: Australia
Posts: 169
Posted: 07:15am 19 Sep 2023
Copy link to clipboard 
Print this post

Thanks to everyone for the help, I couldn't wrap my little brain around what was happening...

  Quote  I had similar issues with POST on Safari but worked fine on Chrome.

Thanks for the heads up Carl, that confirmed a couple of things for me that I could work on from there.

So, while doing some mundane robotics at work today, I had some time to ponder a solution. Here's what I've come up with so far (maybe it'll change as I do a little more coding)

First, in the HTML - the "Save Changes" button, I recoded from this -
  Quote  <input type="submit" name="SubmitForm" value=" SAVE CHANGES " />

to this -
  Quote  <input type="submit" name="SubmitManual" value=" SAVE CHANGES " />


Then, in the MMcode, I did this -
  Quote       ---Previous code here---
       ElseIf LInStr(b(),"SubmitManual") > 0 then
         print "Manual"
         CurTime = time$
         CurDate = day$(now) + "  " + Date$
         ProcessManualData b()
         SendManualPage a%
       ElseIf ---Continue onto the next part of the code---


The code in between the 'ElseIf' statements is not important, that's just what my coding points to: the first ElseIf is the crux because when data arrives via the Web TCP, the Longstring buffer will contain the name of the form sending the data... ie: "SubmitManual"
No matter if the POST header is there or not, the code searches for 'SubmitManual' and already knows it MUST have been from a POST header, even if it's not there... The code also knows WHICH page sent the data. In this case, it was the 'Manual' page.
As long as the HTML names are individual to each page, theory says that it should all work.

So far, it's early days... but it's looking good so far.

I hope this helps anyone else that gets tripped up like me...  
John
 
TheMonkeys

Regular Member

Joined: 15/12/2022
Location: Australia
Posts: 59
Posted: 11:40am 19 Sep 2023
Copy link to clipboard 
Print this post

Hi John.

It might be that the form action is an empty string?
usually this means that it submits to the current page, but cannot be guaranteed.

Cheers,

Chris.
 
Malibu
Senior Member

Joined: 07/07/2018
Location: Australia
Posts: 169
Posted: 10:01pm 22 Sep 2023
Copy link to clipboard 
Print this post

Been plugging away on this for a while... I think I got the solution worked out that does well for me. Who would have thought the HTML standards are different depending on which browser is running?
Anyway, using the GetNextPair sub from Geoff's Retic program, I recoded and added to it.

sub GetNextPair b%(), i as integer, n$, value$ 'All the information we need is here
 local Integer StartPos, EndPos, StrLen, CharPos
 local String TmpString
 do 'Remove any Header data that comes through from browsers
   EndPos = linstr(b%(), chr$(13),1) 'Search for a LF character
   if EndPos <> 0 then 'We found a LF char
     longstring trim b%(), EndPos 'Trim that line from the header
   else
     exit do 'Otherwise, no more LF chars... get out of the loop
   end if
 loop 'Go and look for another LF char
 EndPos = linstr(b%(), "&", 1) 'All done, now look for an & so we can get the data
 StrLen = EndPos - 1 'Calculate the length of the data
 if EndPos = 0 then 'if there is no & found, we've reached the end
   i = 0 'Set the value to 0 and pass back to caller
   exit sub 'Get out of here, we're all done
 end if
 TmpString = lgetstr$(b%(), 1, StrLen) 'Extract a string to work on
 'print TmpString 'For debug
 CharPos = instr(TmpString, "=") 'Get the postion of the = so we can split the string into 2
 n$ = left$(TmpString,CharPos-1) 'Get the left part of the string and assign it to 'Name'
 value$ = ConvertStr(mid$(TmpString,CharPos+1)) 'Convert the right part of the string and assign it to 'Value'
 'print CharPos, n$, value$ 'For debug
 longstring trim b%(), StrLen + 1 'Trim off the data that we just worked on, ready for the next manipulation
end sub


function ConvertStr(TmpStr as string) as string 'Cleanup the Raw String
 local integer i
 local TmpChr as string
 for i = 1 to len(TmpStr) 'Determine length of the string
   TmpChr = mid$(TmpStr, i, 1) 'Get the character
   if TmpChr = "+" then TmpChr = " " 'Any + chars are replaced with real spaces
   if TmpChr = "%" then 'A % char indicates a 'special' char
     TmpChr = mid$(TmpStr, i+1, 2) 'get the next 2 character (to use as a HEX number)
     If TmpChr = "22" then TmpChr = "27" 'If it's double quote, change it to single quote
     TmpChr = chr$(val("&H" + TmpChr)) 'change to a HEX value, and convert into a character
     i=i+2 'Add 2 to the pointer, to keep counting the correct character sequence
   end if
   ConvertStr = ConvertStr + TmpChr 'Add the new character and build up the clean string
 next i
end function 'All done, pass the new string back to the function call


(Sorry, lots of comments so it looks a bit crowded)

Basically, it takes whatever comes from the browser and strips all the header information (if it's there) and just works on the actual data that is needed.
I also added a function to 'cleanup' any spaces, etc in the strings.
I also found that browsers pass a % for special characters (like #, &) so the function also sorts them out into plain text.

A bit of work, and I'm sure it could be coded a bit tighter, but hopefully it'll handle anything that comes through from the browser.
Hope this helps anyone with the same problem :)
John
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3708
Posted: 10:10pm 22 Sep 2023
Copy link to clipboard 
Print this post

Just a nit: chr$(13) is CR not LF.

John
 
Malibu
Senior Member

Joined: 07/07/2018
Location: Australia
Posts: 169
Posted: 10:26pm 22 Sep 2023
Copy link to clipboard 
Print this post

  Quote  Just a nit: chr$(13) is CR not LF.




Yup... of course it is... I shoulda known better, thanks!
Fixed :)

...and the reason I use LF is because I've seen some headers come with CRLF and some only with LF
So, that would have tripped me up eventually.
John
 
carlschneider
Senior Member

Joined: 04/08/2023
Location: South Africa
Posts: 148
Posted: 11:06pm 22 Sep 2023
Copy link to clipboard 
Print this post

Hi John

Maybe you need to consider the CRLF pair as well as whatever happens in your case. The below Wireshark capture for illustration reflecting all the CRLF as defined by HTTP.



In my case, although Safari was sending the correct Headers, understood and sniffed by Wireshark, the WEB Read on the WebMite was only getting the full Header into the buffer in about 1 in 13+ attempts. Most of the time the buffer only contained the JSON string payload being sent.

I decided that duplicating the analysis of the buffer to cater for JSON payload only and the 1 in occasionally that the full Headers arrived in the buffer wasn't worth it. If you only cater for the anomaly, when the correct Header gets through then it's a 404 situation.

But I needed it to work on my iPad as well as everywhere else, so I went with GET, which works reliably across all my browsers on all my devices.

Best of luck
Cheers Carl                                                        
Retirement is tough on Hobbies without a day job
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024