|
Forum Index : Microcontroller and PC projects : WiFi Logger
| Author | Message | ||||
| MikeO Senior Member Joined: 11/09/2011 Location: AustraliaPosts: 275 |
Using the 8 port controller PCB I posted recently I just completed a simple wifi logger system, this is not a complete project more a proof of concept. I used matherp's cfunctions for serial flash together with my UMite to ESP8266 routines which allow UDP network transmissions to a Windows PC. It is also possible to send email from this combination which could be used for various notifications like, low power supply, sensor warnings out of range, controller resets etc. A proper project would probably have a Java app for dumping the data to a file by day and month etc. Mike ![]() ![]() 'http://www.codenquilts.com.au 'Michael Ogden June 2018 'Micromite MMBasic Geoff Graham 'cFunctions Peter Mather 'uMite MX170 Logger example(using 8 Port Controller v1.3 PCB) 'data stored in Flash Ram 'v1.1 '***************** Flash Routines ************* '1-15000 pages, fpg% holds last page written ''Subs 'f.clear() 'initialise and clear memory 'f.open(page) 'initialise only 'f.write(page,data,[rewrite=1]) ''Functions 'f.read$(page) 'f.search$(page,lookup) '************************* 'Flag List (Examples) Flag(20) set in library '0=err '1=timeout '3=read Flash '4=restart Option Explicit Option Default Integer Option autorun On dim f.pos% Dim integer Secs dim xx% const dest$="ESP_Svr" Const NumofMonth$="JAN,FEB,MAR,APR,MAY,JUN,JLY,AUG,SEP,OCT,NOV,DEC" Dim wholedate$ sub MM.STARTUP 'must contain variable Nowifi, debug 'set Nowifi=1 if no ESP8266 dim integer Nowifi=0 'set debug=1 to receive all ESP8266 data dim integer debug=0 dim w170name$="" dim w170pass$="" dim w170node$="ESP_8port" end sub 'resarts flag(4)=1 flag(8)=1 'interupts Settick 1000 ,T1,1 'establish seconds "Tick Timer" setupemail pause 3000 fpg%=100 f.open 'test data ' for xx%=1 to 100 ' ' f.write(xx%,"page number:"+str$(xx%,4)+ ",90,0,0,29,0,23.2,57.4,1021.0,25.7,39.1,18:16:32,192.168.0.9",1) ' ' next print "current page is "; fpg% '*** This portion add to User program main program loop ********************* Do 'user program Do Loop ' WatchDog 8000 'optional but recommended ' '***** mxWiFi Hook **** If userprocessflag=1 Then StartTime = Timer UserProcess UserProcessFlag=0 xbsend "udp.send:|"+from$+"|"+Chr$(4)+"|" Print "Processing elapsed time"; Timer-StartTime EndIf '***** End mxWiFi Hook **** if flag(3)=1 then if f.pos%>fpg% then 'greater than last page? flag(3)=0 else readflash end if end if ' if secs mod 30 = 0 Then ' log data every 30 secs for example ' collect data from sensors to data$ ' fpg%=fpg%+1 'lastpage ' f.write(fpg%,date$+","+ data$,1) ' ' end if ' Loop 'user program Do Loop '***** End main program loop 'T1 - 1second Tick interrupt 'set up some time flags Sub T1 local x secs=secs+1 'update seconds timer ' pulse 23,50 if secs => 86400 then '24 hrs reached secs = 0 'reset counter FLAG(8)=1 'set NTP flag , for RTC correction EndIf if secs mod 25 = 0 Then 'every 25 secs if flag(8)=1 then print "Try to get NTP data" xbsend "time:" 'try to get NTP time data end if end if if secs mod 7200 = 0 then 'every 120 mins 'FLAG(8)=1 'set NTP flag , have RTC FLAG(12)=1 'set SaveToFlash flag endif End Sub 'Optional External command processing sub Routine ' if required, called by library Sub extCmd Print "External Commands:- From:";from$;" Cmd:";cmd$;" Config:";cfg$;" Data:";strin$ 'printline "From:"+from$+" Cmd:"+cmd$+" Config:"+cfg$+" Data:"+strin$ select case cmd$ case "reset" secs = 0 'reset counter FLAG(8)=1 'set NTP flag , for RTC correction print "Reset counters and RTC correction" case "ntp" wholedate$=parse$(strin$,1," ")+" "+parse$(strin$,3," ")+" "+parse$(strin$,2," ")+" "+parse$(strin$,5," ") if wholedate$<>"" then flag(8)=0 'reset NTP flag time$=left$(parse$(strin$,4," "),5) print time$ print wholedate$ temp$=ucase$(parse$(strin$,2," ")) date$=parse$(strin$,3," ")+"-"+Str$(moy(temp$),2)+"-"+parse$(strin$,5," ") print date$ If IsDST()=1 Then IncTime if flag(4)=1 then sendemail ("from Logger","Logger restarted at " + wholedate$ +" @ "+time$) flag(4)=0 end if 'time$="23:59:00" 'test for midnight end if case "uMclear" f.clear case "uMopen" f.open case "uMdump" print "dump flash" flag(3)=1 f.pos%=1 end select End Sub 'End of Optional External command processing sub Routine 'open Flash and send via UDP sub readflash local d$ d$=f.read$(f.pos%) print d$ if d$<>"" then xbsend "udp.send:|"+dest$+"|flash|flash.txt|"+d$ WaitforReady 'reset flag f.pos%=f.pos%+1 else flag(3)=0 xbsend "udp.send:|"+dest$+"|flash-Close|" WaitforReady 'reset flag end if End Sub sub sendemail(esub$,ebody$) print "Sending email..." xbsend "email:mike@codenquilts.com.au:mike@codenquilts.com.au:"+esub$+":"+ebody$ pause 3000 end sub sub setupemail print "Setup email......" local string providor$="mail.smtp2go.com" local string username$="" 'your account details local string password$="" local string portnum$="2525" xbsend "emailsetup:"+providor$+":"+portnum$+":"+username$+":"+password$+":" end sub Codenquilts |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |