Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 23:54 27 Nov 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 : Wifi Communication between two Webmites

Author Message
Derek_H
Newbie

Joined: 26/07/2023
Location: United Kingdom
Posts: 10
Posted: 04:15pm 20 Aug 2023
Copy link to clipboard 
Print this post

A real novice here (and ancient to boot!)
I'm measuring 2 local temperatures with DS18B20 and sending them to a web page hosted on the Webmite using MMBasic. This page is available to any browser equipped device on the local network.
I'd like to measure two more temperatures, but the sensors will be some distance away and any cable runs would be physically difficult.
My idea is to use a second Webmite reading the temperatures from 2 more DS18B20 sensors.
Both Webmites would be on the same wifi network with their own static IP's.

My question is, how would I get the temperature values from the basic program running on the second Webmite into the MMBasic web server running on first Webmite.
 
Andy-g0poy
Regular Member

Joined: 07/03/2023
Location: United Kingdom
Posts: 59
Posted: 05:41pm 20 Aug 2023
Copy link to clipboard 
Print this post

I know nothing about the web version of MMBASIC a wifi pico only turned up a couple of days ago :-)

There are several methods, the simple method is to open up some form of TCP port on both computers, and one listens on the port the other sends. Think of it as a wireless serial connection. You just treat it as such. You may already use something like this if you telnet or ssh into something

The thing I wanted to point out is the range. The antennas on the picos are tiny, and if the signal is poor you will have a lot of trouble. So it might be worth having a walk around with a wifi signal detector on a smartphone and see what you get.

If the signal is strong then no problem.

However if it's not good then maybe another option needs to be employed. Try a 430Mhz Tx/Rx module pair. They are simple serial devices, and have a much better range. Another advantage is that you don't have to use a wifi pico at the remote end :-)

Andy
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2914
Posted: 08:10pm 20 Aug 2023
Copy link to clipboard 
Print this post

Hi Derek,

Further on what Andy said, use a pair of HC-12 modules. These are ver simple devices, fed by a serial line and transmitted on 433MHz. The receiver sends on the serial line they are bi directional

Beware there are a lot of clones out there of dubious quality, Grogster on this board buys direct from the manufacturer so you will get genuine if you get them from him.

Regards,

Mick
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
okwatts
Regular Member

Joined: 27/09/2022
Location: Canada
Posts: 59
Posted: 09:05pm 20 Aug 2023
Copy link to clipboard 
Print this post

An alternative using 433 MHz send and receive I used about 10 years ago (although it was Arduino based) can be found at
https://www.osengr.org/Projects/Canberra-Wireless-Sensor/Canberra-Wireless-Sensor.shtml

An Aussie by the name of Maurie Daly devised this sensor and used Oshonsoft Basic to send to the base station. You might be able to build the sensors and look at the basic code to implement on a Pico W base and then do the web interface. Likely more work to build and program but it would be compatible with a commercial system (Oregon Scientific - maybe no longer in existence). If you were looking to use more than a couple it might prove to be cheaper as well as provide a learning experience. I built 4 at least and they are still running but to a Windows based application referenced in the link. I have been toying with the idea of providing a web interface but the Window application keeps a log of all readings.
The other side benefit is that an SDR application exists to observe and reports from these 433 Mhz sensors.
Have fun!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6100
Posted: 09:08pm 20 Aug 2023
Copy link to clipboard 
Print this post

On the 'slave' WEBmite, set up a web server with a simple page giving the required temperature readings.

On the main WEBmite use WEB TCP CLIENT REQUEST to fetch that page.
Once you have it, extract the data and insert it into the main WEBmite's web pages.

Simple and no other hardware needed.
It also keeps the HTML simple.

Jim
VK7JH
MMedit   MMBasic Help
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4246
Posted: 06:38am 21 Aug 2023
Copy link to clipboard 
Print this post

Jim,

It sounds very simpel as you explain it. Is it possible for you to write both webmite (demo) programs in simplest possible form. This is something very usefull to add to the Webmite user manual. And I would learn how to do it.

Thank you in advance for the tip.

Volhout
PicomiteVGA PETSCII ROBOTS
 
Derek_H
Newbie

Joined: 26/07/2023
Location: United Kingdom
Posts: 10
Posted: 09:29am 21 Aug 2023
Copy link to clipboard 
Print this post

Thanks for all the great suggestions.

I've checked the wifi signal at both locations and it's good. So I don't think I'll need external radios to make the connection.

I'll have to read up more on using TCP.

I like the idea of setting up another web server on the remote Webmite, then extracting  
the data from there to place in the main webpage.

Like Volhout, I'm not sure exactly how to extract the data from the slave webserver, but I'm going to see what I can do with this.
I don't yet have a second Pico W, so I'm going to get one on order and then work on this suggestion.

Again, thanks to all.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9126
Posted: 09:32am 21 Aug 2023
Copy link to clipboard 
Print this post

You can also use UDP - probably simpler than TCP. See the thread on the 5.07.08 Webmite beta for details
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6100
Posted: 09:50am 21 Aug 2023
Copy link to clipboard 
Print this post

UDP is simpler but TCP allows you to use a web browser to test both picos individually.
I will look at doing something simple to demonstrate but it might be a day or two.

Jim
VK7JH
MMedit   MMBasic Help
 
Derek_H
Newbie

Joined: 26/07/2023
Location: United Kingdom
Posts: 10
Posted: 04:33pm 21 Aug 2023
Copy link to clipboard 
Print this post

Thanks Jim,

I've ordered a couple more Pico W, but they'll be a few days away.

Derek
G0PBQ
 
atmega8

Guru

Joined: 19/11/2013
Location: Germany
Posts: 722
Posted: 05:11pm 21 Aug 2023
Copy link to clipboard 
Print this post

You can also exchange the Informations/Data etc. filebased;-)

TFTP: Once connected the WebMite will automatically enable its TFTP server so that files can be copied to/from the WebMite over the WiFi network.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6100
Posted: 09:02pm 21 Aug 2023
Copy link to clipboard 
Print this post

  atmega8 said  You can also exchange the Informations/Data etc. filebased;-)

TFTP: Once connected the WebMite will automatically enable its TFTP server so that files can be copied to/from the WebMite over the WiFi network.


TFTP is great for transferring between WEBmites and PCs etc but he wants to transfer data between two WEBmites. You can't use TFTP for that. WEBmites are only TFTP servers.

Jim
VK7JH
MMedit   MMBasic Help
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6100
Posted: 05:57am 22 Aug 2023
Copy link to clipboard 
Print this post

Install the main program on the "remote" WEBmite. along with this index.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>Remote location</title>
<p align="center">Temperature is {CPUtemp}</p>
</body></html>

You shold be able to connect with any web browser.
Load the same program on the "Main" WEBmite along with this index.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>Main server</title>
<meta http-equiv="Refresh" content="15"></head><body>
<p align="center">Temperature is {CPUtemp}</p>
<p align="center">Remote Temperature is {remoteTemp}</p>
</body></html>

Lines 7 and 8 need changing. to the remotes IP and set isMaster =1

I have left AUTORUN disabled for now.
In the bas program these lines fetch the remote data and convert it ready for the main mite to display it.
 IF isMaster THEN
   WEB OPEN TCP CLIENT slaves$, 80
   WEB TCP CLIENT REQUEST "GET /index.html HTTP/1.1", inbuff%()
   WEB CLOSE TCP CLIENT
   'Longstring print inBuff%()
   r = LINSTR(inbuff%(), "Temperature") + 15
   remoteTemp = VAL(LGETSTR$(inbuff%(), r, 4))
   CPUtemp = PIN(temp)
 ELSE



BAS program:
 ' RTV monitor kw\WEBmite
 OPTION EXPLICIT
 OPTION DEFAULT INTEGER
 'option autorun on
 DIM Buff%(512)
 DIM inBuff%(512)
 DIM slaves$ = "10.1.0.230" ' this is the remote IP, needed on the Master
 CONST isMaster = 0          ' set to 1 for Master
 CONST qt$ = CHR$(34)
 CONST Maxargs=20
 CONST html_def$ = "index.html"
 
 DIM tickTime, CPUtemp, Quit
 DIM FLOAT remoteTemp
 DIM k$
 
 SETTICK 10000, ticker         ' reading temperature at 10 second interval
 WEB TCP INTERRUPT gotrequest
 ticker
 DO
   IF tickTime THEN dotick
   k$ = INKEY$
   IF k$ <>"" THEN
     SELECT CASE k$
       CASE "X","x"
         OPTION AUTORUN OFF
         WATCHDOG hw OFF
         Quit = 1
     END SELECT
   ENDIF
   WATCHDOG hw 8000
 LOOP UNTIL Quit
 
SUB ticker
 tickTime = 1
END SUB
 
SUB dotick
 LOCAL logstate, minLog$, hr$, r
 ' do all the readings here
 tickTime = 0
 WATCHDOG hw 8000
 IF isMaster THEN
   WEB OPEN TCP CLIENT slaves$, 80
   WEB TCP CLIENT REQUEST "GET /index.html HTTP/1.1", inbuff%()
   WEB CLOSE TCP CLIENT
   'Longstring print inBuff%()
   r = LINSTR(inbuff%(), "Temperature") + 15
   remoteTemp = VAL(LGETSTR$(inbuff%(), r, 4))
   CPUtemp = PIN(temp)
 ELSE
   CPUtemp = PIN(temp)*RND() ' randomise the slave so you can see changing values
 ENDIF
END SUB
 
SUB gotrequest
 LOCAL p%, t%, a%, s$, i, nparams, page$, page_ext$, cons$, newfolder$
 LOCAL arg$(1,maxargs-1), endtime
 FOR a%=1 TO MM.INFO(MAX CONNECTIONS)
   IF NOT MM.INFO(TCP REQUEST a%) THEN CONTINUE FOR
   LONGSTRING CLEAR Buff%()
   WEB TCP READ a%,Buff%()
   'Longstring print Buff%()
   IF LLEN(Buff%()) THEN
     page$=parsehtmldata$(nparams,Buff%(), arg$())
     ' if page$ = "" then page$ = html_def$
     IF INSTR(page$,".") THEN
       page_ext$ = LCASE$(FIELD$(page$,2,"."))
     ELSE
       page_ext$ = ""
     ENDIF
     IF MM.INFO$(FILESIZE page$) > 0 THEN ' file does exist.
       SELECT CASE page_ext$
         CASE "html", "htm"
           WEB TRANSMIT PAGE a%,page$
         CASE "ico"
           WEB TRANSMIT FILE a%,page$,"image/vnd.microsoft.icon"
         CASE "jpg"
           WEB TRANSMIT FILE a%,page$,"image/jpeg"
         CASE "png"
           WEB TRANSMIT FILE a%,page$,"image/png"
         CASE "gif"
           WEB TRANSMIT FILE a%,page$,"image/gif"
         CASE "bmp"
           WEB TRANSMIT FILE a%,page$,"image/bmp"
         CASE "js"
           WEB TRANSMIT FILE a%,page$,"script/javascript"
         CASE "txt", "csv", "bas", "py"
           WEB TRANSMIT FILE a%,page$,"text/plain"
         CASE "cgi"
           WEB TRANSMIT FILE a%,page$,"application/x-httpd-cgi"
         CASE ""
           WEB TRANSMIT FILE a%,page$,"text/plain"
         CASE ELSE
           WEB TRANSMIT PAGE a%,"notfound.html"
           WEB TRANSMIT CODE a%, 404
       END SELECT
     ELSE
       WEB TRANSMIT PAGE a%,"notfound.html"
       WEB TRANSMIT CODE a%, 404
     ENDIF
   ELSE
     '
   ENDIF
 NEXT a%
END SUB
 
FUNCTION parsehtmldata$(paramcount AS INTEGER, inbuf() AS INTEGER, arg$())
 CONST starttext$="HTTP"
 LOCAL a$,b$, post
 LOCAL INTEGER buf(BOUND(inbuf()))
 LOCAL INTEGER inpos,startparam,processargs
 paramcount=0
 inpos=LINSTR(inbuf(),"GET /",1)
 IF inpos=0 THEN inpos=LINSTR(inbuf(),"post /",1): post = 1
 IF inpos=0 THEN
   parsehtmldata$=""
 ELSE
   LONGSTRING MID buf(),inbuf(),inpos+5+post
   inpos=LINSTR(buf(),starttext$,1)
   IF inpos>2 THEN 'page request found
     inpos=inpos-2
     a$=LGETSTR$(buf(),1,inpos)
     ' print a$
     inpos=INSTR(a$,"?")
     IF inpos<>0 THEN 'parameters found
       processargs=1
       parsehtmldata$=LEFT$(a$,inpos-1)
       a$=MID$(a$,inpos+1)
       DO
         arg$(0,paramcount)=""
         arg$(1,paramcount)=""
         inpos=INSTR(a$,"=")
         startparam=1
         arg$(0,paramcount)=MID$(a$,startparam,inpos-startparam)
         startparam=inpos+1
         inpos=INSTR(a$,"&")
         IF inpos<>0 THEN
           arg$(1,paramcount)=MID$(a$,startparam,inpos-startparam)
           a$=MID$(a$,inpos+1)
           paramcount=paramcount+1
         ELSE
           arg$(1,paramcount)=MID$(a$,startparam)
           paramcount=paramcount+1
           processargs=0
         ENDIF
       LOOP WHILE processargs
     ELSE
       parsehtmldata$=a$
     ENDIF
   ELSE ' no page requested
     parsehtmldata$= html_def$
   ENDIF
 ENDIF
END FUNCTION


point your PC web browser to the main WEBmite and you should see:



The second line is from the remote mite.

This is one of many ways to skin the cat.

Jim
VK7JH
MMedit   MMBasic Help
 
atmega8

Guru

Joined: 19/11/2013
Location: Germany
Posts: 722
Posted: 06:04am 22 Aug 2023
Copy link to clipboard 
Print this post

  TassyJim said  
  atmega8 said  You can also exchange the Informations/Data etc. filebased;-)

TFTP: Once connected the WebMite will automatically enable its TFTP server so that files can be copied to/from the WebMite over the WiFi network.


TFTP is great for transferring between WEBmites and PCs etc but he wants to transfer data between two WEBmites. You can't use TFTP for that. WEBmites are only TFTP servers.

Jim


Ok, no Client, no bidirectional communication…..
Sorry
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3802
Posted: 06:57am 22 Aug 2023
Copy link to clipboard 
Print this post

  atmega8 said  Ok, no Client, no bidirectional communication…..
Sorry

I think that's right for WebMite TFTP.

John
 
Derek_H
Newbie

Joined: 26/07/2023
Location: United Kingdom
Posts: 10
Posted: 11:29am 24 Aug 2023
Copy link to clipboard 
Print this post

I've now received another Pico W.
I've been able to set up communication between two Webmites via an HTML page. It's working great, thanks to all especially to Tassy Jim.

I upgraded to WebMiteV5.07.08b4 in order to be able to use fixed IP addresses. This works fine on my remote Webmite.
However the master is getting NTP time from the internet. This works fine if I let the router allocate the IP address, but if I fix the IP address it fails. I can't see where  my error is.

'Setup NTP time
DO WHILE MM.INFO(IP ADDRESS) = "0.0.0.0"
IF TIMER > 5000 THEN CPU RESTART
LOOP

ON ERROR SKIP 3
WEB NTP 1
IF MM.ERRNO THEN WEB NTP 1
IF MM.ERRNO THEN PRINT "Failure to connect to the Internet" : CPU RESTART


When using fixed IP I get the error message from the last line above in the console output.

Pico_MS connecting to WiFi...
Connected 192.168.1.242
Starting TCP server at 192.168.1.242 on port 80
Failure to connect to the Internet


When using DHCP I get

PICOE6616408437 connecting to WiFi...
Connected 192.168.1.242
Starting TCP server at 192.168.1.242 on port 80
ntp address 162.159.200.1
got ntp response: 24/08/2023 11:59:05


If I comment out the NTP time code above there are no error messages when using fixed IP address.

I'm sure it must be some rookie error, but I'm not seeing it.

Derek
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6100
Posted: 11:33am 24 Aug 2023
Copy link to clipboard 
Print this post

Fixed IP probably doesn't get you a gateway address.

Much better to let the router assign the same IP each time.

Jim
VK7JH
MMedit   MMBasic Help
 
Derek_H
Newbie

Joined: 26/07/2023
Location: United Kingdom
Posts: 10
Posted: 02:59pm 24 Aug 2023
Copy link to clipboard 
Print this post

OK, thanks Jim, I'll stick with DHCP then.
Cheers, Derek
G0PBQ
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9126
Posted: 03:27pm 24 Aug 2023
Copy link to clipboard 
Print this post

  Quote  Fixed IP probably doesn't get you a gateway address.


Should do if you specify it

OPTION WIFI SSID$, PASSWD$, [NAME$] [,IPADDRESS$, MASK$, GATEWAY$]

see bottom of here
 
Print this page


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

© JAQ Software 2024