123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774 |
- # 主業務邏輯中的視圖和路由的定義
- import os
- import datetime
- from flask import Flask, redirect, render_template, request, session, Response, jsonify
- from sqlalchemy.sql.expression import desc, false, null
- # 導入藍圖程序,用於構建路由
- from werkzeug.utils import redirect
- from werkzeug.wrappers import response
- from . import main
- from coffee_manage import mqtt
- # 導入db,用於操作數據庫
- from coffee_manage import db
- # 導入實體類,用於操作數據庫
- from ..models import *
- import json
- from datetime import datetime as dt
- from sqlalchemy import text
- import pymysql
- import pandas as pd
- from concurrent.futures import ThreadPoolExecutor
- import cv2
- import pickle
- import socket
- import time
- import threading
- import numpy as np
- import math
- from .mqtt import MQTT
- from matplotlib import pyplot as plt
- import random
- from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg as FigureCanvas
- import io
- from flask import make_response
- from distutils.util import strtobool # 將字串 string 轉成布林 boolean
- import psutil
- pool = ThreadPoolExecutor(25)
- s_sock = 0
- lock = threading.Lock()
- '''
- mydb = pymysql.connect(host='52.69.200.169', port=3306, user='coffee',
- password='skyeye', database='Coffee', charset='utf8')
- mycursor = mydb.cursor()
- '''
- # 主頁的訪問路徑
- @main.route('/')
- def main_index():
- # 獲取登入信息
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- # Rita 參數 params 是用來取得參數的 locals=() 所有參數
- return render_template('index.html', params=locals())
- else:
- return render_template('sign_in.html')
- # Rita 測試
- # 使用者名稱測試
- @main.route('/test', methods=['GET', 'POST'])
- def test():
- info = request.args.to_dict()
- print(info)
- print("info[command]: ", info['command'])
- return json.dumps(info)
- # !!! AttributeError: 'NoneType' object has no attribute 'vacuum'
- @main.route('/demo', methods=['GET', 'POST'])
- def demo():
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- clean_status = clean_container_status.query.order_by(text('datetime desc')).first()
- CI1 = clean_status.Clean_Input_1
- CI2 = clean_status.Clean_Input_2
- C1 = clean_status.Clean_Tank_1
- C2 = clean_status.Clean_Tank_2
- # 中水桶
- S1 = clean_status.ColorSelect_Tank_1
- S2 = clean_status.ColorSelect_Tank_2
- SOg1 = clean_status.ColorSelect_Output_g1
- SOb1 = clean_status.ColorSelect_Output_b1
- SOg2 = clean_status.ColorSelect_Output_g2
- SOb2 = clean_status.ColorSelect_Output_b2
- P1 = clean_status.Peel_Tank_1
- P2 = clean_status.Peel_Tank_2
- PO1 = clean_status.Peel_Output_1
- PO2 = clean_status.Peel_Output_2
- ferment_status = ferment_container_status.query.order_by(text('datetime desc')).first()
- F1 = ferment_status.Ferment_Tank_1
- F2 = ferment_status.Ferment_Tank_2
- dry_status = dry_container_status.query.order_by(text('datetime desc')).first()
- D1 = dry_status.Dry_Tank_1
- D2 = dry_status.Dry_Tank_2
- DO1 = dry_status.Dry_Output_1
- DO2 = dry_status.Dry_Output_2
- POb1 = clean_status.Peel_Output_b1
- return render_template('demo.html', title="[測試] DEMO 貨櫃自動化", **locals())
- else:
- return render_template('sign_in.html')
- # 乾燥槽自動化測試頁
- @main.route('/dry_auto', methods=['GET', 'POST'])
- def dry_auto():
- # 獲取登入信息
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- dry_status = dry_container_status.query.order_by(text('datetime desc')).first()
- DI1 = dry_status.Dry_Input_1
- DI2 = dry_status.Dry_Input_2
- D1 = dry_status.Dry_Tank_1
- D2 = dry_status.Dry_Tank_2
- D3 = dry_status.Dry_Tank_3
- D4 = dry_status.Dry_Tank_4
- D5 = dry_status.Dry_Tank_5
- D6 = dry_status.Dry_Tank_6
- D7 = dry_status.Dry_Tank_7
- D8 = dry_status.Dry_Tank_8
- D9 = dry_status.Dry_Tank_9
- D10 = dry_status.Dry_Tank_10
- D11 = dry_status.Dry_Tank_11
- D12 = dry_status.Dry_Tank_12
- DO1 = dry_status.Dry_Output_1
- DO2 = dry_status.Dry_Output_2
- return render_template('dry_auto.html', title="[測試] 乾燥自動化", **locals())
- else:
- return render_template('sign_in.html')
- @main.route('/dry_auto_status', methods=['GET', 'POST'])
- def dry_auto_test():
- # [介面] 讓使用者可以選擇排程內有乾燥/清洗/校正, 此處預設為 True
- Dry_btn = True
- # 從資料庫資料表中取得最新狀態
- dry_status = dry_container_status.query.order_by(text('datetime desc')).first()
- DI1 = dry_status.Dry_Input_1
- DI2 = dry_status.Dry_Input_2
- D1 = dry_status.Dry_Tank_1
- D2 = dry_status.Dry_Tank_2
- D3 = dry_status.Dry_Tank_3
- D4 = dry_status.Dry_Tank_4
- D5 = dry_status.Dry_Tank_5
- D6 = dry_status.Dry_Tank_6
- D7 = dry_status.Dry_Tank_7
- D8 = dry_status.Dry_Tank_8
- D9 = dry_status.Dry_Tank_9
- D10 = dry_status.Dry_Tank_10
- D11 = dry_status.Dry_Tank_11
- D12 = dry_status.Dry_Tank_12
- DO1 = dry_status.Dry_Output_1
- DO2 = dry_status.Dry_Output_2
- FO1 = 'FO_Waiting' # 'FO_OutputtingBean'
- FO2 = 'FO_Waiting'
- D_UP_tanklist = [D1, D2, D3, D4, D5, D6]
- D_DOWN_tanklist = [D7, D8, D9, D10, D11, D12]
- # ----- 乾燥桶槽 D1~D6 入料暫停→入料判斷 ------------------------------
- Dry_InputtingBeanPause_number = int(D_UP_tanklist.count('D_InputtingBean_Pause'))
- # 若入料儲豆槽可出豆, 且 D1~D6 其中有桶槽入料暫停 (就是入料時桶槽豆子未滿 or 儲豆槽=='DI_Waiting' 已空) 時, 優先入豆
- if DI1 == 'DI_OutputtingBean' and Dry_InputtingBeanPause_number >= 1:
- if D1 == 'D_InputtingBean_Pause':
- D1 = 'D_InputtingBean'
- print('------- D1 狀態更新:入料中 -------')
- elif D2 == 'D_InputtingBean_Pause':
- D2 = 'D_InputtingBean'
- print('------- D2 狀態更新:入料中 -------')
- elif D3 == 'D_InputtingBean_Pause':
- D3 = 'D_InputtingBean'
- print('------- D3 狀態更新:入料中 -------')
- elif D4 == 'D_InputtingBean_Pause':
- D4 = 'D_InputtingBean'
- print('------- D4 狀態更新:入料中 -------')
- elif D5 == 'D_InputtingBean_Pause':
- D5 = 'D_InputtingBean'
- print('------- D5 狀態更新:入料中 -------')
- elif D6 == 'D_InputtingBean_Pause':
- D6 = 'D_InputtingBean'
- print('------- D6 狀態更新:入料中 -------')
- # ----- 乾燥桶槽 D1~D6 等待→入料判斷 ------------------------------
- # 目前乾燥槽 D1~D6 正在入豆的桶槽數量 (應小於一桶)
- Dry_InputtingBean_number = int(D_UP_tanklist.count('D_InputtingBean'))
- # [介面] 若未啟用 發酵 狀態
- if not Dry_btn:
- print('未指定乾燥流程')
- # 入料儲豆槽 非可出料狀態
- elif Dry_btn and DI1 != 'DI_OutputtingBean':
- print('入料儲豆槽非可出豆, 無法入料')
- # 若 D1~D6 乾燥桶槽為 入豆暫停, 則狀態改為入豆優先入豆
- elif Dry_btn and DI1 == 'DI_OutputtingBean' and Dry_InputtingBeanPause_number >= 1:
- print('乾燥槽 D', D_UP_tanklist.index('D_InputtingBean_Pause')+1, '優先入料中')
- print('------- D', D_UP_tanklist.index('D_InputtingBean_Pause')+1, ' 入料中 -------')
- # 若 D1~D6 發酵桶槽為 入豆, 則桶槽數字小者 優先入豆
- elif Dry_btn and DI1 == 'DI_OutputtingBean' and Dry_InputtingBean_number >= 1:
- print('乾燥槽 D', D_UP_tanklist.index('D_InputtingBean')+1, '優先入料中')
- print('------- D', D_UP_tanklist.index('D_InputtingBean')+1, ' 入料中 -------')
- elif Dry_btn and DI1 == 'DI_OutputtingBean' \
- and Dry_InputtingBean_number == 0 and Dry_InputtingBeanPause_number == 0:
- # 當達標準入料條件
- if D1 == 'D_Waiting':
- D1 = 'D_InputtingBean'
- print('------- D1 狀態更新:入料中 -------')
- elif D2 == 'D_Waiting':
- D2 = 'D_InputtingBean'
- print('------- D2 狀態更新:入料中 -------')
- elif D3 == 'D_Waiting':
- D3 = 'D_InputtingBean'
- print('------- D3 狀態更新:入料中 -------')
- elif D4 == 'D_Waiting':
- D4 = 'D_InputtingBean'
- print('------- D4 狀態更新:入料中 -------')
- elif D5 == 'D_Waiting':
- D5 = 'D_InputtingBean'
- print('------- D5 狀態更新:入料中 -------')
- elif D6 == 'D_Waiting':
- D6 = 'D_InputtingBean'
- print('------- D6 狀態更新:入料中 -------')
- # ----- 乾燥桶槽 D1~D6 入料→入料暫停判斷 ------------------------------
- Dry_InputtingBean_number = int(D_UP_tanklist.count('D_InputtingBean'))
- # -- 取得乾燥桶槽 D1~D6 超音波生豆高度 UltraSonic -------------
- D_UP_tank_UltraSonic = []
- for i in range(1, 7, 1):
- tank_UltraSonic = dry_tank_UltraSonic.query.filter_by(tank_num='D' + str(i)).order_by(text('datetime desc')).first()
- UltraSonic = int(tank_UltraSonic.UltraSonic)
- D_UP_tank_UltraSonic.append(UltraSonic)
- print('D_UP_tank_UltraSonic: ', D_UP_tank_UltraSonic)
- # -- 取得乾燥桶槽 D1~D6 超音波生豆高度 UltraSonic -------------
- if DI1 != 'DI_OutputtingBean' and Dry_InputtingBean_number >= 1:
- if D1 == 'D_InputtingBean' and D_UP_tank_UltraSonic[0] < 110:
- D1 = 'D_InputtingBean_Pause'
- print('------- D1 狀態更新:入料暫停 -------')
- else:
- D1 = 'D_InputtingBean_Finish'
- print('------- D1 狀態更新:入料完成 -------')
- if D2 == 'D_InputtingBean' and D_UP_tank_UltraSonic[1] < 110:
- D2 = 'D_InputtingBean_Pause'
- print('------- D2 狀態更新:入料暫停 -------')
- else:
- D2 = 'D_InputtingBean_Finish'
- print('------- D2 狀態更新:入料完成 -------')
- if D3 == 'D_InputtingBean' and D_UP_tank_UltraSonic[2] < 110:
- D3 = 'D_InputtingBean_Pause'
- print('------- D3 狀態更新:入料暫停 -------')
- else:
- D3 = 'D_InputtingBean_Finish'
- print('------- D3 狀態更新:入料完成 -------')
- if D4 == 'D_InputtingBean' and D_UP_tank_UltraSonic[3] < 110:
- D4 = 'D_InputtingBean_Pause'
- print('------- D4 狀態更新:入料暫停 -------')
- else:
- D4 = 'D_InputtingBean_Finish'
- print('------- D4 狀態更新:入料完成 -------')
- if D5 == 'D_InputtingBean' and D_UP_tank_UltraSonic[4] < 110:
- D5 = 'D_InputtingBean_Pause'
- print('------- D5 狀態更新:入料暫停 -------')
- else:
- D5 = 'D_InputtingBean_Finish'
- print('------- D5 狀態更新:入料完成 -------')
- if D6 == 'D_InputtingBean' and D_UP_tank_UltraSonic[5] < 110:
- D6 = 'D_InputtingBean_Pause'
- print('------- D6 狀態更新:入料暫停 -------')
- else:
- D6 = 'D_InputtingBean_Finish'
- print('------- D6 狀態更新:入料完成 -------')
- # # ----- 乾燥桶槽 D1~D6 入料完成→乾燥判斷 ------------------------------
- # Dry_InputtingBeanFinish_number = int(D_UP_tanklist.count('D_InputtingBean_Finish'))
- # # 乾燥條件:當前桶槽入豆達指定高度, 則開始乾燥 (可以多桶乾燥)
- # # !!! 乾燥槽 D_Drying 狀態應該請硬體判斷
- # # !!! 若狀態為 D_InputtingBean 且 超音波值>指定生豆高度, 狀態改為 D_Drying 乾燥
- # if D1 == 'D_InputtingBean_Finish' or D1 == 'D_InputtingBean_Pause' and D_UP_tank_UltraSonic[0] >= 110:
- # D1 = 'D_Drying'
- # print('------- D1 狀態更新:乾燥中 -------')
- # if D2 == 'D_InputtingBean_Finish' and D_UP_tank_UltraSonic[1] >= 110:
- # D2 = 'D_Drying'
- # print('------- D2 狀態更新:乾燥中 -------')
- # if D3 == 'D_InputtingBean_Finish' and D_UP_tank_UltraSonic[2] >= 110:
- # D3 = 'D_Drying'
- # print('------- D3 狀態更新:乾燥中 -------')
- # if D4 == 'D_InputtingBean_Finish' and D_UP_tank_UltraSonic[3] >= 110:
- # D4 = 'D_Drying'
- # print('------- D4 狀態更新:乾燥中 -------')
- # if D5 == 'D_InputtingBean_Finish' and D_UP_tank_UltraSonic[4] >= 110:
- # D5 = 'D_Drying'
- # print('------- D5 狀態更新:乾燥中 -------')
- # if D6 == 'D_InputtingBean_Finish' and D_UP_tank_UltraSonic[5] >= 110:
- # D6 = 'D_Drying'
- # print('------- D6 狀態更新:乾燥中 -------')
-
- # ----- 乾燥桶槽 D1~D6 發酵→可出豆 判斷 ------------------------------
- # !!! 發酵槽 D_OutputtingBean 狀態應該請硬體判斷
- # !!! 若狀態為 D_Drying 且 達指定乾燥條件, 狀態改為 D_OutputtingBean 可出豆
- # 可以多桶各自執行發酵排程
- # ----- [測試用] !!!!! D1~D6 入料完成→可出豆 判斷 ------------------------------
- if D1 == 'D_InputtingBean_Finish': D1 = 'D_OutputtingBean'
- if D2 == 'D_InputtingBean_Finish': D2 = 'D_OutputtingBean'
- if D3 == 'D_InputtingBean_Finish': D3 = 'D_OutputtingBean'
- if D4 == 'D_InputtingBean_Finish': D4 = 'D_OutputtingBean'
- if D5 == 'D_InputtingBean_Finish': D5 = 'D_OutputtingBean'
- if D6 == 'D_InputtingBean_Finish': D6 = 'D_OutputtingBean'
- # ----- [測試用] !!!!! D1~D6 入料完成→可出豆 判斷 ------------------------------
- # # ----- 乾燥桶槽 D1~D6 可出豆→出料儲豆槽 DO1 判斷 ------------------------------
- Dry_OutputtingBean_number = int(D_UP_tanklist.count('D_OutputtingBean'))
- # # !!! 若出料儲豆槽狀態為 DO_Waiting(空桶等待) 且 桶槽狀態為 D_OutputtingBean 可出豆, 與 DO1 配合開始出豆
- # if DO1 == 'DO_Waiting' and Dry_OutputtingBean_number >= 1:
- # if D1 == 'D_OutputtingBean':
- # DO1 = 'DO_InputtingBean'
- # print('------- D1 狀態更新:出豆中 -------')
- # print('------- DO1 狀態更新:入豆中 -------')
- # elif D2 == 'D_OutputtingBean':
- # DO1 = 'DO_InputtingBean'
- # print('------- D2 狀態更新:出豆中 -------')
- # print('------- DO1 狀態更新:入豆中 -------')
- # elif D3 == 'D_OutputtingBean':
- # DO1 = 'DO_InputtingBean'
- # print('------- D3 狀態更新:出豆中 -------')
- # print('------- DO1 狀態更新:入豆中 -------')
- # elif D4 == 'D_OutputtingBean':
- # DO1 = 'DO_InputtingBean'
- # print('------- D4 狀態更新:出豆中 -------')
- # print('------- DO1 狀態更新:入豆中 -------')
- # elif D5 == 'D_OutputtingBean':
- # DO1 = 'DO_InputtingBean'
- # print('------- D5 狀態更新:出豆中 -------')
- # print('------- DO1 狀態更新:入豆中 -------')
- # elif D6 == 'D_OutputtingBean':
- # DO1 = 'DO_InputtingBean'
- # print('------- D6 狀態更新:出豆中 -------')
- # print('------- DO1 狀態更新:入豆中 -------')
- # ----- 乾燥入料儲豆槽 DI1~DI2 入豆→可出豆判斷 ------------------------------
- # -- 取得乾燥入料儲豆槽 FI1~FI2 桶內高度 UltraSonic -------------
- DI_UP_UltraSoniclist = []
- for i in range(1, 3, 1):
- input_UltraSonic = dry_input_sensor.query.filter_by(tank_num='DI' + str(i)).order_by(text('datetime desc')).first()
- UltraSonic = int(input_UltraSonic.UltraSonic)
- DI_UP_UltraSoniclist.append(UltraSonic)
- print('DI_UP_UltraSoniclist: ', DI_UP_UltraSoniclist)
- # !!! 乾燥入料儲豆槽 D_OutputtingBean 狀態應該請硬體判斷
- # 入料儲豆槽等待中、且發酵槽出料儲豆槽可出豆時, 入料儲豆槽入豆
- if DI1 == 'DI_Waiting' and FO1 == 'FO_OutputtingBean':
- DI1 = 'DI_InputtingBean'
- print('------- DI1 狀態更新:入豆中 -------')
- # 入料儲豆槽入豆時 且 (發酵儲豆槽有入料 或者 前方儲豆槽非可出豆), 則停止入豆
- elif DI1 == 'DI_InputtingBean' and (DI_UP_UltraSoniclist[0] > 35) and (FO1 != 'FO_OutputtingBean') :
- DI1 = 'DI_OutputtingBean'
- print('------- DI1 狀態更新:可出豆 -------')
- # 若入料儲豆槽可出豆 且 儲豆槽內高度低於 40 且 前方脫皮機儲豆槽可出豆 且 目前無桶槽需入料時
- elif DI1 == 'DI_OutputtingBean' and (DI_UP_UltraSoniclist[0] < 40) and FO1 == 'FO_OutputtingBean' and Dry_InputtingBean_number == 0 and Dry_InputtingBeanPause_number == 0:
- DI1 = 'DI_InputtingBean'
- print('------- DI1 狀態更新:入豆中 -------')
- # if DI2 == 'DI_Waiting' and FO2 == 'FO_OutputtingBean':
- # DI2 = 'DI_InputtingBean'
- # print('------- DI2 狀態更新:入豆中 -------')
- # elif DI2 == 'DI_InputtingBean' and ((DI_DOWN_UltraSoniclist[1] > 35) or (FO2 == 'FO_OutputtingBean')) :
- # DI2 = 'DI_OutputtingBean'
- # print('------- DI2 狀態更新:可出豆 -------')
- # elif DI2 == 'DI_OutputtingBean' and (DI_DOWN_UltraSoniclist[1] < 40) and FO2 == 'FO_OutputtingBean' and Dry_InputtingBean_number == 0 and Dry_InputtingBeanPause_number == 0:
- # DI2 = 'DI_InputtingBean'
- # print('------- DI2 狀態更新:入豆中 -------')
- # ----- 乾燥出料儲豆槽 DO1~DO2 入豆→可出豆判斷 ------------------------------
- # -- 取得乾燥出料儲豆槽 DO1~DO2 桶內高度 UltraSonic -------------
- DO_UP_UltraSoniclist = []
- for i in range(1, 3, 1):
- output_UltraSonic = dry_output_sensor.query.filter_by(tank_num='DO' + str(i)).order_by(text('datetime desc')).first()
- UltraSonic = int(output_UltraSonic.UltraSonic)
- DO_UP_UltraSoniclist.append(UltraSonic)
- print('DO_UP_UltraSoniclist: ', DO_UP_UltraSoniclist)
- # 桶槽可出豆, 且出料儲豆槽等待時, 出料儲豆槽入豆
- # 參考 -- 乾燥桶槽 F1~F6 可出豆→出料儲豆槽 FO1 判斷 --
- # 出料儲豆槽入料 且滿時, 出料儲豆槽可出豆
- if DO1 == ('DO_InputtingBean' and DO_UP_UltraSoniclist[0] > 35):
- DO1 = 'DO_OutputtingBean'
- # 出料儲豆槽入料 且未滿, 桶槽可出豆已空
- # -- 取得乾燥桶槽 D1~D6 桶內高度 UltraSonic -------------
- D_UP_UltraSoniclist = []
- for i in range(1, 7, 1):
- tank_UltraSonic = dry_tank_UltraSonic.query.filter_by(tank_num='D' + str(i)).order_by(text('datetime desc')).first()
- UltraSonic = int(tank_UltraSonic.UltraSonic)
- D_UP_UltraSoniclist.append(UltraSonic)
- print('D_UP_UltraSoniclist: ', D_UP_UltraSoniclist)
- # -- 取得乾燥桶槽 D1~D6 桶內高度 UltraSonic -------------
- if DO1 == 'DO_InputtingBean' and Dry_OutputtingBean_number >= 1:
- if D1 == 'D_OutputtingBean' and D_UP_UltraSoniclist[0] < 5:
- D1 = 'D_Waiting'
- DO1 = 'DO_OutputtingBean'
- print('------- D1 狀態更新:空桶等待 -------')
- print('------- DO1 狀態更新:可出豆 -------')
- elif D2 == 'D_OutputtingBean' and D_UP_UltraSoniclist[1] < 5:
- D2 = 'D_Waiting'
- DO1 = 'DO_OutputtingBean'
- print('------- D2 狀態更新:空桶等待 -------')
- print('------- DO1 狀態更新:可出豆 -------')
- elif D3 == 'D_OutputtingBean' and D_UP_UltraSoniclist[2] < 5:
- D3 = 'D_Waiting'
- DO1 = 'DO_OutputtingBean'
- print('------- D3 狀態更新:空桶等待 -------')
- print('------- DO1 狀態更新:可出豆 -------')
- elif D4 == 'D_OutputtingBean' and D_UP_UltraSoniclist[3] < 5:
- D4 = 'D_Waiting'
- DO1 = 'DO_OutputtingBean'
- print('------- D4 狀態更新:空桶等待 -------')
- print('------- DO1 狀態更新:可出豆 -------')
- elif D5 == 'D_OutputtingBean' and D_UP_UltraSoniclist[4] < 5:
- D5 = 'D_Waiting'
- DO1 = 'DO_OutputtingBean'
- print('------- D5 狀態更新:空桶等待 -------')
- print('------- DO1 狀態更新:可出豆 -------')
- elif D6 == 'D_OutputtingBean' and D_UP_UltraSoniclist[5] < 5:
- D6 = 'D_Waiting'
- DO1 = 'DO_OutputtingBean'
- print('------- D6 狀態更新:空桶等待 -------')
- print('------- DO1 狀態更新:可出豆 -------')
- elif DO1 == 'DO_OutputtingBean' and DO_UP_UltraSoniclist[0] < 5:
- DO1 = 'DO_Waiting'
- # # ----- 將狀態寫入資料庫 ------------------------------
- # # 獲取文本框的值並賦值給user實體對象
- # D_status = dry_container_status()
- # D_status.Dry_Input_1 = DI1
- # D_status.Dry_Input_2 = DI2
- # D_status.Dry_Tank_1 = D1
- # D_status.Dry_Tank_2 = D2
- # D_status.Dry_Tank_3 = D3
- # D_status.Dry_Tank_4 = D4
- # D_status.Dry_Tank_5 = D5
- # D_status.Dry_Tank_6 = D6
- # D_status.Dry_Tank_7 = D7
- # D_status.Dry_Tank_8 = D8
- # D_status.Dry_Tank_9 = D9
- # D_status.Dry_Tank_10 = D10
- # D_status.Dry_Tank_11 = D11
- # D_status.Dry_Tank_12 = D12
- # D_status.Dry_Output_1 = DO1
- # D_status.Dry_Output_2 = DO2
- # #將數據保存進資料庫
- # db.session.add(D_status)
- # # 手動提交
- # db.session.commit()
- # # ----- 將狀態寫入資料庫 ------------------------------
-
- return jsonify({"Dry_Input_1":DI1,
- "Dry_Tank_1":D1,
- "Dry_Tank_2":D2,
- "Dry_Tank_3":D3,
- "Dry_Tank_4":D4,
- "Dry_Tank_5":D5,
- "Dry_Tank_6":D6,
- "Dry_Output_1":DO1
- })
- # 發酵槽自動化測試頁
- @main.route('/ferment_auto', methods=['GET', 'POST'])
- def ferment_auto():
- # 獲取登入信息
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- ferment_status = ferment_container_status.query.order_by(text('datetime desc')).first()
- FI1 = ferment_status.Ferment_Input_1
- FI2 = ferment_status.Ferment_Input_2
- F1 = ferment_status.Ferment_Tank_1
- F2 = ferment_status.Ferment_Tank_2
- F3 = ferment_status.Ferment_Tank_3
- F4 = ferment_status.Ferment_Tank_4
- F5 = ferment_status.Ferment_Tank_5
- F6 = ferment_status.Ferment_Tank_6
- F7 = ferment_status.Ferment_Tank_7
- F8 = ferment_status.Ferment_Tank_8
- F9 = ferment_status.Ferment_Tank_9
- F10 = ferment_status.Ferment_Tank_10
- F11 = ferment_status.Ferment_Tank_11
- F12 = ferment_status.Ferment_Tank_12
- FO1 = ferment_status.Ferment_Output_1
- FO2 = ferment_status.Ferment_Output_2
- clean_status = clean_container_status.query.order_by(text('datetime desc')).first()
- PO1 = clean_status.Peel_Output_1 # PO_Waiting # PO_OutputtingBean
- return render_template('ferment_auto.html', title="[測試] 發酵自動化", **locals())
- else:
- return render_template('sign_in.html')
- @main.route('/ferment_auto_status', methods=['GET', 'POST'])
- def ferment_auto_test():
- info = request.args.to_dict()
- # 寫定入料、桶槽、出料的空桶標準, 若 <= 2 則為空桶
- Ferment_Input_bean_empty = 2
- Ferment_Tank_bean_empty = 2
- Ferment_Output_bean_empty = 2
- # 從介面取得 指定生豆高度/發酵桶槽排程:發酵、清洗、校正 EC、校正攪拌棒
- FermentAuto_fermenting = int(info['FermentAuto_fermenting'])
- FermentAuto_cleaning = int(info['FermentAuto_cleaning'])
- FermentAuto_calibratingEC = int(info['FermentAuto_calibratingEC'])
- FermentAuto_calibratingSTIR = int(info['FermentAuto_calibratingSTIR'])
- Ferment_Input_bean_height = float(info['Ferment_Input_bean_height'])
- Ferment_Input_vacuumON_time = float(info['Ferment_Input_vacuumON_time'])
- Ferment_Input_vacuumOFF_time = float(info['Ferment_Input_vacuumOFF_time'])
- Ferment_Tank_bean_height = float(info['Ferment_Tank_bean_height'])
- Ferment_Tank_vacuumON_time = float(info['Ferment_Tank_vacuumON_time'])
- Ferment_Tank_vacuumOFF_time = float(info['Ferment_Tank_vacuumOFF_time'])
- Ferment_Tank_water_height = float(info['Ferment_Tank_water_height'])
- Ferment_Tank_fermenting_temp = float(info['Ferment_Tank_fermenting_temp'])
- Ferment_Tank_fermenting_time = float(info['Ferment_Tank_fermenting_time'])
- Ferment_Tank_motor_rpm = float(info['Ferment_Tank_motor_rpm'])
- Ferment_Tank_motor_time = float(info['Ferment_Tank_motor_time'])
- Ferment_Tank_fermenting_pH = float(info['Ferment_Tank_fermenting_pH'])
- Ferment_Output_bean_height = float(info['Ferment_Output_bean_height'])
- Ferment_Output_vacuumON_time = float(info['Ferment_Output_vacuumON_time'])
- Ferment_Output_vacuumOFF_time = float(info['Ferment_Output_vacuumOFF_time'])
- Ferment_Tank_WaterOut_time = float(info['Ferment_Tank_WaterOut_time'])
- Ferment_Tank_Disinfect_time = float(info['Ferment_Tank_Disinfect_time'])
- Ferment_cb_vacuum = info['Ferment_cb_vacuum'] # 'true' 'false'
- Ferment_cb_vacuum_time = float(info['Ferment_cb_vacuum_time'])
-
- # [介面] 讓使用者可以選擇排程內有發酵/清洗/校正, 此處預設為 True
- Ferment_btn = FermentAuto_fermenting # Ferment_btn = True
- # 從資料庫資料表中取得最新狀態
- ferment_status = ferment_container_status.query.order_by(text('datetime desc')).first()
- FI1 = ferment_status.Ferment_Input_1
- FI2 = ferment_status.Ferment_Input_2
- F1 = ferment_status.Ferment_Tank_1
- F2 = ferment_status.Ferment_Tank_2
- F3 = ferment_status.Ferment_Tank_3
- F4 = ferment_status.Ferment_Tank_4
- F5 = ferment_status.Ferment_Tank_5
- F6 = ferment_status.Ferment_Tank_6
- F7 = ferment_status.Ferment_Tank_7
- F8 = ferment_status.Ferment_Tank_8
- F9 = ferment_status.Ferment_Tank_9
- F10 = ferment_status.Ferment_Tank_10
- F11 = ferment_status.Ferment_Tank_11
- F12 = ferment_status.Ferment_Tank_12
- FO1 = ferment_status.Ferment_Output_1
- FO2 = ferment_status.Ferment_Output_2
- clean_status = clean_container_status.query.order_by(text('datetime desc')).first()
- PO1 = clean_status.Peel_Output_1 # PO_Waiting # PO_OutputtingBean
- PO2 = clean_status.Peel_Output_2
- F_UP_tanklist = [F1, F2, F3, F4, F5, F6]
- F_DOWN_tanklist = [F7, F8, F9, F10, F11, F12]
- FOutputtingBean_Tank = '' # 這是給出料儲豆槽判斷目前出豆的桶槽
- # ----- 發酵入料儲豆槽 FI1~FI2 入豆→可出豆判斷 ------------------------------
- # 目前發酵槽 F1~F6 正在入豆、入水的桶槽數量 (應小於一桶)
- FermentUp_Waiting_number = int(F_UP_tanklist.count('F_Waiting'))
- FermentUp_InputtingBean_number = int(F_UP_tanklist.count('F_InputtingBean'))
- FermentUp_InputtingBeanPause_number = int(F_UP_tanklist.count('F_InputtingBean_Pause'))
- FermentUp_InputtingBeanFinish_number = int(F_UP_tanklist.count('F_InputtingBean_Finish'))
- FermentUp_InputtingWater_number = int(F_UP_tanklist.count('F_InputtingWater'))
- # -- 取得發酵 入料儲豆槽 FI1~FI2 / 桶槽 F1~F6 / 出料 FO1~FO2 桶內高度 UltraSonic start -------------
- FI_UP_UltraSoniclist = []
- for i in range(1, 3, 1):
- input_UltraSonic = ferment_input_UltraSonic.query.filter_by(tank_num='F' + str(i)).order_by(text('datetime desc')).first()
- # UltraSonic = float("{:.2f}".format(34.6 - float(input_UltraSonic.UltraSonic)))
- UltraSonic = float(input_UltraSonic.UltraSonic)
- FI_UP_UltraSoniclist.append(UltraSonic)
- print('FI_UP_UltraSoniclist: ', FI_UP_UltraSoniclist)
- F_UP_UltraSoniclist = []
- for i in range(1, 7, 1):
- tank_UltraSonic = ferment_tank_UltraSonic.query.filter_by(tank_num='F' + str(i)).order_by(text('datetime desc')).first()
- UltraSonic = (float(tank_UltraSonic.UltraSonic))
- F_UP_UltraSoniclist.append(UltraSonic)
- print('F_UP_UltraSoniclist: ', F_UP_UltraSoniclist)
- FO_UP_UltraSoniclist = []
- for i in range(1, 3, 1):
- output_UltraSonic = ferment_output_UltraSonic.query.filter_by(tank_num='FO' + str(i)).order_by(text('datetime desc')).first()
- UltraSonic = float(output_UltraSonic.UltraSonic)
- FO_UP_UltraSoniclist.append(UltraSonic)
- print('FO_UP_UltraSoniclist: ', FO_UP_UltraSoniclist)
- # -- 取得發酵 入料儲豆槽 FI1~FI2 / 桶槽 F1~F6 / 出料 FO1~FO2 桶內高度 UltraSonic end -------------
- # -- 取得發酵桶槽 F1~F6 夾層水位高度 WaterLevel start -------------
- F_UP_tank_WaterLevel = []
- for i in range(1, 7, 1):
- tank_WaterLevel = ferment_tank_WaterLevel.query.filter_by(tank_num='F' + str(i)).order_by(text('datetime desc')).first()
- WaterLevel = float(tank_WaterLevel.WaterLevel)
- F_UP_tank_WaterLevel.append(WaterLevel)
- print('F_UP_tank_WaterLevel: ', F_UP_tank_WaterLevel)
- # -- 取得發酵桶槽 F1~F6 夾層水位高度 WaterLevel end -------------
- # -- 取得發酵桶槽 F1~F6 pH -------------
- F_UP_tank_PH = []
- for i in range(1, 7, 1):
- tank_PH = ferment_tank_PH.query.filter_by(tank_num='F' + str(i)).order_by(text('datetime desc')).first()
- PH = float(tank_PH.PH)
- F_UP_tank_PH.append(PH)
- print('F_UP_tank_PH: ', F_UP_tank_PH)
- # -- 取得發酵桶槽 F1~F6 pH -------------
- # -- 取得發酵桶槽 F1~F6 SHT11_TEMP -------------
- F_UP_tank_SHT11_Temp = []
- for i in range(1, 7, 1):
- tank_SHT11 = ferment_tank_SHT11.query.filter_by(tank_num='F' + str(i)).order_by(text('datetime desc')).first()
- SHT11_Temp = float(tank_SHT11.SHT11_Temp)
- F_UP_tank_SHT11_Temp.append(SHT11_Temp)
- print('F_UP_tank_SHT11_Temp: ', F_UP_tank_SHT11_Temp)
- # -- 取得發酵桶槽 F1~F6 SHT11_TEMP -------------
- # 入料儲豆槽等待中、且脫皮機儲豆槽可出豆時, 入料儲豆槽入豆
- if FI1 == 'FI_Waiting' and PO1 == 'PO_OutputtingBean':
- FI1 = 'FI_InputtingBean'
- print('------- FI1 狀態更新:入豆中 -------')
- # 入料儲豆槽入豆時
- elif FI1 == 'FI_InputtingBean':
- # 桶槽內達指定生豆高度時, 入料儲豆槽狀態轉為 可出豆
- if (FI_UP_UltraSoniclist[0] >= Ferment_Input_bean_height):
- # [致動器] 入料真空吸料機 OFF
- data = { "tank_num": "F1", "command": "input_vacuum_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- FI1 = 'FI_OutputtingBean'
- print('------- FI1 狀態更新:可出豆 -------')
- # 桶槽內未達指定生豆高度, 且 前方 PO1 可出豆, 就執行入料動作
- elif (FI_UP_UltraSoniclist[0] < Ferment_Input_bean_height) and PO1 == 'PO_OutputtingBean':
- # [致動器] 入料真空吸料機 ON
- data = { "tank_num": "F1", "command": "input_vacuum_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- timer = time.time()
- while True:
- if (time.time() - timer) > Ferment_Input_vacuumON_time:
- # [致動器] 入料真空吸料機 OFF
- data = { "tank_num": "F1", "command": "input_vacuum_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- timer = time.time()
- break
- while True:
- if (time.time() - timer) > Ferment_Input_vacuumOFF_time:
- break
- # 桶槽內大於空桶高度, 且 前方 PO1 非可出豆, 將狀態轉為可出豆
- elif (FI_UP_UltraSoniclist[0] > Ferment_Input_bean_empty) and PO1 != 'PO_OutputtingBean':
- FI1 = 'FI_OutputtingBean'
- print('------- FI1 狀態更新:可出豆 -------')
- # 桶槽內小於空桶高度, 且 前方 PO1 非可出豆, 將狀態轉為空桶等待
- elif (FI_UP_UltraSoniclist[0] <= Ferment_Input_bean_empty) and PO1 != 'PO_OutputtingBean':
- FI1 = 'FI_Waiting'
- print('------- FI1 狀態更新:空桶等待 -------')
- # 入料儲豆槽出豆時, 桶槽高度為 空桶高度時, 狀態轉為 空桶等待
- elif FI1 == 'FI_OutputtingBean' and (FI_UP_UltraSoniclist[0] <= Ferment_Input_bean_empty):
- FI1 = 'FI_Waiting'
- print('------- FI1 狀態更新:空桶等待 -------')
- # ----- 發酵排程動作 start ------------------------------------------------------------------
- def FInputtingBean_TO_FInputtingBeanFinish(tid):
- # [致動器] 真空吸料機 OFF
- data = { "tank_num": tid, "command": "tank_vacuum_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 馬達 0
- data = { "tank_num": tid, "command": "tank_motor_status", "value": "0" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 入料三通閥 ON排氣
- data = { "tank_num": tid, "command": "tank_threewayvalve_input_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- print('------- ', tid,' 狀態更新:入料完成 -------')
- def FInputtingBean_butnot_filled(tid):
- # [致動器] 入料三通閥 OFF入豆
- data = { "tank_num": tid, "command": "tank_threewayvalve_input_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 真空吸料機 ON
- data = { "tank_num": tid, "command": "tank_vacuum_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- timer = time.time()
- while True:
- if (time.time() - timer) > Ferment_Tank_vacuumON_time:
- # [致動器] 入料真空吸料機 OFF
- data = { "tank_num": tid, "command": "tank_vacuum_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- timer = time.time()
- break
- while True:
- if (time.time() - timer) > Ferment_Tank_vacuumOFF_time:
- break
- def FInputtingBean_butnot_FIOutputtingBean(tid):
- # [致動器] 真空吸料機 OFF
- data = { "tank_num": tid, "command": "tank_vacuum_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 入料三通閥 OFF入豆
- data = { "tank_num": tid, "command": "tank_threewayvalve_input_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 馬達 0
- data = { "tank_num": tid, "command": "tank_motor_status", "value": "0" }
- print('data: ', data)
- # mqtt_f(data)
- print('------- ', tid,' 狀態更新:入豆暫停 -------')
- # ----- 發酵排程動作 end ------------------------------------------------------------------
- # [介面] 若啟用 發酵 狀態
- if Ferment_btn:
- # ----- 發酵桶槽 F1~F6 入料桶槽優先入料判斷 ------------------------------
- # 若 F1~F6 桶槽中有一個桶槽入豆中
- if FermentUp_InputtingBean_number == 1:
- # 若 F1 桶槽為入豆中
- if F1 == 'F_InputtingBean':
- if (F_UP_UltraSoniclist[0] >= Ferment_Tank_bean_height):
- FInputtingBean_TO_FInputtingBeanFinish("F1")
- F1 = 'F_InputtingBean_Finish'
- elif FI1 == 'FI_OutputtingBean' and (F_UP_UltraSoniclist[0] < Ferment_Tank_bean_height):
- FInputtingBean_butnot_filled("F1")
- elif FI1 != 'FI_OutputtingBean':
- FInputtingBean_butnot_FIOutputtingBean("F1")
- F1 = 'F_InputtingBean_Pause'
- elif F2 == 'F_InputtingBean':
- pass
- elif F3 == 'F_InputtingBean':
- pass
- elif F4 == 'F_InputtingBean':
- pass
- elif F5 == 'F_InputtingBean':
- pass
- elif F6 == 'F_InputtingBean':
- pass
- # 若 F1~F6 桶槽中有一個桶槽入豆暫停中, 且 FI1 可出豆
- elif FermentUp_InputtingBeanPause_number == 1 and FI1 == 'FI_OutputtingBean':
- # 若 F1 桶槽為入豆暫停 且 FI1 可出料
- if F1 == 'F_InputtingBean_Pause':
- # [致動器] 入料三通閥 OFF入豆
- data = { "tank_num": "F1", "command": "tank_threewayvalve_input_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 馬達 5
- data = { "tank_num": "F1", "command": "tank_motor_status", "value": "5" }
- print('data: ', data)
- # mqtt_f(data)
- F1 = 'F_InputtingBean'
- print('------- F1 狀態更新:入料中 -------')
- elif F2 == 'F_InputtingBean_Pause':
- pass
- elif F3 == 'F_InputtingBean_Pause':
- pass
- elif F4 == 'F_InputtingBean_Pause':
- pass
- elif F5 == 'F_InputtingBean_Pause':
- pass
- elif F6 == 'F_InputtingBean_Pause':
- pass
- # 若 F1~F6 桶槽中 無桶槽正在入料或入料等待, 且 FI1 可出豆時
- elif FermentUp_InputtingBean_number == 0 and FermentUp_InputtingBeanPause_number == 0 and FI1 == 'FI_OutputtingBean' and FermentUp_Waiting_number >= 1:
- if F1 == 'F_Waiting':
- # [致動器] 馬達 5
- data = { "tank_num": "F1", "command": "tank_motor_status", "value": "5" }
- print('data: ', data)
- # mqtt_f(data)
- F1 = 'F_InputtingBean'
- print('------- F1 狀態更新:入料中 -------')
- elif F2 == 'F_Waiting':
- pass
- elif F3 == 'F_Waiting':
- pass
- elif F4 == 'F_Waiting':
- pass
- elif F5 == 'F_Waiting':
- pass
- elif F6 == 'F_Waiting':
- pass
- # 若 F1~F6 桶槽中 無桶槽正在入水, 則入豆完成者轉換狀態 開始入水
- elif FermentUp_InputtingWater_number == 0 and FermentUp_InputtingBeanFinish_number >= 1:
- if F1 == 'F_InputtingBean_Finish':
- F1 = 'F_InputtingWater'
- print('------- F1 狀態更新:入水中 -------')
- # [致動器] 浮選三通閥 ON
- data = { "tank_num": "F1", "command": "outer_threewayvalve_float_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- if (F_UP_tank_WaterLevel[0] == 0):
- # [致動器] 桶外進水電磁閥 ON
- data = { "tank_num": "F1", "command": "outer_solenoid_water_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- if (F_UP_UltraSoniclist[0] < Ferment_Tank_water_height):
- # 桶內高度若低於水位指定高度, [致動器] 桶內進水電磁閥 ON
- data = { "tank_num": "F1", "command": "tank_solenoid_water_in_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- elif F2 == 'F_InputtingBean_Finish':
- pass
- elif F3 == 'F_InputtingBean_Finish':
- pass
- elif F4 == 'F_InputtingBean_Finish':
- pass
- elif F5 == 'F_InputtingBean_Finish':
- pass
- elif F6 == 'F_InputtingBean_Finish':
- pass
- elif FermentUp_InputtingWater_number == 1:
- if F1 == 'F_InputtingWater':
- # 若夾層入水達水位計高度 且 桶內入水達指定水位高度, 狀態轉換為發酵中
- if (F_UP_tank_WaterLevel[0] == 1) and (F_UP_UltraSoniclist[0] >= Ferment_Tank_water_height):
- # 桶外水位高度高於水位計高度, [致動器] 桶外進水電磁閥 OFF
- data = { "tank_num": "F1", "command": "outer_solenoid_water_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- # 桶內高度若高於水位指定高度, [致動器] 桶內進水電磁閥 OFF
- data = { "tank_num": "F1", "command": "tank_solenoid_water_in_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- F1 = 'F_Fermenting'
- print('------- F1 狀態更新:發酵中 -------')
- # 若勾選 發酵時桶內抽真空?
- if Ferment_cb_vacuum == 'true':
- # [致動器] 入料三通閥 ON排氣
- data = { "tank_num": "F1", "command": "tank_threewayvalve_input_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 外桶浮選三通閥 OFF
- data = { "tank_num": "F1", "command": "outer_threewayvalve_float_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 真空吸料機 ON
- data = { "tank_num": "F1", "command": "tank_vacuum_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- print('真空發酵, 桶槽抽氣 ' , Ferment_cb_vacuum_time, ' 秒')
- timer = time.time()
- while True:
- if (time.time() - timer) > Ferment_cb_vacuum_time:
- # [致動器] 入料真空吸料機 OFF
- data = { "tank_num": "F1", "command": "tank_vacuum_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- break
- # [致動器] 馬達 (指定轉速)
- data = { "tank_num": "F1", "command": "tank_motor_status", "value": Ferment_Tank_motor_rpm }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 溫控開關 ON
- # data = { "tank_num": "F1", "command": "tank_temp_enable_status", "value": "on", "duration": Ferment_Tank_fermenting_time}
- # print('data: ', data)
- # # mqtt_f(data)
- # [致動器] 設定溫度、持溫時間
- # [致動器] 加熱器 1 ON
- data = { "tank_num": "F1", "command": "tank_heater1_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 雙核薄膜泵 水質檢測 ON
- data = { "tank_num": "F1", "command": "tank_pump_sensor_status", "value": "on"}
- print('data: ', data)
- # mqtt_f(data)
- # TODO 增加發酵條件等
- elif (F_UP_tank_WaterLevel[0] == 1):
- # [致動器] 桶外進水電磁閥 OFF
- data = { "tank_num": "F1", "command": "outer_solenoid_water_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- elif (F_UP_UltraSoniclist[0] >= Ferment_Tank_water_height):
- # 桶內高度若高於水位指定高度, [致動器] 桶內進水電磁閥 OFF
- data = { "tank_num": "F1", "command": "tank_solenoid_water_in_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- else:
- if F1 == 'F_Fermenting' and F_UP_tank_SHT11_Temp[0] >= Ferment_Tank_fermenting_temp and F_UP_tank_PH[0] <= Ferment_Tank_fermenting_pH:
- print('發酵等待 ', Ferment_Tank_fermenting_time, ' 秒')
- timer = time.time()
- while True:
- if (time.time() - timer) > Ferment_Tank_fermenting_time :
- # [致動器] 外桶浮選三通閥 OFF
- data = { "tank_num": "F1", "command": "outer_threewayvalve_float_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 馬達 0
- data = { "tank_num": "F1", "command": "tank_motor_status", "value": "0" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 溫控開關 OFF
- # data = { "tank_num": "F1", "command": "tank_temp_enable_status", "value": "off" }
- # print('data: ', data)
- # # mqtt_f(data)
- # [致動器] 加熱器 1 OFF
- data = { "tank_num": "F1", "command": "tank_heater1_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 雙核薄膜泵 水質檢測 OFF
- data = { "tank_num": "F1", "command": "tank_pump_sensor_status", "value": "off"}
- print('data: ', data)
- # mqtt_f(data)
- # TODO 增加發酵條件等
- break
- # [致動器] 廢水排水閥 (桶內) ON
- data = { "tank_num": "F1", "command": "tank_solenoid_water_out_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- print('桶內廢水排水 ', Ferment_Tank_WaterOut_time, ' 秒')
- timer = time.time()
- while True:
- if (time.time() - timer) > Ferment_Tank_WaterOut_time:
- # [致動器] 廢水排水閥 (桶內) OFF
- data = { "tank_num": "F1", "command": "tank_solenoid_water_out_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- break
- F1 = 'F_OutputtingBean'
- print('------- F1 狀態更新:可出豆 -------')
- # 將可出豆桶槽賦值
- if FOutputtingBean_Tank == '': FOutputtingBean_Tank = 'F1'
- if F2 == 'F_Fermenting':
- pass
- if F3 == 'F_Fermenting':
- pass
- if F4 == 'F_Fermenting':
- pass
- if F5 == 'F_Fermenting':
- pass
- if F6 == 'F_Fermenting':
- pass
-
- # 若桶槽 F1~F6 可出豆 且 桶槽內為空桶 且 有指定清洗排程, 進行清洗桶槽
- # TODO 發酵次數計算、消毒次數、校正
- if F1 == 'F_OutputtingBean' and (F_UP_UltraSoniclist[0] <= Ferment_Tank_bean_empty):
- FOutputtingBean_Tank = ''
- if (FermentAuto_cleaning == 0): F1 = 'F_Waiting'
- elif (FermentAuto_cleaning != 0): F1 = 'F_Cleaning'
- if F2 == 'F_OutputtingBean' and (F_UP_UltraSoniclist[1] <= Ferment_Tank_bean_empty):
- pass
- if F3 == 'F_OutputtingBean' and (F_UP_UltraSoniclist[2] <= Ferment_Tank_bean_empty):
- pass
- if F4 == 'F_OutputtingBean' and (F_UP_UltraSoniclist[3] <= Ferment_Tank_bean_empty):
- pass
- if F5 == 'F_OutputtingBean' and (F_UP_UltraSoniclist[4] <= Ferment_Tank_bean_empty):
- pass
- if F6 == 'F_OutputtingBean' and (F_UP_UltraSoniclist[5] <= Ferment_Tank_bean_empty):
- pass
- # 避免桶槽可出豆時未賦值
- if FOutputtingBean_Tank == '':
- if F1 == 'F_OutputtingBean': FOutputtingBean_Tank = 'F1'
- elif F2 == 'F_OutputtingBean': FOutputtingBean_Tank = 'F2'
- elif F3 == 'F_OutputtingBean': FOutputtingBean_Tank = 'F3'
- elif F4 == 'F_OutputtingBean': FOutputtingBean_Tank = 'F4'
- elif F5 == 'F_OutputtingBean': FOutputtingBean_Tank = 'F5'
- elif F6 == 'F_OutputtingBean': FOutputtingBean_Tank = 'F6'
-
- # 若桶槽 F1~F6 為清洗中
- if F1 == 'F_Cleaning':
- # [致動器] 浮選三通閥 OFF
- data = { "tank_num": "F1", "command": "outer_threewayvalve_float_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 逆洗雙核薄膜泵電磁閥 ON
- data = { "tank_num": "F1", "command": "solenoid_tank_pump_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 馬達 10
- data = { "tank_num": "F1", "command": "tank_motor_status", "value": "10" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 消毒電磁閥 ON
- data = { "tank_num": "F1", "command": "tank_solenoid_disinfect_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 消毒抽水 Pump ON TODO
- # 暫停 (消毒時間) 秒
- timer = time.time()
- while True:
- if (time.time() - timer) > Ferment_Tank_Disinfect_time :
- # [致動器] 消毒電磁閥 OFF
- data = { "tank_num": "F1", "command": "tank_solenoid_disinfect_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- break
- # [致動器] 消毒抽水 Pump OFF TODO
- # [致動器] 馬達 0
- data = { "tank_num": "F1", "command": "tank_motor_status", "value": "0" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 浮選三通閥 ON
- data = { "tank_num": "F1", "command": "outer_threewayvalve_float_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 逆洗雙核薄膜泵電磁閥 OFF
- data = { "tank_num": "F1", "command": "solenoid_tank_pump_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 消毒電磁閥 OFF
- data = { "tank_num": "F1", "command": "tank_solenoid_disinfect_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 廢水排水閥 (桶內) ON
- data = { "tank_num": "F1", "command": "tank_solenoid_water_out_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- print('桶內廢水排水 ', Ferment_Tank_WaterOut_time, ' 秒')
- timer = time.time()
- while True:
- if (time.time() - timer) > Ferment_Tank_WaterOut_time:
- # [致動器] 廢水排水閥 (桶內) OFF
- data = { "tank_num": "F1", "command": "tank_solenoid_water_out_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- break
- F1 = 'F_Waiting'
- print('------- F1 狀態更新:空桶等待 -------')
- if F2 == 'F_Cleaning':
- pass
- if F3 == 'F_Cleaning':
- pass
- if F4 == 'F_Cleaning':
- pass
- if F5 == 'F_Cleaning':
- pass
- if F6 == 'F_Cleaning':
- pass
-
- # # ----- [測試用] !!!!! F1~F6 入料完成→可出豆 判斷 ------------------------------
- # if F1 == 'F_InputtingBean_Finish': F1 = 'F_OutputtingBean'
- # if F2 == 'F_InputtingBean_Finish': F2 = 'F_OutputtingBean'
- # if F3 == 'F_InputtingBean_Finish': F3 = 'F_OutputtingBean'
- # if F4 == 'F_InputtingBean_Finish': F4 = 'F_OutputtingBean'
- # if F5 == 'F_InputtingBean_Finish': F5 = 'F_OutputtingBean'
- # if F6 == 'F_InputtingBean_Finish': F6 = 'F_OutputtingBean'
- # # ----- [測試用] !!!!! F1~F6 入料完成→可出豆 判斷 ------------------------------
- else:
- # [介面] 若未啟用 發酵 狀態
- print('未啟用發酵流程')
- # ----- 發酵出料儲豆槽 FO1~FO2 入豆→可出豆判斷 ------------------------------
- # 目前發酵槽 F1~F6 正在入豆、入水的桶槽數量 (應小於一桶)
- # Ferment_OutputtingBean_number = int(F_UP_tanklist.count('F_OutputtingBean'))
- # 若出料儲豆槽狀態為 空桶等待 且 桶槽狀態為 F_OutputtingBean 可出豆, 與 FO1 配合開始出豆
-
- if FO1 == 'FO_Waiting' and FOutputtingBean_Tank != '':
- # 判斷要對應出料的桶槽為何, 設定成 FOutputtingBean_Tank = 'F1', 待出完料再把 FOutputtingBean_Tank == ''
- FO1 = 'FO_InputtingBean'
- print('------- ' + FOutputtingBean_Tank + ' 狀態更新:出豆中 -------')
- print('------- FO1 狀態更新:入豆中 -------')
- # [致動器] F1 蝴蝶閥 ON
- data = { "tank_num": FOutputtingBean_Tank, "command": "tank_diskvalve_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- elif FO1 == 'FO_InputtingBean' and FOutputtingBean_Tank != '':
- if FO_UP_UltraSoniclist[0] >= Ferment_Output_bean_height:
- # [致動器] 出料真空吸料機 OFF
- data = { "tank_num": FOutputtingBean_Tank, "command": "input_vacuum_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] F1 蝴蝶閥 OFF
- data = { "tank_num": FOutputtingBean_Tank, "command": "tank_diskvalve_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- FO1 = 'FO_OutputtingBean'
- print('------- FO1 狀態更新:出豆中 -------')
- elif FO_UP_UltraSoniclist[0] < Ferment_Output_bean_height:
- # [致動器] 出料真空吸料機 ON
- data = { "tank_num": FOutputtingBean_Tank, "command": "input_vacuum_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- timer = time.time()
- while True:
- if (time.time() - timer) > Ferment_Output_vacuumON_time:
- # [致動器] 出料真空吸料機 OFF
- data = { "tank_num": FOutputtingBean_Tank, "command": "input_vacuum_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- timer = time.time()
- break
- while True:
- if (time.time() - timer) > Ferment_Output_vacuumOFF_time:
- break
- # 若是無桶槽可入豆, 出料儲豆槽判斷是否可出豆或空桶等待入豆
- elif FOutputtingBean_Tank == '':
- if FO_UP_UltraSoniclist[0] > Ferment_Output_bean_empty:
- FO1 == 'FO_OutputtingBean'
- print('------- FO1 狀態更新:出豆中 -------')
- elif FO_UP_UltraSoniclist[0] <= Ferment_Output_bean_empty:
- FO1 == 'FO_Waiting'
- print('------- FO1 狀態更新:空桶等待 -------')
- elif FO1 == 'FO_OutputtingBean' and FO_UP_UltraSoniclist[0] <= Ferment_Output_bean_empty:
- FO1 == 'FO_Waiting'
- print('------- FO1 狀態更新:空桶等待 -------')
- # ----- 將狀態寫入資料庫 ------------------------------
- # 獲取文本框的值並賦值給user實體對象
- F_status = ferment_container_status()
- F_status.Ferment_Input_1 = FI1
- F_status.Ferment_Input_2 = FI2
- F_status.Ferment_Tank_1 = F1
- F_status.Ferment_Tank_2 = F2
- F_status.Ferment_Tank_3 = F3
- F_status.Ferment_Tank_4 = F4
- F_status.Ferment_Tank_5 = F5
- F_status.Ferment_Tank_6 = F6
- F_status.Ferment_Tank_7 = F7
- F_status.Ferment_Tank_8 = F8
- F_status.Ferment_Tank_9 = F9
- F_status.Ferment_Tank_10 = F10
- F_status.Ferment_Tank_11 = F11
- F_status.Ferment_Tank_12 = F12
- F_status.Ferment_Output_1 = FO1
- F_status.Ferment_Output_2 = FO2
- #將數據保存進資料庫
- db.session.add(F_status)
- # 手動提交
- db.session.commit()
- # ----- 將狀態寫入資料庫 ------------------------------
- return jsonify({"Peel_Output_1":PO1,
- "Ferment_Input_1":FI1,
- "Ferment_Tank_1":F1,
- "Ferment_Tank_2":F2,
- "Ferment_Tank_3":F3,
- "Ferment_Tank_4":F4,
- "Ferment_Tank_5":F5,
- "Ferment_Tank_6":F6,
- "Ferment_Output_1":FO1
- })
- # 1026 以流程圖判斷, 改寫 def ferment_auto_test, 以下為原備份
- @main.route('/ferment_auto_test_1026backup')
- def ferment_auto_test_1026backup():
- info = request.args.to_dict()
- # 從介面取得 指定生豆高度/發酵桶槽排程:發酵、清洗、校正 EC、校正攪拌棒
- Ferment_Input_bean_empty = 2
- Ferment_Tank_bean_empty = 2
- Ferment_Output_bean_empty = 2
- FermentAuto_fermenting = int(info['FermentAuto_fermenting'])
- FermentAuto_cleaning = int(info['FermentAuto_cleaning'])
- FermentAuto_calibratingEC = int(info['FermentAuto_calibratingEC'])
- FermentAuto_calibratingSTIR = int(info['FermentAuto_calibratingSTIR'])
- Ferment_Input_bean_height = float(info['Ferment_Input_bean_height'])
- Ferment_Input_vacuumON_time = float(info['Ferment_Input_vacuumON_time'])
- Ferment_Input_vacuumOFF_time = float(info['Ferment_Input_vacuumOFF_time'])
- Ferment_Tank_bean_height = float(info['Ferment_Tank_bean_height'])
- Ferment_Tank_vacuumON_time = float(info['Ferment_Tank_vacuumON_time'])
- Ferment_Tank_vacuumOFF_time = float(info['Ferment_Tank_vacuumOFF_time'])
- Ferment_Tank_water_height = float(info['Ferment_Tank_water_height'])
- Ferment_Tank_fermenting_temp = float(info['Ferment_Tank_fermenting_temp'])
- Ferment_Tank_fermenting_time = float(info['Ferment_Tank_fermenting_time'])
- Ferment_Tank_motor_rpm = float(info['Ferment_Tank_motor_rpm'])
- Ferment_Tank_motor_time = float(info['Ferment_Tank_motor_time'])
- Ferment_Tank_fermenting_pH = float(info['Ferment_Tank_fermenting_pH'])
- Ferment_Output_bean_height = float(info['Ferment_Output_bean_height'])
- Ferment_Output_vacuumON_time = float(info['Ferment_Output_vacuumON_time'])
- Ferment_Output_vacuumOFF_time = float(info['Ferment_Output_vacuumOFF_time'])
- Ferment_Tank_WaterOut_time = float(info['Ferment_Tank_WaterOut_time'])
- Ferment_Tank_Disinfect_time = float(info['Ferment_Tank_Disinfect_time'])
- # print('發酵自動化_指定生豆高度: ', Ferment_Tank_bean_height)
- # print('發酵自動化_發酵排程: ', FermentAuto_fermenting, type(FermentAuto_fermenting))
- # print('發酵自動化_清洗排程: ', FermentAuto_cleaning, type(FermentAuto_cleaning))
- # print('發酵自動化_校正 EC 排程: ', FermentAuto_calibratingEC, type(FermentAuto_calibratingEC))
- # print('發酵自動化_校正攪拌棒排程: ', FermentAuto_calibratingSTIR, type(FermentAuto_calibratingSTIR))
- # [介面] 讓使用者可以選擇排程內有發酵/清洗/校正, 此處預設為 True
- Ferment_btn = FermentAuto_fermenting # Ferment_btn = True
- # 從資料庫資料表中取得最新狀態
- ferment_status = ferment_container_status.query.order_by(text('datetime desc')).first()
- FI1 = ferment_status.Ferment_Input_1
- FI2 = ferment_status.Ferment_Input_2
- F1 = ferment_status.Ferment_Tank_1
- F2 = ferment_status.Ferment_Tank_2
- F3 = ferment_status.Ferment_Tank_3
- F4 = ferment_status.Ferment_Tank_4
- F5 = ferment_status.Ferment_Tank_5
- F6 = ferment_status.Ferment_Tank_6
- F7 = ferment_status.Ferment_Tank_7
- F8 = ferment_status.Ferment_Tank_8
- F9 = ferment_status.Ferment_Tank_9
- F10 = ferment_status.Ferment_Tank_10
- F11 = ferment_status.Ferment_Tank_11
- F12 = ferment_status.Ferment_Tank_12
- FO1 = ferment_status.Ferment_Output_1
- FO2 = ferment_status.Ferment_Output_2
- clean_status = clean_container_status.query.order_by(text('datetime desc')).first()
- PO1 = clean_status.Peel_Output_1 # PO_Waiting # PO_OutputtingBean
- PO2 = clean_status.Peel_Output_2
- F_UP_tanklist = [F1, F2, F3, F4, F5, F6]
- F_DOWN_tanklist = [F7, F8, F9, F10, F11, F12]
- # ----- 發酵入料儲豆槽 FI1~FI2 入豆→可出豆判斷 ------------------------------
- # 目前發酵槽 F1~F6 正在入豆的桶槽數量 (應小於一桶)
- FermentUp_InputtingBean_number = int(F_UP_tanklist.count('F_InputtingBean'))
- FermentUp_InputtingBeanPause_number = int(F_UP_tanklist.count('F_InputtingBean_Pause'))
- # -- 取得發酵入料儲豆槽 FI1~FI2 桶內高度 UltraSonic -------------
- FI_UP_UltraSoniclist = []
- for i in range(1, 3, 1):
- input_UltraSonic = ferment_input_UltraSonic.query.filter_by(tank_num='F' + str(i)).order_by(text('datetime desc')).first()
- # UltraSonic = float("{:.2f}".format(34.6 - float(input_UltraSonic.UltraSonic)))
- UltraSonic = float(input_UltraSonic.UltraSonic)
- FI_UP_UltraSoniclist.append(UltraSonic)
- print('FI_UP_UltraSoniclist: ', FI_UP_UltraSoniclist)
- # -- 取得發酵入料儲豆槽 FI1~FI2 桶內高度 UltraSonic -------------
- # 入料儲豆槽等待中、且脫皮機儲豆槽可出豆時, 入料儲豆槽入豆
- if FI1 == 'FI_Waiting' and PO1 == 'PO_OutputtingBean':
- FI1 = 'FI_InputtingBean'
- print('------- FI1 狀態更新:入豆中 -------')
- # [致動器] 入料真空吸料機 ON
- data = { "tank_num": "F1", "command": "input_vacuum_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- timer = time.time()
- while True:
- if (time.time() - timer) > Ferment_Input_vacuumON_time:
- # [致動器] 入料真空吸料機 OFF
- data = { "tank_num": "F1", "command": "input_vacuum_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- timer = time.time()
- break
- while True:
- if (time.time() - timer) > Ferment_Input_vacuumOFF_time:
- break
- # 入料儲豆槽入豆時
- elif FI1 == 'FI_InputtingBean':
- # 桶槽內未達指定生豆高度, 且 前方 PO1 可出豆, 就執行入料動作
- if (FI_UP_UltraSoniclist[0] < Ferment_Input_bean_height) and PO1 == 'PO_OutputtingBean':
- # [致動器] 入料真空吸料機 ON
- data = { "tank_num": "F1", "command": "input_vacuum_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- timer = time.time()
- while True:
- if (time.time() - timer) > Ferment_Input_vacuumON_time:
- # [致動器] 入料真空吸料機 OFF
- data = { "tank_num": "F1", "command": "input_vacuum_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- timer = time.time()
- break
- while True:
- if (time.time() - timer) > Ferment_Input_vacuumOFF_time:
- break
- # 桶槽內達指定生豆高度時, 入料儲豆槽狀態轉為 可出豆
- if (FI_UP_UltraSoniclist[0] >= Ferment_Input_bean_height):
- FI1 = 'FI_OutputtingBean'
- print('------- FI1 狀態更新:可出豆 -------')
-
- # 入料儲豆槽出豆時, 桶槽高度為 空桶高度時, 狀態轉為 空桶等待
- elif FI1 == 'FI_OutputtingBean' and (FI_UP_UltraSoniclist[0] <= Ferment_Input_bean_empty):
- FI1 = 'FI_Waiting'
- print('------- FI1 狀態更新:空桶等待 -------')
- # [1012 刪除, 避免混豆]若入料儲豆槽可出豆 且 儲豆槽內高度低於 40 且 前方脫皮機儲豆槽可出豆 且 目前無桶槽需入料時
- # elif FI1 == 'FI_OutputtingBean' and (FI_UP_UltraSoniclist[0] < 40) and PO1 == 'PO_OutputtingBean' and FermentUp_InputtingBean_number == 0 and FermentUp_InputtingBeanPause_number == 0:
- # FI1 = 'FI_InputtingBean'
- # print('------- FI1 狀態更新:入豆中 -------')
-
- # if FI2 == 'FI_Waiting' and PO2 == 'PO_OutputtingBean':
- # FI2 = 'FI_InputtingBean'
- # print('------- FI2 狀態更新:入豆中 -------')
- # elif FI2 == 'FI_InputtingBean' and ((FI_UP_UltraSoniclist[1] >= 35) or (PO2 != 'PO_OutputtingBean')) :
- # FI2 = 'FI_OutputtingBean'
- # print('------- FI2 狀態更新:可出豆 -------')
- # elif FI2 == 'FI_OutputtingBean' and (FI_UP_UltraSoniclist[1] < 40) and PO2 == 'PO_OutputtingBean' and FermentUp_InputtingBean_number == 0 and FermentUp_InputtingBeanPause_number == 0:
- # FI2 = 'FI_InputtingBean'
- # print('------- FI2 狀態更新:入豆中 -------')
-
- # ----- 發酵桶槽 F1~F6 入料暫停→入料判斷 ------------------------------
- ### 移到入料
- # ----- 發酵桶槽 F1~F6 等待→入料判斷 ------------------------------
- # -- 取得發酵桶槽 F1~F6 桶內高度 UltraSonic -------------
- F_UP_UltraSoniclist = []
- for i in range(1, 7, 1):
- tank_UltraSonic = ferment_tank_UltraSonic.query.filter_by(tank_num='F' + str(i)).order_by(text('datetime desc')).first()
- UltraSonic = (float(tank_UltraSonic.UltraSonic))
- F_UP_UltraSoniclist.append(UltraSonic)
- print('F_UP_UltraSoniclist: ', F_UP_UltraSoniclist)
- # -- 取得發酵桶槽 F1~F6 桶內高度 UltraSonic -------------
- # [介面] 若啟用 發酵 狀態
- if Ferment_btn:
- # 若入料儲豆槽可出料狀態
- if FI1 == 'FI_OutputtingBean':
- # 若 F1~F6 發酵桶槽為 入豆中, 繼續入豆, 當高度 > 指定生豆高度 時入豆完成
- if F1 == 'F_InputtingBean':
- if (F_UP_UltraSoniclist[0] >= Ferment_Tank_bean_height):
- F1 = 'F_InputtingBean_Finish'
- print('------- F1 狀態更新:入料完成 -------')
- # [致動器] 入料三通閥 ON排氣
- data = { "tank_num": "F1", "command": "tank_threewayvalve_input_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 馬達 0
- data = { "tank_num": "F1", "command": "tank_motor_status", "value": "0" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 真空吸料機 OFF
- data = { "tank_num": "F1", "command": "tank_vacuum_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- else:
- # [致動器] 真空吸料機 ON
- data = { "tank_num": "F1", "command": "tank_vacuum_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- timer = time.time()
- while True:
- if (time.time() - timer) > Ferment_Tank_vacuumON_time:
- # [致動器] 入料真空吸料機 OFF
- data = { "tank_num": "F1", "command": "tank_vacuum_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- timer = time.time()
- break
- while True:
- if (time.time() - timer) > Ferment_Tank_vacuumOFF_time:
- break
- if F2 == 'F_InputtingBean' and (F_UP_UltraSoniclist[1] >= Ferment_Tank_bean_height):
- F2 = 'F_InputtingBean_Finish'
- print('------- F2 狀態更新:入料完成 -------')
- if F3 == 'F_InputtingBean' and (F_UP_UltraSoniclist[2] >= Ferment_Tank_bean_height):
- F3 = 'F_InputtingBean_Finish'
- print('------- F3 狀態更新:入料完成 -------')
- if F4 == 'F_InputtingBean' and (F_UP_UltraSoniclist[3] >= Ferment_Tank_bean_height):
- F4 = 'F_InputtingBean_Finish'
- print('------- F4 狀態更新:入料完成 -------')
- if F5 == 'F_InputtingBean' and (F_UP_UltraSoniclist[4] >= Ferment_Tank_bean_height):
- F5 = 'F_InputtingBean_Finish'
- print('------- F5 狀態更新:入料完成 -------')
- if F6 == 'F_InputtingBean' and (F_UP_UltraSoniclist[5] >= Ferment_Tank_bean_height):
- F6 = 'F_InputtingBean_Finish'
- print('------- F6 狀態更新:入料完成 -------')
- # 若有兩個以上桶槽入料中, 則桶號最小者優先入料 ←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←← 1021 優先入豆判斷
- if FermentUp_InputtingBean_number == 1:
- if F1 == 'F_InputtingBean':
- # [致動器] 桶槽真空吸料機 ON
- data = { "tank_num": "F1", "command": "tank_vacuum_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- timer = time.time()
- while True:
- if (time.time() - timer) > Ferment_Tank_vacuumON_time:
- # [致動器] 桶槽真空吸料機 OFF
- data = { "tank_num": "F1", "command": "tank_vacuum_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- timer = time.time()
- break
- while True:
- if (time.time() - timer) > Ferment_Tank_vacuumOFF_time:
- break
- # else if F2 == ''...
- # 若 F1~F6 發酵桶槽為 入豆暫停, 則狀態改為優先入豆 ←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←← 1021 優先入豆判斷
- elif FermentUp_InputtingBeanPause_number >= 1:
- if F1 == 'F_InputtingBean_Pause':
- F1 = 'F_InputtingBean'
- print('------- F1 狀態更新:入料中 -------')
- # [致動器] 桶槽真空吸料機 ON
- data = { "tank_num": "F1", "command": "tank_vacuum_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- timer = time.time()
- while True:
- if (time.time() - timer) > Ferment_Tank_vacuumON_time:
- # [致動器] 桶槽真空吸料機 OFF
- data = { "tank_num": "F1", "command": "tank_vacuum_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- timer = time.time()
- break
- while True:
- if (time.time() - timer) > Ferment_Tank_vacuumOFF_time:
- break
- elif F2 == 'F_InputtingBean_Pause':
- F2 = 'F_InputtingBean'
- print('------- F2 狀態更新:入料中 -------')
- elif F3 == 'F_InputtingBean_Pause':
- F3 = 'F_InputtingBean'
- print('------- F3 狀態更新:入料中 -------')
- elif F4 == 'F_InputtingBean_Pause':
- F4 = 'F_InputtingBean'
- print('------- F4 狀態更新:入料中 -------')
- elif F5 == 'F_InputtingBean_Pause':
- F5 = 'F_InputtingBean'
- print('------- F5 狀態更新:入料中 -------')
- elif F6 == 'F_InputtingBean_Pause':
- F6 = 'F_InputtingBean'
- print('------- F6 狀態更新:入料中 -------')
- # 若 F1~F6 皆無入豆 無入豆暫停, 則桶號最小者開始入豆
- elif FermentUp_InputtingBean_number == 0 and FermentUp_InputtingBeanPause_number == 0:
- if F1 == 'F_Waiting':
- F1 = 'F_InputtingBean'
- print('------- F1 狀態更新:入料中 -------')
- # [致動器] 入料入料三通閥 OFF入豆
- data = { "tank_num": "F1", "command": "tank_threewayvalve_input_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 馬達 5
- data = { "tank_num": "F1", "command": "tank_motor_status", "value": "5" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 桶槽真空吸料機 ON
- data = { "tank_num": "F1", "command": "tank_vacuum_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- timer = time.time()
- while True:
- if (time.time() - timer) > Ferment_Tank_vacuumON_time:
- # [致動器] 桶槽真空吸料機 OFF
- data = { "tank_num": "F1", "command": "tank_vacuum_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- timer = time.time()
- break
- while True:
- if (time.time() - timer) > Ferment_Tank_vacuumON_time:
- break
- elif F2 == 'F_Waiting':
- F2 = 'F_InputtingBean'
- print('------- F2 狀態更新:入料中 -------')
- elif F3 == 'F_Waiting':
- F3 = 'F_InputtingBean'
- print('------- F3 狀態更新:入料中 -------')
- elif F4 == 'F_Waiting':
- F4 = 'F_InputtingBean'
- print('------- F4 狀態更新:入料中 -------')
- elif F5 == 'F_Waiting':
- F5 = 'F_InputtingBean'
- print('------- F5 狀態更新:入料中 -------')
- elif F6 == 'F_Waiting':
- F6 = 'F_InputtingBean'
- print('------- F6 狀態更新:入料中 -------')
- # 若入料儲豆槽非可出豆, 且 F1~F6 其中有桶槽入料中, 若桶槽未滿則入料暫停
- elif FI1 != 'FI_InputtingBean' and FermentUp_InputtingBean_number >= 1:
- if F1 == 'F_InputtingBean' and F_UP_UltraSoniclist[0] < Ferment_Tank_bean_height:
- F1 = 'F_InputtingBean_Pause'
- print('------- F1 狀態更新:入料暫停 -------')
- # [致動器] 桶槽真空吸料機 OFF
- data = { "tank_num": "F1", "command": "tank_vacuum_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- elif F1 == 'F_InputtingBean' and F_UP_UltraSoniclist[0] >= Ferment_Tank_bean_height:
- F1 = 'F_InputtingBean_Finish'
- print('------- F1 狀態更新:入料完成 -------')
- # [致動器] 入料三通閥 ON排氣
- data = { "tank_num": "F1", "command": "tank_threewayvalve_input_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 馬達 0
- data = { "tank_num": "F1", "command": "tank_motor_status", "value": "0" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 入料真空吸料機 OFF
- data = { "tank_num": "F1", "command": "input_vacuum_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- if F2 == 'F_InputtingBean' and F_UP_UltraSoniclist[1] < Ferment_Tank_bean_height:
- F2 = 'F_InputtingBean_Pause'
- print('------- F2 狀態更新:入料暫停 -------')
- elif F2 == 'F_InputtingBean' and F_UP_UltraSoniclist[1] >= Ferment_Tank_bean_height:
- F2 = 'F_InputtingBean_Finish'
- print('------- F2 狀態更新:入料完成 -------')
- if F3 == 'F_InputtingBean' and F_UP_UltraSoniclist[2] < Ferment_Tank_bean_height:
- F3 = 'F_InputtingBean_Pause'
- print('------- F3 狀態更新:入料暫停 -------')
- elif F3 == 'F_InputtingBean' and F_UP_UltraSoniclist[2] >= Ferment_Tank_bean_height:
- F3 = 'F_InputtingBean_Finish'
- print('------- F3 狀態更新:入料完成 -------')
- if F4 == 'F_InputtingBean' and F_UP_UltraSoniclist[3] < Ferment_Tank_bean_height:
- F4 = 'F_InputtingBean_Pause'
- print('------- F4 狀態更新:入料暫停 -------')
- elif F4 == 'F_InputtingBean' and F_UP_UltraSoniclist[3] >= Ferment_Tank_bean_height:
- F4 = 'F_InputtingBean_Finish'
- print('------- F4 狀態更新:入料完成 -------')
- if F5 == 'F_InputtingBean' and F_UP_UltraSoniclist[4] < Ferment_Tank_bean_height:
- F5 = 'F_InputtingBean_Pause'
- print('------- F5 狀態更新:入料暫停 -------')
- elif F5 == 'F_InputtingBean' and F_UP_UltraSoniclist[4] >= Ferment_Tank_bean_height:
- F5 = 'F_InputtingBean_Finish'
- print('------- F5 狀態更新:入料完成 -------')
- if F6 == 'F_InputtingBean' and F_UP_UltraSoniclist[5] < Ferment_Tank_bean_height:
- F6 = 'F_InputtingBean_Pause'
- print('------- F6 狀態更新:入料暫停 -------')
- elif F6 == 'F_InputtingBean' and F_UP_UltraSoniclist[5] >= Ferment_Tank_bean_height:
- F6 = 'F_InputtingBean_Finish'
- print('------- F6 狀態更新:入料完成 -------')
- else:
- # 若入料儲豆槽非可出料狀態
- print('發酵入料儲豆槽空, 桶槽無法入料')
- else:
- # [介面] 若未啟用 發酵 狀態
- print('未啟用發酵流程')
- # ----- 10/07 --------------------------------------------------------------------------------------------------------------------------------
- # ----- 發酵桶槽 F1~F6 入料→入料暫停判斷 ------------------------------
- ### 移到入料
- # ----- 發酵桶槽 F1~F6 入料→入水判斷 ------------------------------
- # -- 取得發酵桶槽 F1~F6 夾層水位高度 WaterLevel -------------
- F_UP_tank_WaterLevel = []
- for i in range(1, 7, 1):
- tank_WaterLevel = ferment_tank_WaterLevel.query.filter_by(tank_num='F' + str(i)).order_by(text('datetime desc')).first()
- WaterLevel = float(tank_WaterLevel.WaterLevel)
- F_UP_tank_WaterLevel.append(WaterLevel)
- print('F_UP_tank_WaterLevel: ', F_UP_tank_WaterLevel)
- # -- 取得發酵桶槽 F1~F6 夾層水位高度 WaterLevel -------------
- Ferment_InputtingBeanFinish_number = int(F_UP_tanklist.count('F_InputtingBean_Finish'))
- Ferment_InputtingWater_number = int(F_UP_tanklist.count('F_InputtingWater'))
- # 入水條件:當前桶槽入豆 + 沒有其他桶槽入水
- if Ferment_InputtingBeanFinish_number >= 1 and Ferment_InputtingWater_number == 0:
- # 當入豆到指定高度時, 狀態轉換為入水 (桶槽編號小者優先)
- # !!! 發酵槽 F_InputtingBean_Finish 狀態應該請硬體判斷
- # !!! 若狀態為 F_InputtingBean 且 超音波值>指定生豆高度, 狀態改為 F_InputtingBean_Finish 並等待入水 F_InputtingWater
- # 這邊是考慮一次僅一個桶槽入水, 多桶入水會不會速度變慢?
- if F1 == 'F_InputtingBean_Finish':
- F1 = 'F_InputtingWater'
- print('------- F1 狀態更新:入水中 -------')
- # [致動器] 外桶浮選三通閥 ON
- data = { "tank_num": "F1", "command": "outer_threewayvalve_float_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- # 桶內高度若低於水位指定高度, [致動器] 桶內進水電磁閥 ON
- if F_UP_UltraSoniclist[0] < Ferment_Tank_water_height:
- data = { "tank_num": "F1", "command": "tank_solenoid_water_in_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 桶內進水電磁閥 OFF
- else:
- data = { "tank_num": "F1", "command": "tank_solenoid_water_in_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- # 桶外水位高度若低於水位計高度, [致動器] 桶外進水電磁閥 ON
- if F_UP_tank_WaterLevel[0] != 1:
- data = { "tank_num": "F1", "command": "outer_solenoid_water_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 桶外進水電磁閥 OFF
- else:
- data = { "tank_num": "F1", "command": "outer_solenoid_water_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- elif F2 == 'F_InputtingBean_Finish':
- F2 = 'F_InputtingWater'
- print('------- F2 狀態更新:入水中 -------')
- elif F3 == 'F_InputtingBean_Finish':
- F3 = 'F_InputtingWater'
- print('------- F3 狀態更新:入水中 -------')
- elif F4 == 'F_InputtingBean_Finish':
- F4 = 'F_InputtingWater'
- print('------- F4 狀態更新:入水中 -------')
- elif F5 == 'F_InputtingBean_Finish':
- F5 = 'F_InputtingWater'
- print('------- F5 狀態更新:入水中 -------')
- elif F6 == 'F_InputtingBean_Finish':
- F6 = 'F_InputtingWater'
- print('------- F6 狀態更新:入水中 -------')
- # ----- 發酵桶槽 F1~F6 入水→發酵判斷 ------------------------------
- # !!! 發酵槽 F_Fermenting 狀態應該請硬體判斷
- # !!! 若狀態為 F_InputtingWater 且 超音波值>指定水位高度 且 夾層水位計 == 1, 狀態改為 F_Fermenting 發酵
- if F1 == 'F_InputtingWater':
- if F_UP_tank_WaterLevel[0] == 1 and F_UP_UltraSoniclist[0] >= Ferment_Tank_water_height:
- # 桶外水位高度高於水位計高度, [致動器] 桶外進水電磁閥 OFF
- data = { "tank_num": "F1", "command": "outer_solenoid_water_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- # 桶內高度若高於水位指定高度, [致動器] 桶內進水電磁閥 OFF
- data = { "tank_num": "F1", "command": "tank_solenoid_water_in_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- F1 = 'F_Fermenting'
- print('------- F1 狀態更新:發酵中 -------')
- # [致動器] 馬達 (指定轉速)
- data = { "tank_num": "F1", "command": "tank_motor_status", "value": Ferment_Tank_motor_rpm }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 溫控開關 ON
- # data = { "tank_num": "F1", "command": "tank_temp_enable_status", "value": "on" }
- # print('data: ', data)
- # # mqtt_f(data)
- # [致動器] 設定溫度、持溫時間
- # [致動器] 加熱器 1 ON
- data = { "tank_num": "F1", "command": "tank_heater1_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- elif F_UP_tank_WaterLevel[0] == 1:
- # 桶外水位高度高於水位計高度, [致動器] 桶外進水電磁閥 OFF
- data = { "tank_num": "F1", "command": "outer_solenoid_water_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- elif F_UP_UltraSoniclist[0] >= Ferment_Tank_water_height:
- # 桶內高度若高於水位指定高度, [致動器] 桶內進水電磁閥 OFF
- data = { "tank_num": "F1", "command": "tank_solenoid_water_in_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- if F2 == 'F_InputtingWater' and F_UP_tank_WaterLevel[1] == 1 and F_UP_UltraSoniclist[1] >= Ferment_Tank_water_height:
- F2 = 'F_Fermenting'
- print('------- F2 狀態更新:發酵中 -------')
- if F3 == 'F_InputtingWater' and F_UP_tank_WaterLevel[2] == 1 and F_UP_UltraSoniclist[2] >= Ferment_Tank_water_height:
- F3 = 'F_Fermenting'
- print('------- F3 狀態更新:發酵中 -------')
- if F4 == 'F_InputtingWater' and F_UP_tank_WaterLevel[3] == 1 and F_UP_UltraSoniclist[3] >= Ferment_Tank_water_height:
- F4 = 'F_Fermenting'
- print('------- F4 狀態更新:發酵中 -------')
- if F5 == 'F_InputtingWater' and F_UP_tank_WaterLevel[4] == 1 and F_UP_UltraSoniclist[4] >= Ferment_Tank_water_height:
- F5 = 'F_Fermenting'
- print('------- F5 狀態更新:發酵中 -------')
- if F6 == 'F_InputtingWater' and F_UP_tank_WaterLevel[5] == 1 and F_UP_UltraSoniclist[5] >= Ferment_Tank_water_height:
- F6 = 'F_Fermenting'
- print('------- F6 狀態更新:發酵中 -------')
-
- # ----- 發酵桶槽 F1~F6 發酵→可出豆 判斷 ------------------------------
- # TODO
- # !!! 發酵槽 F_Fermenting 狀態應該請硬體判斷
- # !!! 若狀態為 F_InputtingWater 且 超音波值>指定水位高度 且 夾層水位計 == 1, 狀態改為 F_Fermenting 發酵
- # 可以多桶各自執行發酵排程
- # -- 取得發酵桶槽 F1~F6 pH -------------
- F_UP_tank_PH = []
- for i in range(1, 7, 1):
- tank_PH = ferment_tank_PH.query.filter_by(tank_num='F' + str(i)).order_by(text('datetime desc')).first()
- PH = float(tank_PH.PH)
- F_UP_tank_PH.append(PH)
- print('F_UP_tank_PH: ', F_UP_tank_PH)
- # -- 取得發酵桶槽 F1~F6 pH -------------
- # -- 取得發酵桶槽 F1~F6 SHT11_TEMP -------------
- F_UP_tank_SHT11_Temp = []
- for i in range(1, 7, 1):
- tank_SHT11 = ferment_tank_SHT11.query.filter_by(tank_num='F' + str(i)).order_by(text('datetime desc')).first()
- SHT11_Temp = float(tank_SHT11.SHT11_Temp)
- F_UP_tank_SHT11_Temp.append(SHT11_Temp)
- print('F_UP_tank_SHT11_Temp: ', F_UP_tank_SHT11_Temp)
- # -- 取得發酵桶槽 F1~F6 SHT11_TEMP -------------
- #
- if F1 == 'F_Fermenting' and F_UP_tank_SHT11_Temp[0] >= Ferment_Tank_fermenting_temp and F_UP_tank_PH[0] <= Ferment_Tank_fermenting_pH:
- print('發酵等待 ', Ferment_Tank_fermenting_time, ' 秒')
- timer = time.time()
- while True:
- if (time.time() - timer) > Ferment_Tank_fermenting_time :
- # [致動器] 外桶浮選三通閥 OFF
- data = { "tank_num": "F1", "command": "outer_threewayvalve_float_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 馬達 0
- data = { "tank_num": "F1", "command": "tank_motor_status", "value": "0" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 溫控開關 OFF
- # data = { "tank_num": "F1", "command": "tank_temp_enable_status", "value": "off" }
- # print('data: ', data)
- # # mqtt_f(data)
- # [致動器] 加熱器 1 OFF
- data = { "tank_num": "F1", "command": "tank_heater1_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- break
- # [致動器] 廢水排水閥 (桶內) ON
- data = { "tank_num": "F1", "command": "tank_solenoid_water_out_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- print('桶內廢水排水 ', Ferment_Tank_WaterOut_time, ' 秒')
- timer = time.time()
- while True:
- if (time.time() - timer) > Ferment_Tank_WaterOut_time:
- # [致動器] 廢水排水閥 (桶內) OFF
- data = { "tank_num": "F1", "command": "tank_solenoid_water_out_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- break
- F1 = 'F_OutputtingBean'
- print('------- F1 狀態更新:可出豆 -------')
- if F2 == 'F_Fermenting' and F_UP_tank_PH[1] <= Ferment_Tank_fermenting_pH:
- F2 = 'F_OutputtingBean'
- print('------- F1 狀態更新:可出豆 -------')
- if F3 == 'F_Fermenting' and F_UP_tank_PH[2] <= Ferment_Tank_fermenting_pH:
- F3 = 'F_OutputtingBean'
- print('------- F1 狀態更新:可出豆 -------')
- if F4 == 'F_Fermenting' and F_UP_tank_PH[3] <= Ferment_Tank_fermenting_pH:
- F4 = 'F_OutputtingBean'
- print('------- F1 狀態更新:可出豆 -------')
- if F5 == 'F_Fermenting' and F_UP_tank_PH[4] <= Ferment_Tank_fermenting_pH:
- F5 = 'F_OutputtingBean'
- print('------- F1 狀態更新:可出豆 -------')
- if F6 == 'F_Fermenting' and F_UP_tank_PH[5] <= Ferment_Tank_fermenting_pH:
- F6 = 'F_OutputtingBean'
- print('------- F1 狀態更新:可出豆 -------')
-
- if F1 == 'F_OutputtingBean' and F_UP_UltraSoniclist[0] < Ferment_Tank_bean_empty:
- # 增加消毒電磁閥開關
- # [致動器] 消毒電磁閥 ON
- data = { "tank_num": "F1", "command": "tank_solenoid_disinfect_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- # 暫停 (消毒時間) 秒
- timer = time.time()
- while True:
- if (time.time() - timer) > Ferment_Tank_Disinfect_time :
- # [致動器] 消毒電磁閥 OFF
- data = { "tank_num": "F1", "command": "tank_solenoid_disinfect_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- break
- print('------- F1 狀態更新:空桶等待 -------')
- F1 = 'F_Waiting'
- # # ----- [測試用] !!!!! F1~F6 入料完成→可出豆 判斷 ------------------------------
- # if F1 == 'F_InputtingBean_Finish': F1 = 'F_OutputtingBean'
- # if F2 == 'F_InputtingBean_Finish': F2 = 'F_OutputtingBean'
- # if F3 == 'F_InputtingBean_Finish': F3 = 'F_OutputtingBean'
- # if F4 == 'F_InputtingBean_Finish': F4 = 'F_OutputtingBean'
- # if F5 == 'F_InputtingBean_Finish': F5 = 'F_OutputtingBean'
- # if F6 == 'F_InputtingBean_Finish': F6 = 'F_OutputtingBean'
- # # ----- [測試用] !!!!! F1~F6 入料完成→可出豆 判斷 ------------------------------
- # ----- 發酵桶槽 F1~F6 可出豆→出料儲豆槽 FO1 判斷 ------------------------------
- # ----- 發酵出料儲豆槽 FO1~FO2 入豆→可出豆判斷 ------------------------------
- # -- 取得發酵出料儲豆槽 FO1~FO2 桶內高度 UltraSonic -------------
- FO_UP_UltraSoniclist = []
- for i in range(1, 3, 1):
- output_UltraSonic = ferment_output_UltraSonic.query.filter_by(tank_num='FO' + str(i)).order_by(text('datetime desc')).first()
- UltraSonic = float(output_UltraSonic.UltraSonic)
- FO_UP_UltraSoniclist.append(UltraSonic)
- print('FO_UP_UltraSoniclist: ', FO_UP_UltraSoniclist)
- # 桶槽可出豆, 且出料儲豆槽等待時, 出料儲豆槽入豆
- # 參考 -- 發酵桶槽 F1~F6 可出豆→出料儲豆槽 FO1 判斷 --
- Ferment_OutputtingBean_number = int(F_UP_tanklist.count('F_OutputtingBean'))
- # !!! 若出料儲豆槽狀態為 FO_Waiting(空桶等待) 且 桶槽狀態為 F_OutputtingBean 可出豆, 與 FO1 配合開始出豆
- if FO1 == 'FO_Waiting' and Ferment_OutputtingBean_number >= 1:
- if F1 == 'F_OutputtingBean':
- FO1 = 'FO_InputtingBean'
- print('------- F1 狀態更新:出豆中 -------')
- print('------- FO1 狀態更新:入豆中 -------')
- # [致動器] 出料真空吸料機 ON
- data = { "tank_num": "F1", "command": "input_vacuum_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- # 暫停 3 秒
- timer = time.time()
- while True:
- if (time.time() - timer) > 3 :
- # [致動器] 蝴蝶閥 ON
- data = { "tank_num": "F1", "command": "tank_diskvalve_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- break
- timer = time.time()
- while True:
- if (time.time() - timer) > Ferment_Output_vacuumON_time:
- # [致動器] 出料真空吸料機 OFF
- data = { "tank_num": "F1", "command": "input_vacuum_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- timer = time.time()
- break
- while True:
- if (time.time() - timer) > Ferment_Output_vacuumOFF_time:
- break
- elif F2 == 'F_OutputtingBean':
- FO1 = 'FO_InputtingBean'
- print('------- F2 狀態更新:出豆中 -------')
- print('------- FO1 狀態更新:入豆中 -------')
- elif F3 == 'F_OutputtingBean':
- FO1 = 'FO_InputtingBean'
- print('------- F3 狀態更新:出豆中 -------')
- print('------- FO1 狀態更新:入豆中 -------')
- elif F4 == 'F_OutputtingBean':
- FO1 = 'FO_InputtingBean'
- print('------- F4 狀態更新:出豆中 -------')
- print('------- FO1 狀態更新:入豆中 -------')
- elif F5 == 'F_OutputtingBean':
- FO1 = 'FO_InputtingBean'
- print('------- F5 狀態更新:出豆中 -------')
- print('------- FO1 狀態更新:入豆中 -------')
- elif F6 == 'F_OutputtingBean':
- FO1 = 'FO_InputtingBean'
- print('------- F6 狀態更新:出豆中 -------')
- print('------- FO1 狀態更新:入豆中 -------')
- # 出料儲豆槽入料滿時, 出料儲豆槽狀態改為可出豆 (需判斷是哪個桶槽, 好關閉蝴蝶閥)
- elif FO1 == 'FO_InputtingBean' and FO_UP_UltraSoniclist[0] >= Ferment_Output_bean_height:
- if F1 == 'F_OutputtingBean':
- FO1 = 'FO_OutputtingBean'
- print('------- FO1 狀態更新:可出豆 -------')
- # [致動器] 出料真空吸料機 OFF
- data = { "tank_num": "F1", "command": "input_vacuum_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- # [致動器] 蝴蝶閥 OFF
- data = { "tank_num": "F1", "command": "tank_diskvalve_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- elif F2 == 'F_OutputtingBean':
- pass # TODO ←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←← 1020 TODO
- # 出料儲豆槽入料時, 桶槽已空, 則桶槽回到空桶等待, 出料儲豆槽可出豆 ←←←←←←←←←←←←←←←←←←←←←←←←←← 1012 這段怪怪的
- elif FO1 == 'FO_InputtingBean' and Ferment_OutputtingBean_number == 1:
- if F1 == 'F_OutputtingBean':
- if F_UP_UltraSoniclist[0] < Ferment_Tank_bean_empty:
- FO1 = 'FO_OutputtingBean'
- print('------- FO1 狀態更新:可出豆 -------')
- # 增加消毒電磁閥開關
- # [致動器] 消毒電磁閥 ON
- data = { "tank_num": "F1", "command": "tank_solenoid_disinfect_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- # 暫停 (消毒時間) 秒
- timer = time.time()
- while True:
- if (time.time() - timer) > Ferment_Tank_Disinfect_time :
- # [致動器] 消毒電磁閥 OFF
- data = { "tank_num": "F1", "command": "tank_solenoid_disinfect_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- break
- print('------- F1 狀態更新:空桶等待 -------')
- F1 = 'F_Waiting'
- else:
- # [致動器] 出料真空吸料機 ON
- data = { "tank_num": "F1", "command": "input_vacuum_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- # 暫停 3 秒
- timer = time.time()
- while True:
- if (time.time() - timer) > 3 :
- # [致動器] 蝴蝶閥 ON
- data = { "tank_num": "F1", "command": "tank_diskvalve_status", "value": "on" }
- print('data: ', data)
- # mqtt_f(data)
- break
- timer = time.time()
- while True:
- if (time.time() - timer) > Ferment_Output_vacuumON_time:
- # [致動器] 出料真空吸料機 OFF
- data = { "tank_num": "F1", "command": "input_vacuum_status", "value": "off" }
- print('data: ', data)
- # mqtt_f(data)
- timer = time.time()
- break
- while True:
- if (time.time() - timer) > Ferment_Output_vacuumOFF_time:
- break
- elif F2 == 'F_OutputtingBean' and F_UP_UltraSoniclist[1] < 5:
- F2 = 'F_Waiting'
- FO1 = 'FO_OutputtingBean'
- print('------- F2 狀態更新:空桶等待 -------')
- print('------- FO1 狀態更新:可出豆 -------')
- elif F3 == 'F_OutputtingBean' and F_UP_UltraSoniclist[2] < 5:
- F3 = 'F_Waiting'
- FO1 = 'FO_OutputtingBean'
- print('------- F3 狀態更新:空桶等待 -------')
- print('------- FO1 狀態更新:可出豆 -------')
- elif F4 == 'F_OutputtingBean' and F_UP_UltraSoniclist[3] < 5:
- F4 = 'F_Waiting'
- FO1 = 'FO_OutputtingBean'
- print('------- F4 狀態更新:空桶等待 -------')
- print('------- FO1 狀態更新:可出豆 -------')
- elif F5 == 'F_OutputtingBean' and F_UP_UltraSoniclist[4] < 5:
- F5 = 'F_Waiting'
- FO1 = 'FO_OutputtingBean'
- print('------- F5 狀態更新:空桶等待 -------')
- print('------- FO1 狀態更新:可出豆 -------')
- elif F6 == 'F_OutputtingBean' and F_UP_UltraSoniclist[5] < 5:
- F6 = 'F_Waiting'
- FO1 = 'FO_OutputtingBean'
- print('------- F6 狀態更新:空桶等待 -------')
- print('------- FO1 狀態更新:可出豆 -------')
- # 出料儲豆槽出料 且 儲豆槽內高度低於 5 , 為空桶等待
- elif FO1 == 'FO_OutputtingBean' and FO_UP_UltraSoniclist[0] < Ferment_Output_bean_empty:
- FO1 = 'FO_Waiting'
- # ----- 發酵入料儲豆槽 FI1~FI2 入豆→可出豆判斷 ------------------------------
- # 1008 移到桶槽前面
- # ----- 發酵出料儲豆槽 FO1~FO2 入豆→可出豆判斷 ------------------------------
- # 1012 移到桶槽可出豆內
- # ----- 將狀態寫入資料庫 ------------------------------
- # 獲取文本框的值並賦值給user實體對象
- F_status = ferment_container_status()
- F_status.Ferment_Input_1 = FI1
- F_status.Ferment_Input_2 = FI2
- F_status.Ferment_Tank_1 = F1
- F_status.Ferment_Tank_2 = F2
- F_status.Ferment_Tank_3 = F3
- F_status.Ferment_Tank_4 = F4
- F_status.Ferment_Tank_5 = F5
- F_status.Ferment_Tank_6 = F6
- F_status.Ferment_Tank_7 = F7
- F_status.Ferment_Tank_8 = F8
- F_status.Ferment_Tank_9 = F9
- F_status.Ferment_Tank_10 = F10
- F_status.Ferment_Tank_11 = F11
- F_status.Ferment_Tank_12 = F12
- F_status.Ferment_Output_1 = FO1
- F_status.Ferment_Output_2 = FO2
- #將數據保存進資料庫
- db.session.add(F_status)
- # 手動提交
- db.session.commit()
- # ----- 將狀態寫入資料庫 ------------------------------
- return jsonify({"Peel_Output_1":PO1,
- "Ferment_Input_1":FI1,
- "Ferment_Tank_1":F1,
- "Ferment_Tank_2":F2,
- "Ferment_Tank_3":F3,
- "Ferment_Tank_4":F4,
- "Ferment_Tank_5":F5,
- "Ferment_Tank_6":F6,
- "Ferment_Output_1":FO1
- })
- '''
- return jsonify({"Ferment_Input_1":FI1,
- "Ferment_Input_2":FI2,
- "Ferment_Tank_1":F1,
- "Ferment_Tank_2":F2,
- "Ferment_Tank_3":F3,
- "Ferment_Tank_4":F4,
- "Ferment_Tank_5":F5,
- "Ferment_Tank_6":F6,
- "Ferment_Tank_7":F7,
- "Ferment_Tank_8":F8,
- "Ferment_Tank_9":F9,
- "Ferment_Tank_10":F10,
- "Ferment_Tank_11":F11,
- "Ferment_Tank_12":F12,
- "Ferment_Output_1":FO1,
- "Ferment_Output_2":FO2
- })
- '''
- # 1026 以流程圖判斷, 改寫 def ferment_auto_test, 以上為原備份
- # 舊有 video 介面
- @main.route('/video')
- def main_video():
- # 獲取登入信息
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- return render_template('video.html', params=locals())
- else:
- return render_template('sign_in.html')
- @main.route('/sitemap')
- def sitemap():
- if request.method == 'GET':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- print('username: ', username)
- print('status: ', status)
- if status == 9:
- return render_template('signin_disable.html', **locals())
- elif status == 8:
- return render_template('signin_new.html', **locals())
- return render_template('sitemap.html', **locals())
- else:
- return render_template('sign_in.html')
- @main.route('/index_navbar', methods=['GET'])
- def index_navbar():
- return render_template('index_navbar.html')
- @main.route('/camera_dry', methods=['GET', 'POST'])
- def camera_dry():
- if request.method == 'GET':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- return render_template('camera_dry.html', title='乾燥貨櫃攝影機', **locals())
- else:
- return render_template('sign_in.html')
- @main.route('/camera_ferment', methods=['GET', 'POST'])
- def camera_ferment():
- if request.method == 'GET':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- return render_template('camera_ferment.html', title='發酵貨櫃攝影機', **locals())
- else:
- return render_template('sign_in.html')
-
- @main.route('/camera_clean', methods=['GET', 'POST'])
- def camera_clean():
- if request.method == 'GET':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- return render_template('camera_clean.html', title='清洗貨櫃攝影機', **locals())
- else:
- return render_template('sign_in.html')
- @main.route('/camera_dry_1', methods=['GET', 'POST'])
- def camera_dry_2():
- if request.method == 'GET':
- return render_template('camera_dry_1.html', title='乾燥貨櫃攝影機', **locals())
- @main.route('/camera_<tid>', methods=['GET', 'POST'])
- def camera(tid):
- if request.method == 'GET':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- if tid == 'CCargo_in':
- WS_URL = 'ws:///60.250.156.230:1111'
- camera_title = '清洗貨櫃內部'
- return render_template('camera.html', title='[畫面]' + camera_title, **locals())
- elif tid == 'CCargo_out':
- WS_URL = 'ws:///60.250.156.230:1111'
- camera_title = '清洗貨櫃外部'
- return render_template('camera.html', title='[畫面]' + camera_title, **locals())
- elif tid == 'FCargo_in':
- WS_URL = 'ws:///60.250.156.230:1111'
- camera_title = '發酵貨櫃內部'
- return render_template('camera.html', title='[畫面]' + camera_title, **locals())
- elif tid == 'FCargo_out':
- WS_URL = 'ws:///60.250.156.230:1111'
- camera_title = '發酵貨櫃外部'
- return render_template('camera.html', title='[畫面]' + camera_title, **locals())
- elif tid == 'DCargo_in':
- WS_URL = 'ws:///60.250.156.230:1111'
- camera_title = '乾燥貨櫃內部'
- return render_template('camera.html', title='[畫面]' + camera_title, **locals())
- elif tid == 'DCargo_out':
- WS_URL = 'ws:///60.250.156.230:1111'
- camera_title = '乾燥貨櫃外部'
- return render_template('camera.html', title='[畫面]' + camera_title, **locals())
- elif tid[:2] == 'DO':
- WS_URL_list = ['ws:///60.250.156.230:1111',
- 'ws:///60.250.156.230:2222'
- ]
- WS_URL = WS_URL_list[int(tid[2:])-1]
- camera_title = '乾燥出料儲豆槽'
- return render_template('camera.html', title='[畫面]' + camera_title + ' ' + tid, **locals())
- elif tid[:2] == 'DI':
- WS_URL_list = ['ws:///60.250.156.230:1111',
- 'ws:///60.250.156.230:2222'
- ]
- WS_URL = WS_URL_list[int(tid[2:])-1]
- camera_title = '乾燥入料儲豆槽'
- return render_template('camera.html', title='[畫面]' + camera_title + ' ' + tid, **locals())
- elif tid[:1] == 'D':
- WS_URL_list = ['ws:///60.250.156.230:8093', # D1 攝影機已安裝
- 'ws:///60.250.156.230:2222',
- 'ws:///60.250.156.230:3333',
- 'ws:///60.250.156.230:4444',
- 'ws:///60.250.156.230:5555',
- 'ws:///60.250.156.230:6666',
- 'ws:///60.250.156.230:7777',
- 'ws:///60.250.156.230:8888',
- 'ws:///60.250.156.230:9999',
- 'ws:///60.250.156.230:1010',
- 'ws:///60.250.156.230:1111',
- 'ws:///60.250.156.230:1212'
- ]
- WS_URL = WS_URL_list[int(tid[1:])-1]
- camera_title = '乾燥槽'
- return render_template('camera.html', title='[畫面]' + camera_title + ' ' + tid, **locals())
- elif tid[:2] == 'FO':
- WS_URL_list = ['ws:///60.250.156.230:1111',
- 'ws:///60.250.156.230:2222'
- ]
- WS_URL = WS_URL_list[int(tid[2:])-1]
- camera_title = '發酵出料儲豆槽'
- return render_template('camera.html', title='[畫面]' + camera_title + ' ' + tid, **locals())
- elif tid[:2] == 'FI':
- WS_URL_list = ['ws:///60.250.156.230:1111',
- 'ws:///60.250.156.230:2222'
- ]
- WS_URL = WS_URL_list[int(tid[2:])-1]
- camera_title = '發酵入料儲豆槽'
- return render_template('camera.html', title='[畫面]' + camera_title + ' ' + tid, **locals())
- elif tid[:1] == 'F':
- WS_URL_list = ['ws:///60.250.156.230:8089', # F1 攝影機已安裝
- 'ws:///60.250.156.230:2222',
- 'ws:///60.250.156.230:3333',
- 'ws:///60.250.156.230:4444',
- 'ws:///60.250.156.230:5555',
- 'ws:///60.250.156.230:6666',
- 'ws:///60.250.156.230:7777',
- 'ws:///60.250.156.230:8888',
- 'ws:///60.250.156.230:9999',
- 'ws:///60.250.156.230:1010',
- 'ws:///60.250.156.230:1111',
- 'ws:///60.250.156.230:1212'
- ]
- WS_URL = WS_URL_list[int(tid[1:])-1]
- camera_title = '發酵槽'
- return render_template('camera.html', title='[畫面]' + camera_title + ' ' + tid, **locals())
- elif tid[:2] == 'CO':
- WS_URL_list = ['ws:///60.250.156.230:1111',
- 'ws:///60.250.156.230:2222'
- ]
- WS_URL = WS_URL_list[int(tid[2:])-1]
- camera_title = '清洗浮選出料儲豆槽'
- return render_template('camera.html', title='[畫面]' + camera_title + ' ' + tid, **locals())
- elif tid[:1] == 'C':
- WS_URL_list = ['ws:///60.250.156.230:8088', # C1 攝影機已安裝
- 'ws:///60.250.156.230:2222'
- ]
- WS_URL = WS_URL_list[int(tid[1:])-1]
- camera_title = '清洗浮選槽'
- return render_template('camera.html', title='[畫面]' + camera_title + ' ' + tid, **locals())
- elif tid[:2] == 'SO':
- WS_URL_list = ['ws:///60.250.156.230:1111',
- 'ws:///60.250.156.230:2222'
- ]
- WS_URL = WS_URL_list[int(tid[2:])-1]
- camera_title = '色選機出料儲豆槽'
- return render_template('camera.html', title='[畫面]' + camera_title + ' ' + tid, **locals())
- elif tid[:1] == 'S':
- WS_URL_list = ['ws:///60.250.156.230:1111',
- 'ws:///60.250.156.230:2222'
- ]
- WS_URL = WS_URL_list[int(tid[1:])-1]
- camera_title = '色選機'
- return render_template('camera.html', title='[畫面]' + camera_title + ' ' + tid, **locals())
- elif tid[:2] == 'PO':
- WS_URL_list = ['ws:///60.250.156.230:1111',
- 'ws:///60.250.156.230:2222'
- ]
- WS_URL = WS_URL_list[int(tid[2:])-1]
- camera_title = '脫皮機出料儲豆槽'
- return render_template('camera.html', title='[畫面]' + camera_title + ' ' + tid, **locals())
- elif tid[:1] == 'P':
- WS_URL_list = ['ws:///60.250.156.230:1111',
- 'ws:///60.250.156.230:2222'
- ]
- WS_URL = WS_URL_list[int(tid[1:])-1]
- camera_title = '脫皮機'
- return render_template('camera.html', title='[畫面]' + camera_title + ' ' + tid, **locals())
- else:
- return render_template('sign_in.html')
- else:
- pass
- @main.route('/dry_SHT11_<dtid>', methods=['GET', 'POST'])
- def dry_SHT11(dtid):
- if request.method == 'GET':
- tank_Soil = dry_tank_Soil.query.filter_by(tank_num='D' + dtid).order_by(text('datetime desc')).first()
- tank_SHT11 = dry_tank_SHT11.query.filter_by(tank_num='D' + dtid).order_by(text('datetime desc')).first()
- SHT11_Temp = tank_SHT11.SHT11_Temp
- SHT11_Humidity = tank_SHT11.SHT11_Humidity
- Soil_Temp = tank_Soil.soil_Temp
- return jsonify({"SHT11_Temp":SHT11_Temp,
- "SHT11_Humidity":SHT11_Humidity,
- "Soil_Temp":Soil_Temp
- })
- else:
- pass
- @main.route('/dry_UltraSonic_<dtid>', methods=['GET', 'POST'])
- def dry_UltraSonic(dtid):
- if request.method == 'GET':
- tank_UltraSonic = dry_tank_UltraSonic.query.filter_by(tank_num='D' + dtid).order_by(text('datetime desc')).first()
- UltraSonic = tank_UltraSonic.UltraSonic
- return jsonify({"UltraSonic":UltraSonic
- })
- else:
- pass
- @main.route('/dry_input_UltraSonic_<dtid>', methods=['GET', 'POST'])
- def dry_input_UltraSonic(dtid):
- if request.method == 'GET':
- input_UltraSonic = dry_input_sensor.query.filter_by(tank_num='DI' + dtid).order_by(text('datetime desc')).first()
- UltraSonic = input_UltraSonic.UltraSonic
- return jsonify({"UltraSonic":UltraSonic
- })
- else:
- pass
- @main.route('/dry_output_UltraSonic_<dtid>', methods=['GET', 'POST'])
- def dry_output_UltraSonic(dtid):
- if request.method == 'GET':
- output_UltraSonic = dry_output_sensor.query.filter_by(tank_num='DO' + dtid).order_by(text('datetime desc')).first()
- UltraSonic = output_UltraSonic.UltraSonic
- return jsonify({"UltraSonic":UltraSonic
- })
- else:
- pass
- @main.route('/ferment_SHT11_<ftid>', methods=['GET', 'POST'])
- def ferment_SHT11(ftid):
- if request.method == 'GET':
- tank_SHT11 = ferment_tank_SHT11.query.filter_by(tank_num='F' + ftid).order_by(text('datetime desc')).first()
- SHT11_Temp = tank_SHT11.SHT11_Temp
- return jsonify({"SHT11_Temp":SHT11_Temp
- })
- else:
- pass
- @main.route('/ferment_WaterLevel_<ftid>', methods=['GET', 'POST'])
- def ferment_WaterLevel(ftid):
- if request.method == 'GET':
- tank_WaterLevel = ferment_tank_WaterLevel.query.filter_by(tank_num='F' + ftid).order_by(text('datetime desc')).first()
- WaterLevel = tank_WaterLevel.WaterLevel
- return jsonify({"WaterLevel":WaterLevel
- })
- else:
- pass
-
- @main.route('/ferment_WaterIn_<ftid>', methods=['GET', 'POST'])
- def ferment_WaterIn(ftid):
- if request.method == 'GET':
- tank_UltraSonic = ferment_tank_UltraSonic.query.filter_by(tank_num='F' + ftid).order_by(text('datetime desc')).first()
- UltraSonic = (float(tank_UltraSonic.UltraSonic))
- # tank_PressureWaterLevel = ferment_tank_PressureWaterLevel.query.filter_by(tank_num='F' + ftid).order_by(text('datetime desc')).first()
- # PressureWaterLevel = '{:.2f}'.format((float(tank_PressureWaterLevel.PressureWaterLevel) -15 -90.278)/9.4214)
- tank_WaterLevel = ferment_tank_WaterLevel.query.filter_by(tank_num='F' + ftid).order_by(text('datetime desc')).first()
- WaterLevel = tank_WaterLevel.WaterLevel
- return jsonify({"UltraSonic":UltraSonic,
- "WaterLevel":WaterLevel
- })
- else:
- pass
- @main.route('/ferment_UltraSonic_<ftid>', methods=['GET', 'POST'])
- def ferment_UltraSonic(ftid):
- if request.method == 'GET':
- tank_UltraSonic = ferment_tank_UltraSonic.query.filter_by(tank_num='F' + ftid).order_by(text('datetime desc')).first()
- UltraSonic = (float(tank_UltraSonic.UltraSonic))
- return jsonify({"UltraSonic":UltraSonic
- })
- else:
- pass
- '''
- @main.route('/ferment_LiDAR_<ftid>', methods=['GET', 'POST'])
- def ferment_LiDAR(ftid):
- if request.method == 'GET':
- tank_LiDAR = ferment_tank_LiDAR.query.filter_by(tank_num='F' + ftid).order_by(text('datetime desc')).first()
- LiDAR = tank_LiDAR.LiDAR
- return jsonify({"LiDAR":LiDAR
- })
- else:
- pass
- '''
- @main.route('/ferment_input_UltraSonic_<ftid>', methods=['GET', 'POST'])
- def ferment_input_UltraSonic_(ftid):
- if request.method == 'GET':
- input_UltraSonic = ferment_input_UltraSonic.query.filter_by(tank_num='FI' + ftid).order_by(text('datetime desc')).first()
- UltraSonic = input_UltraSonic.UltraSonic
- return jsonify({"UltraSonic":UltraSonic
- })
- else:
- pass
-
- @main.route('/ferment_output_UltraSonic_<ftid>', methods=['GET', 'POST'])
- def ferment_output_UltraSonic_(ftid):
- if request.method == 'GET':
- output_UltraSonic = ferment_output_UltraSonic.query.filter_by(tank_num='FO' + ftid).order_by(text('datetime desc')).first()
- UltraSonic = output_UltraSonic.UltraSonic
- return jsonify({"UltraSonic":UltraSonic
- })
- else:
- pass
- @main.route('/ferment_watertesting_<tid>', methods=['GET', 'POST'])
- def ferment_watertesting(tid):
- if request.method == 'GET':
- tank_PH = ferment_tank_PH.query.filter_by(tank_num='F' + tid).order_by(text('datetime desc')).first()
- tank_ORP = ferment_tank_ORP.query.filter_by(tank_num='F' + tid).order_by(text('datetime desc')).first()
- tank_DO = ferment_tank_DO.query.filter_by(tank_num='F' + tid).order_by(text('datetime desc')).first()
- tank_EC = ferment_tank_EC.query.filter_by(tank_num='F' + tid).order_by(text('datetime desc')).first()
- PH = tank_PH.PH
- ORP = tank_ORP.ORP
- DO = tank_DO.DO
- EC = tank_EC.EC
- return jsonify({"PH":PH,
- "ORP":ORP,
- "DO":DO,
- "EC":EC,
- })
- '''
- @main.route('/ferment_PressureWaterLevel_<ftid>', methods=['GET', 'POST'])
- def ferment_PressureWaterLevel(ftid):
- if request.method == 'GET':
- tank_PressureWaterLevel = ferment_tank_PressureWaterLevel.query.filter_by(tank_num='F' + ftid).order_by(text('datetime desc')).first()
- PressureWaterLevel = float(tank_PressureWaterLevel.PressureWaterLevel)
- #PressureWaterLevel = '{:.2f}'.format((float(tank_PressureWaterLevel.PressureWaterLevel) -15 -90.278)/9.4214)
- print("PressureWaterLevel_start: ", PressureWaterLevel)
- return jsonify({"PressureWaterLevel":PressureWaterLevel
- })
- # 此段刪除
- while int(PressureWaterLevel) < int(testing_water_height):
- tank_water_status = 'NO'
- time.sleep(3)
- # print(ferment_water_height(testing_water_height))
- # [目前桶內水位高度]發酵槽_感測器_壓力式水位計
- tank_PressureWaterLevel = ferment_tank_PressureWaterLevel.query.filter_by(tank_num='F1').order_by(text('datetime desc')).first()
- PressureWaterLevel = tank_PressureWaterLevel.PressureWaterLevel
- print("-- MySQL --")
- print("tank_PressureWaterLevel: ", tank_PressureWaterLevel)
- # tank_water_height()
- # print("PressureWaterLevel_while: ", PressureWaterLevel)
- ferment_water_height(testing_water_height)
- return jsonify({"testing_water_height":testing_water_height,
- "tank_water_status":tank_water_status
- })
- else:
- tank_water_status = 'OK'
- print("PressureWaterLevel_else: ", PressureWaterLevel)
- return jsonify({"testing_water_height":testing_water_height,
- "tank_water_status":tank_water_status
- })
- '''
- '''
- def tank_water_height():
- tank_PressureWaterLevel = ferment_tank_PressureWaterLevel.query.filter_by(tank_num='F1').order_by(text('datetime desc')).first()
- PressureWaterLevel = tank_PressureWaterLevel.PressureWaterLevel
- print("tank_water_height", PressureWaterLevel)
- return PressureWaterLevel
- '''
- @main.route('/loading/SO<sotid>', methods=['GET', 'POST'])
- def SO_loading(sotid):
- if request.method == 'GET':
- # 致動器_脫皮機_ALL
- output_actuator = colorselect_output_actuator.query.filter_by(tank_num='SO'+sotid).order_by(text('datetime desc')).first()
- output_vacuum = output_actuator.vacuum
- return jsonify({"output_vacuum":output_vacuum
- })
- else:
- pass
- @main.route('/loading/S<stid>', methods=['GET', 'POST'])
- def S_loading(stid):
- if request.method == 'GET':
- # 色選機
- return
- else:
- pass
- @main.route('/loading/PO<potid>', methods=['GET', 'POST'])
- def PO_loading(potid):
- if request.method == 'GET':
- # 致動器_脫皮機_ALL
- output_actuator = peel_output_actuator.query.filter_by(tank_num='PO'+potid).order_by(text('datetime desc')).first()
- output_vacuum = output_actuator.vacuum
- return jsonify({"output_vacuum":output_vacuum
- })
- else:
- pass
- @main.route('/loading/P<ptid>', methods=['GET', 'POST'])
- def P_loading(ptid):
- if request.method == 'GET':
- # 致動器_脫皮機_ALL
- tank_actuator = peel_tank_actuator.query.filter_by(tank_num='P'+ptid).order_by(text('datetime desc')).first()
- tank_vacuum = tank_actuator.vacuum
- tank_motor = tank_actuator.motor
- return jsonify({"tank_vacuum":tank_vacuum,
- "tank_motor":tank_motor})
- else:
- pass
- @main.route('/loading/CO<cotid>', methods=['GET', 'POST'])
- def CO_loading(cotid):
- if request.method == 'GET':
- output_actuator = clean_output_actuator.query.filter_by(tank_num='CO'+cotid).order_by(text('datetime desc')).first()
- output_vacuum = output_actuator.vacuum
- return jsonify({"output_vacuum":output_vacuum
- })
- else:
- pass
- @main.route('/loading/C<ctid>', methods=['GET', 'POST'])
- def C_loading(ctid):
- if request.method == 'GET':
- # 致動器_浮選清洗_ALL
- tank_actuator = clean_tank_actuator.query.filter_by(tank_num='C'+ctid).order_by(text('datetime desc')).first()
- tank_vacuum = tank_actuator.vacuum
- tank_pump_waterInput = tank_actuator.pump_waterInput
- tank_pump_waterL2L3 = tank_actuator.pump_waterL2L3
- tank_pump_waterL4L5 = tank_actuator.pump_waterL4L5
- tank_solenoid_waterL2L3 = tank_actuator.solenoid_waterL2L3
- tank_solenoid_waterL4L5 = tank_actuator.solenoid_waterL4L5
- tank_stepping_motor = tank_actuator.stepping_motor
- print('tank_stepping_motor:', tank_stepping_motor)
- # 感測器_浮選清洗_超音波感測器
- tank_UltraSonic = clean_tank_UltraSonic.query.filter_by(tank_num='C'+ctid).order_by(text('datetime desc')).first()
- UltraSonic= tank_UltraSonic.UltraSonic
- return jsonify({"UltraSonic":UltraSonic,
- "tank_vacuum":tank_vacuum,
- "tank_pump_waterInput":tank_pump_waterInput,
- "tank_pump_waterL2L3":tank_pump_waterL2L3,
- "tank_pump_waterL4L5":tank_pump_waterL4L5,
- "tank_solenoid_waterL2L3":tank_solenoid_waterL2L3,
- "tank_solenoid_waterL4L5":tank_solenoid_waterL4L5,
- "tank_stepping_motor":tank_stepping_motor
- })
- else:
- pass
- @main.route('/loading/F<ftid>', methods=['GET', 'POST'])
- def F_loading(ftid):
- if request.method == 'GET':
- # 致動器_發酵槽_ALL
- tank_actuator = ferment_tank_actuator.query.filter_by(tank_num='F'+ftid).order_by(text('datetime desc')).first()
- tank_vacuum = tank_actuator.vacuum
- tank_threewayvalve_input = tank_actuator.threewayvalve_input
- tank_diskvalve = tank_actuator.diskvalve
- solenoid_tank_pump = tank_actuator.solenoid_tank_pump
- tank_solenoid_disinfect = tank_actuator.solenoid_tank_disinfect
- outer_solenoid_water = tank_actuator.solenoid_outer_water
- tank_solenoid_water_in = tank_actuator.solenoid_tank_water_in
- tank_solenoid_water_out = tank_actuator.solenoid_tank_water_out
- tank_pump_sensor = tank_actuator.pump_sensor
- outer_threewayvalve_float = tank_actuator.threewayvalve_outer_float
- tank_motor = tank_actuator.motor
- tank_heater1 = tank_actuator.heater1
- tank_heater2 = tank_actuator.heater2
- tank_temp_enable = tank_actuator.temp_enable
- tank_temp = tank_actuator.temp
- # 感測器_發酵桶_SHT11
- tank_SHT11 = ferment_tank_SHT11.query.filter_by(tank_num='F'+ftid).order_by(text('datetime desc')).first()
- SHT11_Temp = float(tank_SHT11.SHT11_Temp)
- SHT11_Humidity = float(tank_SHT11.SHT11_Humidity)
- # 感測器_發酵桶_二氧化碳
- tank_CO2 = ferment_tank_CO2.query.filter_by(tank_num='F'+ftid).order_by(text('datetime desc')).first()
- CO2 = float(tank_CO2.CO2)
- # 感測器_發酵桶_酸鹼值
- tank_PH = ferment_tank_PH.query.filter_by(tank_num='F'+ftid).order_by(text('datetime desc')).first()
- tank_ORP = ferment_tank_ORP.query.filter_by(tank_num='F'+ftid).order_by(text('datetime desc')).first()
- tank_DO = ferment_tank_DO.query.filter_by(tank_num='F'+ftid).order_by(text('datetime desc')).first()
- tank_EC = ferment_tank_EC.query.filter_by(tank_num='F'+ftid).order_by(text('datetime desc')).first()
- PH = float(tank_PH.PH)
- ORP = float(tank_ORP.ORP)
- DO = float(tank_DO.DO)
- EC = float(tank_EC.EC)
- # 感測器_發酵桶_氣壓
- tank_PA = ferment_tank_PA.query.filter_by(tank_num='F'+ftid).order_by(text('datetime desc')).first()
- PA = float(tank_PA.PA)
- # 感測器_發酵桶_超音波感測器
- tank_UltraSonic = ferment_tank_UltraSonic.query.filter_by(tank_num='F'+ftid).order_by(text('datetime desc')).first()
- UltraSonic= (float(tank_UltraSonic.UltraSonic))
- # 感測器_發酵桶_保溫夾層水位計
- tank_WaterLevel = ferment_tank_WaterLevel.query.filter_by(tank_num='F'+ftid).order_by(text('datetime desc')).first()
- WaterLevel = tank_WaterLevel.WaterLevel
- # 感測器_發酵桶_咖啡生豆高度
- # tank_LiDAR = ferment_tank_LiDAR.query.filter_by(tank_num='F'+ftid).order_by(text('datetime desc')).first()
- # LiDAR = tank_LiDAR.LiDAR
- # 感測器_發酵桶_水位高度
- # tank_PressureWaterLevel = ferment_tank_PressureWaterLevel.query.filter_by(tank_num='F'+ftid).order_by(text('datetime desc')).first()
- # PressureWaterLevel = '{:.2f}'.format((float(tank_PressureWaterLevel.PressureWaterLevel) -15 -90.278)/9.4214)
- return jsonify({"SHT11_Temp": SHT11_Temp,
- "SHT11_Humidity":SHT11_Humidity,
- "CO2":CO2,
- "PH":PH,
- "ORP":ORP,
- "DO":DO,
- "EC":EC,
- "PA":PA,
- "WaterLevel":WaterLevel,
- "UltraSonic":UltraSonic,
-
- "tank_vacuum":tank_vacuum,
- "tank_threewayvalve_input":tank_threewayvalve_input,
- "tank_diskvalve":tank_diskvalve,
- "solenoid_tank_pump":solenoid_tank_pump,
- "tank_solenoid_disinfect":tank_solenoid_disinfect,
- "outer_solenoid_water":outer_solenoid_water,
- "tank_solenoid_water_in":tank_solenoid_water_in,
- "tank_solenoid_water_out":tank_solenoid_water_out,
- "tank_pump_sensor":tank_pump_sensor,
- "outer_threewayvalve_float":outer_threewayvalve_float,
- "tank_motor":tank_motor,
- "tank_heater1":tank_heater1,
- "tank_heater2":tank_heater2,
- "tank_temp_enable":tank_temp_enable,
- "tank_temp":tank_temp
- })
- else:
- pass
-
- @main.route('/loading/FI<fitid>', methods=['GET', 'POST'])
- def FI_loading(fitid):
- if request.method == 'GET':
- input_actuator = ferment_input_actuator.query.filter_by(tank_num='F'+fitid).order_by(text('datetime desc')).first()
- input_vacuum = input_actuator.vacuum
- input_sensor = ferment_input_UltraSonic.query.filter_by(tank_num='F'+fitid).order_by(text('datetime desc')).first()
- # input_UltraSonic = float("{:.2f}".format(34.6 - float(input_sensor.UltraSonic)))
- input_UltraSonic = float(input_sensor.UltraSonic)
- return jsonify({"input_UltraSonic":input_UltraSonic,
- "input_vacuum":input_vacuum
- })
- else:
- pass
- @main.route('/loading/FO<fotid>', methods=['GET', 'POST'])
- def FO_loading(fotid):
- if request.method == 'GET':
- output_actuator = ferment_output_actuator.query.filter_by(tank_num='FO'+fotid).order_by(text('datetime desc')).first()
- output_vacuum = output_actuator.vacuum
- output_sensor = ferment_output_UltraSonic.query.filter_by(tank_num='FO'+fotid).order_by(text('datetime desc')).first()
- output_UltraSonic = output_sensor.UltraSonic
- tank_LiDAR = ferment_tank_LiDAR.query.filter_by(tank_num='F'+fotid).order_by(text('datetime desc')).first()
- LiDAR = tank_LiDAR.LiDAR
- return jsonify({"output_UltraSonic":output_UltraSonic,
- "output_vacuum":output_vacuum,
- "LiDAR":LiDAR
- })
- else:
- pass
- @main.route('/loading/DI<ditid>', methods=['GET', 'POST'])
- def DI_loading(ditid):
- if request.method == 'GET':
- input_actuator = dry_input_brake.query.filter_by(tank_num='DI'+ditid).order_by(text('datetime desc')).first()
- input_vacuum = input_actuator.vacuum
- input_sensor = dry_input_sensor.query.filter_by(tank_num='DI'+ditid).order_by(text('datetime desc')).first()
- input_UltraSonic = input_sensor.UltraSonic
- return jsonify({"input_UltraSonic":input_UltraSonic,
- "input_vacuum":input_vacuum
- })
- else:
- pass
- @main.route('/loading/DO<dotid>', methods=['GET', 'POST'])
- def DO_loading(dotid):
- if request.method == 'GET':
- output_actuator = dry_output_brake.query.filter_by(tank_num='DO'+dotid).order_by(text('datetime desc')).first()
- output_vacuum = output_actuator.vacuum
- output_sensor = dry_output_sensor.query.filter_by(tank_num='DO'+dotid).order_by(text('datetime desc')).first()
- output_UltraSonic = output_sensor.UltraSonic
- return jsonify({"output_vacuum":output_vacuum,
- "output_UltraSonic":output_UltraSonic
- })
- else:
- pass
- @main.route('/loading/D<dtid>', methods=['GET', 'POST'])
- def D_loading(dtid):
- if request.method == 'GET':
- # 感測器_乾燥桶_超音波感測器
- tank_UltraSonic = dry_tank_UltraSonic.query.filter_by(tank_num="D"+dtid).order_by(text('datetime desc')).first()
- UltraSonic = tank_UltraSonic.UltraSonic
- # 感測器_乾燥桶_SHT11
- tank_SHT11 = dry_tank_SHT11.query.filter_by(tank_num="D"+dtid).order_by(text('datetime desc')).first()
- SHT11_Temp = tank_SHT11.SHT11_Temp
- SHT11_Humidity = tank_SHT11.SHT11_Humidity
- # 感測器_乾燥桶_土壤三合一
- tank_Soil = dry_tank_Soil.query.filter_by(tank_num="D"+dtid).order_by(text('datetime desc')).first()
- soil_Temp = tank_Soil.soil_Temp
- soil_Humidity = tank_Soil.soil_Humidity
- soil_EC = tank_Soil.soil_EC
- # 感測器_乾燥桶_氣壓
- tank_PA = dry_tank_PA.query.filter_by(tank_num="D"+dtid).order_by(text('datetime desc')).first()
- PA = tank_PA.PA
- # 致動器_乾燥桶_ALL
- tank_brake = dry_tank_brake.query.filter_by(tank_num="D"+dtid).order_by(text('datetime desc')).first()
- # tank_vacuum = 'ON' if i<100 else 2 if i>100 else 0
- tank_vacuum = tank_brake.vacuum
- tank_threewayvalve = tank_brake.threewayvalve
- tank_diskvalve = tank_brake.diskvalve
- tank_solenoid_disinfect = tank_brake.solenoid_disinfect
- tank_solenoid_water = tank_brake.solenoid_water
- tank_motor = tank_brake.motor
- tank_blower = tank_brake.blower
- tank_heater1 = tank_brake.heater1
- tank_heater2 = tank_brake.heater2
- tank_temp1_enable = tank_brake.temp1_enable
- tank_temp1 = tank_brake.temp1
- #return jsonify({"peeling": peeling_rpm})
- '''
- info = psutil.virtual_memory()
- print('記憶體使用: ', psutil.Process(os.getpid()).memory_info().rss)
- # print('總記憶體: ', info.total)
- print('記憶體占比: ', info.percent)
- print('cpu 個數: ', psutil.cpu_count())
- '''
- return jsonify({"UltraSonic":UltraSonic,
- "SHT11_Temp": SHT11_Temp,
- "SHT11_Humidity":SHT11_Humidity,
- "soil_Temp":soil_Temp,
- "soil_Humidity":soil_Humidity,
- "soil_EC":soil_EC,
- "PA":PA,
-
- "tank_vacuum":tank_vacuum,
- "tank_threewayvalve":tank_threewayvalve,
- "tank_diskvalve":tank_diskvalve,
- "tank_solenoid_disinfect":tank_solenoid_disinfect,
- "tank_solenoid_water":tank_solenoid_water,
- "tank_motor":tank_motor,
- "tank_blower":tank_blower,
- "tank_heater1":tank_heater1,
- "tank_heater2":tank_heater2,
- "tank_temp1_enable":tank_temp1_enable,
- "tank_temp1":tank_temp1
- })
- else:
- pass
- @main.route('/index_new')
- def index_new():
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', **locals())
- elif status == 8:
- return render_template('signin_new.html', **locals())
- else:
- return render_template('oops.html', **locals())
-
- return render_template('index_new.html', title='Smart Coffee', **locals())
- @main.route('/user/<name>')
- def user(name):
- return render_template('hello.html', name=name)
- '''
- @main.route('/plot.png')
- def plot():
- # 重新整理會有問題
- # 圖的寬和高
- fig = plt.figure()
- # 在圖中新增子圖, 通常多個圖才會用到?
- axis = fig.add_subplot(1, 1, 1)
- # x、 軸資料
- xs = range(100)
- ys = [random.randint(1, 50) for x in xs]
- axis.plot(xs, ys)
- canvas = FigureCanvas(fig)
- output = io.BytesIO()
- canvas.print_png(output)
- response = make_response(output.getvalue())
- response.mimetype = 'image/png'
- return response
- '''
- @main.route('/chart_<tank>/<sensor_name>/<tid>', methods=['GET', 'POST'])
- def chart_D(tank, sensor_name, tid):
- if request.method == 'GET':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- else:
- return render_template('oops.html', params=locals())
-
- if tank == 'DI':
- return render_template('sensor_chart_DI.html', title='[圖表]' + tank + tid + '乾燥入料儲豆槽', **locals())
- elif tank == 'DO':
- return render_template('sensor_chart_DO.html', title='[圖表]' + tank + tid + '乾燥出料儲豆槽', **locals())
- elif tank == 'FI':
- return render_template('sensor_chart_FI.html', title='[圖表]' + tank + tid + '發酵入料儲豆槽', **locals())
- elif tank == 'FO':
- return render_template('sensor_chart_FO.html', title='[圖表]' + tank + tid + '發酵出料儲豆槽', **locals())
- elif tank == 'F':
- return render_template('sensor_chart_F.html', title='[圖表]' + tank + tid + '發酵槽', **locals())
- else:
- return render_template('sensor_chart_D.html', title='[圖表]' + tank + tid + '乾燥槽', **locals())
- elif request.method == 'POST':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', **locals())
- elif status == 8:
- return render_template('signin_new.html', **locals())
- else:
- return render_template('oops.html', **locals())
-
-
- starttime = request.values['sensor_starttime'] # 2021-07-19T09:00
- endtime = request.values['sensor_endtime'] # 2021-07-19T12:00
- sensor_name = request.values['sensors']
- print('sensor_name:', sensor_name)
- # 判斷資料索取區間 起<迄
- if starttime < endtime :
- # print('starttime endtime:', starttime, endtime)
- # print('TF:', starttime<endtime ) # 可以比較 起<迄
- # [html]2021-07-19T09:00 轉換成 [python]datetime.datetime(2021, 7, 19, 9, 0, 0)
- start_YY = starttime[:4] # '2021'
- start_MM = starttime[6:7] if starttime[5:7][:1] == '0' else starttime[5:7] # '07'
- start_DD = starttime[9:10] if starttime[8:10][:1] == '0' else starttime[8:10] # '19'
- start_hh = starttime[12:13] if starttime[11:13][:1] == '0' else starttime[11:13] # '09'
- start_mm = starttime[15:] if starttime[14:][:1] == '0' else starttime[14:] # '00'
- start_ss = 0
- end_YY = endtime[:4] # '2021'
- end_MM = endtime[6:7] if endtime[5:7][:1] == '0' else endtime[5:7] # '07'
- end_DD = endtime[9:10] if endtime[8:10][:1] == '0' else endtime[8:10] # '19'
- end_hh = endtime[12:13] if endtime[11:13][:1] == '0' else endtime[11:13] # '09'
- end_mm = endtime[15:] if endtime[14:][:1] == '0' else endtime[14:] # '00'
- end_ss = 0
- time_range = []
- temp_range = []
- # 拿掉會 Error, 要使用沒有 GUI 的 matplotlib
- plt.switch_backend('agg')
- plt.figure()
- if tank == 'DI':
- print('DI')
- if sensor_name == 'UltraSonic':
- for d in db.session.query(dry_input_sensor) \
- .filter_by(tank_num='DI' + tid) \
- .filter(dt(int(start_YY), int(start_MM), int(start_DD), int(start_hh), int(start_mm), int(start_ss)) < dry_input_sensor.datetime) \
- .filter(dry_input_sensor.datetime < dt(int(end_YY), int(end_MM), int(end_DD), int(end_hh), int(end_mm), int(end_ss))) \
- .order_by(dry_input_sensor.datetime):
- # print('d_test', f'{d.datetime} - {d.SHT11_Temp}')
- time_range.append(str(d.datetime))
- temp_range.append(float(d.UltraSonic))
- print('time_range:', time_range)
- print('temp_range:', temp_range)
- return render_template('sensor_chart_DI.html', **locals())
- elif tank == 'DO':
- print('DO')
- if sensor_name == 'UltraSonic':
- for d in db.session.query(dry_output_sensor) \
- .filter_by(tank_num='DO' + tid) \
- .filter(dt(int(start_YY), int(start_MM), int(start_DD), int(start_hh), int(start_mm), int(start_ss)) < dry_output_sensor.datetime) \
- .filter(dry_output_sensor.datetime < dt(int(end_YY), int(end_MM), int(end_DD), int(end_hh), int(end_mm), int(end_ss))) \
- .order_by(dry_output_sensor.datetime):
- # print('d_test', f'{d.datetime} - {d.SHT11_Temp}')
- time_range.append(str(d.datetime))
- temp_range.append(float(d.UltraSonic))
- print('time_range:', time_range)
- print('temp_range:', temp_range)
- return render_template('sensor_chart_DO.html', **locals())
- elif tank == 'D':
- print('D')
- if sensor_name == 'SHT11_Temp':
- for d in db.session.query(dry_tank_SHT11) \
- .filter_by(tank_num='D' + tid) \
- .filter(dt(int(start_YY), int(start_MM), int(start_DD), int(start_hh), int(start_mm), int(start_ss)) < dry_tank_SHT11.datetime) \
- .filter(dry_tank_SHT11.datetime < dt(int(end_YY), int(end_MM), int(end_DD), int(end_hh), int(end_mm), int(end_ss))) \
- .order_by(dry_tank_SHT11.datetime):
- # print('d_test', f'{d.datetime} - {d.SHT11_Temp}')
- time_range.append(str(d.datetime))
- temp_range.append(float(d.SHT11_Temp))
- # 畫出 x 軸基準線
- # plt.axhline(28.5, color= 'r')
-
- elif sensor_name == 'SHT11_Humidity':
- for d in db.session.query(dry_tank_SHT11) \
- .filter_by(tank_num='D' + tid) \
- .filter(dt(int(start_YY), int(start_MM), int(start_DD), int(start_hh), int(start_mm), int(start_ss)) < dry_tank_SHT11.datetime) \
- .filter(dry_tank_SHT11.datetime < dt(int(end_YY), int(end_MM), int(end_DD), int(end_hh), int(end_mm), int(end_ss))) \
- .order_by(dry_tank_SHT11.datetime):
- # print('d_test', f'{d.datetime} - {d.SHT11_Temp}')
- time_range.append(str(d.datetime))
- temp_range.append(float(d.SHT11_Humidity))
-
- elif sensor_name == 'UltraSonic':
- for d in db.session.query(dry_tank_UltraSonic) \
- .filter_by(tank_num='D' + tid) \
- .filter(dt(int(start_YY), int(start_MM), int(start_DD), int(start_hh), int(start_mm), int(start_ss)) < dry_tank_UltraSonic.datetime) \
- .filter(dry_tank_UltraSonic.datetime < dt(int(end_YY), int(end_MM), int(end_DD), int(end_hh), int(end_mm), int(end_ss))) \
- .order_by(dry_tank_UltraSonic.datetime):
- # print('d_test', f'{d.datetime} - {d.SHT11_Temp}')
- time_range.append(str(d.datetime))
- temp_range.append(float(d.UltraSonic))
-
- elif sensor_name == 'PA':
- for d in db.session.query(dry_tank_PA) \
- .filter_by(tank_num='D' + tid) \
- .filter(dt(int(start_YY), int(start_MM), int(start_DD), int(start_hh), int(start_mm), int(start_ss)) < dry_tank_PA.datetime) \
- .filter(dry_tank_PA.datetime < dt(int(end_YY), int(end_MM), int(end_DD), int(end_hh), int(end_mm), int(end_ss))) \
- .order_by(dry_tank_PA.datetime):
- # print('d_test', f'{d.datetime} - {d.SHT11_Temp}')
- time_range.append(str(d.datetime))
- temp_range.append(float(d.PA))
-
- elif sensor_name == 'soil_Temp':
- for d in db.session.query(dry_tank_Soil) \
- .filter_by(tank_num='D' + tid) \
- .filter(dt(int(start_YY), int(start_MM), int(start_DD), int(start_hh), int(start_mm), int(start_ss)) < dry_tank_Soil.datetime) \
- .filter(dry_tank_Soil.datetime < dt(int(end_YY), int(end_MM), int(end_DD), int(end_hh), int(end_mm), int(end_ss))) \
- .order_by(dry_tank_Soil.datetime):
- # print('d_test', f'{d.datetime} - {d.SHT11_Temp}')
- time_range.append(str(d.datetime))
- temp_range.append(float(d.soil_Temp))
- # 畫出 x 軸基準線
- plt.axhline(28.5, color= 'r')
- elif sensor_name == 'soil_Humidity':
- for d in db.session.query(dry_tank_Soil) \
- .filter_by(tank_num='D' + tid) \
- .filter(dt(int(start_YY), int(start_MM), int(start_DD), int(start_hh), int(start_mm), int(start_ss)) < dry_tank_Soil.datetime) \
- .filter(dry_tank_Soil.datetime < dt(int(end_YY), int(end_MM), int(end_DD), int(end_hh), int(end_mm), int(end_ss))) \
- .order_by(dry_tank_Soil.datetime):
- # print('d_test', f'{d.datetime} - {d.SHT11_Temp}')
- time_range.append(str(d.datetime))
- temp_range.append(float(d.soil_Humidity))
-
- elif sensor_name == 'soil_EC':
- for d in db.session.query(dry_tank_Soil) \
- .filter_by(tank_num='D' + tid) \
- .filter(dt(int(start_YY), int(start_MM), int(start_DD), int(start_hh), int(start_mm), int(start_ss)) < dry_tank_Soil.datetime) \
- .filter(dry_tank_Soil.datetime < dt(int(end_YY), int(end_MM), int(end_DD), int(end_hh), int(end_mm), int(end_ss))) \
- .order_by(dry_tank_Soil.datetime):
- # print('d_test', f'{d.datetime} - {d.SHT11_Temp}')
- time_range.append(str(d.datetime))
- temp_range.append(float(d.soil_EC))
- print('time_range:', time_range)
- print('temp_range:', temp_range)
- return render_template('sensor_chart_D.html', **locals())
- elif tank == 'FI':
- print('FI')
- if sensor_name == 'UltraSonic':
- for d in db.session.query(ferment_input_UltraSonic) \
- .filter_by(tank_num='FI' + tid) \
- .filter(dt(int(start_YY), int(start_MM), int(start_DD), int(start_hh), int(start_mm), int(start_ss)) < ferment_input_UltraSonic.datetime) \
- .filter(ferment_input_UltraSonic.datetime < dt(int(end_YY), int(end_MM), int(end_DD), int(end_hh), int(end_mm), int(end_ss))) \
- .order_by(ferment_input_UltraSonic.datetime):
- # print('d_test', f'{d.datetime} - {d.SHT11_Temp}')
- time_range.append(str(d.datetime))
- temp_range.append(float(d.UltraSonic))
- print('time_range:', time_range)
- print('temp_range:', temp_range)
- return render_template('sensor_chart_FI.html', **locals())
- elif tank == 'FO':
- print('FO')
- if sensor_name == 'UltraSonic':
- for d in db.session.query(ferment_output_UltraSonic) \
- .filter_by(tank_num='FO' + tid) \
- .filter(dt(int(start_YY), int(start_MM), int(start_DD), int(start_hh), int(start_mm), int(start_ss)) < ferment_output_UltraSonic.datetime) \
- .filter(ferment_output_UltraSonic.datetime < dt(int(end_YY), int(end_MM), int(end_DD), int(end_hh), int(end_mm), int(end_ss))) \
- .order_by(ferment_output_UltraSonic.datetime):
- # print('d_test', f'{d.datetime} - {d.SHT11_Temp}')
- time_range.append(str(d.datetime))
- temp_range.append(float(d.UltraSonic))
- print('time_range:', time_range)
- print('temp_range:', temp_range)
- return render_template('sensor_chart_FO.html', **locals())
- elif tank == 'F':
- print('F')
- if sensor_name == 'LiDAR':
- for d in db.session.query(ferment_tank_LiDAR) \
- .filter_by(tank_num='F' + tid) \
- .filter(dt(int(start_YY), int(start_MM), int(start_DD), int(start_hh), int(start_mm), int(start_ss)) < ferment_tank_LiDAR.datetime) \
- .filter(ferment_tank_LiDAR.datetime < dt(int(end_YY), int(end_MM), int(end_DD), int(end_hh), int(end_mm), int(end_ss))) \
- .order_by(ferment_tank_LiDAR.datetime):
- time_range.append(str(d.datetime))
- temp_range.append(float(d.LiDAR))
- elif sensor_name == 'PressureWaterLevel':
- for d in db.session.query(ferment_tank_PressureWaterLevel) \
- .filter_by(tank_num='F' + tid) \
- .filter(dt(int(start_YY), int(start_MM), int(start_DD), int(start_hh), int(start_mm), int(start_ss)) < ferment_tank_PressureWaterLevel.datetime) \
- .filter(ferment_tank_PressureWaterLevel.datetime < dt(int(end_YY), int(end_MM), int(end_DD), int(end_hh), int(end_mm), int(end_ss))) \
- .order_by(ferment_tank_PressureWaterLevel.datetime):
- time_range.append(str(d.datetime))
- temp_range.append('{:.2f}'.format((float(d.PressureWaterLevel) -10 -90.278)/9.4214))
- elif sensor_name == 'SHT11_Temp':
- for d in db.session.query(ferment_tank_SHT11) \
- .filter_by(tank_num='F' + tid) \
- .filter(dt(int(start_YY), int(start_MM), int(start_DD), int(start_hh), int(start_mm), int(start_ss)) < ferment_tank_PressureWaterLevel.datetime) \
- .filter(ferment_tank_SHT11.datetime < dt(int(end_YY), int(end_MM), int(end_DD), int(end_hh), int(end_mm), int(end_ss))) \
- .order_by(ferment_tank_SHT11.datetime):
- time_range.append(str(d.datetime))
- temp_range.append(float(d.SHT11_Temp))
- elif sensor_name == 'SHT11_Humidity':
- for d in db.session.query(ferment_tank_SHT11) \
- .filter_by(tank_num='F' + tid) \
- .filter(dt(int(start_YY), int(start_MM), int(start_DD), int(start_hh), int(start_mm), int(start_ss)) < ferment_tank_SHT11.datetime) \
- .filter(ferment_tank_SHT11.datetime < dt(int(end_YY), int(end_MM), int(end_DD), int(end_hh), int(end_mm), int(end_ss))) \
- .order_by(ferment_tank_SHT11.datetime):
- time_range.append(str(d.datetime))
- temp_range.append(float(d.SHT11_Humidity))
- elif sensor_name == 'CO2':
- for d in db.session.query(ferment_tank_CO2) \
- .filter_by(tank_num='F' + tid) \
- .filter(dt(int(start_YY), int(start_MM), int(start_DD), int(start_hh), int(start_mm), int(start_ss)) < ferment_tank_CO2.datetime) \
- .filter(ferment_tank_CO2.datetime < dt(int(end_YY), int(end_MM), int(end_DD), int(end_hh), int(end_mm), int(end_ss))) \
- .order_by(ferment_tank_CO2.datetime):
- time_range.append(str(d.datetime))
- temp_range.append(float(d.CO2))
- elif sensor_name == 'PH':
- for d in db.session.query(ferment_tank_PH) \
- .filter_by(tank_num='F' + tid) \
- .filter(dt(int(start_YY), int(start_MM), int(start_DD), int(start_hh), int(start_mm), int(start_ss)) < ferment_tank_PH.datetime) \
- .filter(ferment_tank_PH.datetime < dt(int(end_YY), int(end_MM), int(end_DD), int(end_hh), int(end_mm), int(end_ss))) \
- .order_by(ferment_tank_PH.datetime):
- time_range.append(str(d.datetime))
- temp_range.append(float(d.PH))
- elif sensor_name == 'ORP':
- for d in db.session.query(ferment_tank_ORP) \
- .filter_by(tank_num='F' + tid) \
- .filter(dt(int(start_YY), int(start_MM), int(start_DD), int(start_hh), int(start_mm), int(start_ss)) < ferment_tank_ORP.datetime) \
- .filter(ferment_tank_ORP.datetime < dt(int(end_YY), int(end_MM), int(end_DD), int(end_hh), int(end_mm), int(end_ss))) \
- .order_by(ferment_tank_ORP.datetime):
- time_range.append(str(d.datetime))
- temp_range.append(float(d.ORP))
- elif sensor_name == 'DO':
- for d in db.session.query(ferment_tank_DO) \
- .filter_by(tank_num='F' + tid) \
- .filter(dt(int(start_YY), int(start_MM), int(start_DD), int(start_hh), int(start_mm), int(start_ss)) < ferment_tank_DO.datetime) \
- .filter(ferment_tank_DO.datetime < dt(int(end_YY), int(end_MM), int(end_DD), int(end_hh), int(end_mm), int(end_ss))) \
- .order_by(ferment_tank_DO.datetime):
- time_range.append(str(d.datetime))
- temp_range.append(float(d.DO))
- elif sensor_name == 'EC':
- for d in db.session.query(ferment_tank_EC) \
- .filter_by(tank_num='F' + tid) \
- .filter(dt(int(start_YY), int(start_MM), int(start_DD), int(start_hh), int(start_mm), int(start_ss)) < ferment_tank_EC.datetime) \
- .filter(ferment_tank_EC.datetime < dt(int(end_YY), int(end_MM), int(end_DD), int(end_hh), int(end_mm), int(end_ss))) \
- .order_by(ferment_tank_EC.datetime):
- time_range.append(str(d.datetime))
- temp_range.append(float(d.EC))
- elif sensor_name == 'PA':
- for d in db.session.query(ferment_tank_PA) \
- .filter_by(tank_num='F' + tid) \
- .filter(dt(int(start_YY), int(start_MM), int(start_DD), int(start_hh), int(start_mm), int(start_ss)) < ferment_tank_PA.datetime) \
- .filter(ferment_tank_PA.datetime < dt(int(end_YY), int(end_MM), int(end_DD), int(end_hh), int(end_mm), int(end_ss))) \
- .order_by(ferment_tank_PA.datetime):
- time_range.append(str(d.datetime))
- temp_range.append(float(d.PA))
-
- print('time_range:', time_range)
- print('temp_range:', temp_range)
- return render_template('sensor_chart_DO.html', **locals())
-
- '''
- # 設定 x 軸資料、y 軸資料、折線顏色
- plt.plot(time_range, temp_range, 'bo')
- # x 軸標題 (中文無法顯示)
- # plt.xlabel('time')
- # plt.ylabel(sensor_name)
- # x 軸 label 和垂直顯示, rotation='vertical'
- plt.xticks(time_range, rotation='vertical' )
- # 設定圖表標題
- plt.title(sensor_name)
- # 調整圖片與周圍的間距
- plt.tight_layout()
- # plt.show()
- # 儲存圖片 應改為相對路徑
- plt.savefig('C:/Users/USER/Rita/Coffee/CoffeeProject/app/static/img/new_plot.png')
- '''
- # 判斷資料索取區間 起>迄
- else:
- return render_template('sensor_chart_D.html', **locals())
- '''
- @main.route('/chart_DI/<sensor_name>/<tid>', methods=['GET', 'POST'])
- def chart_DI(sensor_name, tid):
- if request.method == 'GET':
- return render_template('sensor_chart_DI.html', **locals())
- elif request.method == 'POST':
- starttime = request.values['sensor_starttime'] # 2021-07-19T09:00
- endtime = request.values['sensor_endtime'] # 2021-07-19T12:00
- sensor_name = request.values['sensors']
- print('sensor_name:', sensor_name)
- # 判斷資料索取區間 起<迄
- if starttime < endtime :
- start_YY = starttime[:4] # '2021'
- start_MM = starttime[6:7] if starttime[5:7][:1] == '0' else starttime[5:7] # '07'
- start_DD = starttime[9:10] if starttime[8:10][:1] == '0' else starttime[8:10] # '19'
- start_hh = starttime[12:13] if starttime[11:13][:1] == '0' else starttime[11:13] # '09'
- start_mm = starttime[15:] if starttime[14:][:1] == '0' else starttime[14:] # '00'
- start_ss = 0
- end_YY = endtime[:4] # '2021'
- end_MM = endtime[6:7] if endtime[5:7][:1] == '0' else endtime[5:7] # '07'
- end_DD = endtime[9:10] if endtime[8:10][:1] == '0' else endtime[8:10] # '19'
- end_hh = endtime[12:13] if endtime[11:13][:1] == '0' else endtime[11:13] # '09'
- end_mm = endtime[15:] if endtime[14:][:1] == '0' else endtime[14:] # '00'
- end_ss = 0
- time_range = []
- temp_range = []
- # 拿掉會 Error, 要使用沒有 GUI 的 matplotlib
- plt.switch_backend('agg')
- plt.figure()
- if sensor_name == 'UltraSonic':
- for d in db.session.query(dry_input_sensor) \
- .filter_by(tank_num='DI' + tid) \
- .filter(dt(int(start_YY), int(start_MM), int(start_DD), int(start_hh), int(start_mm), int(start_ss)) < dry_tank_UltraSonic.datetime) \
- .filter(dry_tank_UltraSonic.datetime < dt(int(end_YY), int(end_MM), int(end_DD), int(end_hh), int(end_mm), int(end_ss))) \
- .order_by(dry_tank_UltraSonic.datetime):
- # print('d_test', f'{d.datetime} - {d.SHT11_Temp}')
-
- time_range.append(str(d.datetime))
- temp_range.append(float(d.UltraSonic))
- # 畫出 x 軸基準線
- # plt.axhline(28.5, color= 'r')
-
- print('time_range:', time_range)
- print('temp_range:', temp_range)
-
- return render_template('sensor_chart_DI.html', **locals())
- # 判斷資料索取區間 起>迄
- else:
- return render_template('sensor_chart_DI.html', **locals())
- @main.route('/chart_DO/<sensor_name>/<tid>', methods=['GET', 'POST'])
- def chart_DO(sensor_name, tid):
- if request.method == 'GET':
- return render_template('sensor_chart_DO.html', **locals())
- elif request.method == 'POST':
- starttime = request.values['sensor_starttime'] # 2021-07-19T09:00
- endtime = request.values['sensor_endtime'] # 2021-07-19T12:00
- sensor_name = request.values['sensors']
- print('sensor_name:', sensor_name)
- # 判斷資料索取區間 起<迄
- if starttime < endtime :
- start_YY = starttime[:4] # '2021'
- start_MM = starttime[6:7] if starttime[5:7][:1] == '0' else starttime[5:7] # '07'
- start_DD = starttime[9:10] if starttime[8:10][:1] == '0' else starttime[8:10] # '19'
- start_hh = starttime[12:13] if starttime[11:13][:1] == '0' else starttime[11:13] # '09'
- start_mm = starttime[15:] if starttime[14:][:1] == '0' else starttime[14:] # '00'
- start_ss = 0
- end_YY = endtime[:4] # '2021'
- end_MM = endtime[6:7] if endtime[5:7][:1] == '0' else endtime[5:7] # '07'
- end_DD = endtime[9:10] if endtime[8:10][:1] == '0' else endtime[8:10] # '19'
- end_hh = endtime[12:13] if endtime[11:13][:1] == '0' else endtime[11:13] # '09'
- end_mm = endtime[15:] if endtime[14:][:1] == '0' else endtime[14:] # '00'
- end_ss = 0
- time_range = []
- temp_range = []
- # 拿掉會 Error, 要使用沒有 GUI 的 matplotlib
- plt.switch_backend('agg')
- plt.figure()
- if sensor_name == 'UltraSonic':
- for d in db.session.query(dry_input_sensor) \
- .filter_by(tank_num='DO' + tid) \
- .filter(dt(int(start_YY), int(start_MM), int(start_DD), int(start_hh), int(start_mm), int(start_ss)) < dry_tank_UltraSonic.datetime) \
- .filter(dry_tank_UltraSonic.datetime < dt(int(end_YY), int(end_MM), int(end_DD), int(end_hh), int(end_mm), int(end_ss))) \
- .order_by(dry_tank_UltraSonic.datetime):
- # print('d_test', f'{d.datetime} - {d.SHT11_Temp}')
-
- time_range.append(str(d.datetime))
- temp_range.append(float(d.UltraSonic))
- # 畫出 x 軸基準線
- # plt.axhline(28.5, color= 'r')
-
- print('time_range:', time_range)
- print('temp_range:', temp_range)
-
- return render_template('sensor_chart_DO.html', **locals())
- # 判斷資料索取區間 起>迄
- else:
- return render_template('sensor_chart_DO.html', **locals())
-
- '''
- # Rita 測試
- # 乾燥桶感測器/致動器測試
- # Rita 須加上 <tid> 區分桶號 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- @main.route('/dry_tank/1', methods=['GET'])
- def dry_tank():
- if request.method == 'GET':
-
- return render_template('dry_tank.html')
- @main.route('/clean', methods=['GET'])
- def clean():
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- else:
- return render_template('oops.html', params=locals())
- return render_template('clean.html', title='清洗貨櫃', **locals())
- @main.route('/ferment', methods=['GET'])
- def ferment():
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- else:
- return render_template('oops.html', params=locals())
- return render_template('ferment.html', title='發酵貨櫃', **locals())
- @main.route('/dry', methods=['GET'])
- def dry():
- if request.method == 'GET':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- else:
- return render_template('oops.html', params=locals())
- return render_template('dry.html', title='乾燥貨櫃', **locals())
- @main.route('/peel_container_tank/<tid>', methods=['GET', 'POST'])
- def peel_container_tnak(tid):
- if request.method == 'GET':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- else:
- return render_template('oops.html', params=locals())
- # 致動器_脫皮機_ALL
- tank_actuator = peel_tank_actuator.query.filter_by(tank_num='P'+str(tid)).order_by(text('datetime desc')).first()
- tank_vacuum = tank_actuator.vacuum
- tank_motor = tank_actuator.motor
-
- return render_template('peel_container_tank.html', title='[操作] P' + tid + ' 脫皮機操作介面', **locals())
- elif request.method == 'POST':
- pass
-
- @main.route('/peel_container/<tid>', methods=['GET', 'POST'])
- def peel_container(tid):
- if request.method == 'GET':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- else:
- return render_template('oops.html', params=locals())
- # 致動器_入料儲豆槽_真空吸料機
- input_vacuum = peel_input_actuator.query.filter_by(tank_num='P'+str(tid)).order_by(text('datetime desc')).first()
- input_vacuum = input_vacuum.vacuum
- print("input_vacuum:", input_vacuum)
- # 致動器_脫皮機_ALL
- tank_actuator = peel_tank_actuator.query.filter_by(tank_num='P'+str(tid)).order_by(text('datetime desc')).first()
- tank_vacuum = tank_actuator.vacuum
- tank_motor = tank_actuator.motor
-
- # 致動器_出料儲豆槽_真空吸料機
- output_vacuum = peel_output_actuator.query.filter_by(tank_num='P'+str(tid)).order_by(text('datetime desc')).first()
- output_vacuum = output_vacuum.vacuum
-
- return render_template('peel_container.html', title='脫皮機P' + tid + '總操作介面', **locals())
- elif request.method == 'POST':
- pass
- @main.route('/clean_container/<tid>', methods=['GET', 'POST'])
- def clean_container(tid):
- if request.method == 'GET':
-
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- else:
- return render_template('oops.html', params=locals())
- # 致動器_入料儲豆槽_真空吸料機
- input_vacuum = clean_input_actuator.query.filter_by(tank_num='C'+str(tid)).order_by(text('datetime desc')).first()
- input_vacuum = 'ON' if (input_vacuum.vacuum == 1) else 'OFF'
- # 致動器_浮選清洗_ALL
- tank_actuator = clean_tank_actuator.query.filter_by(tank_num='C'+str(tid)).order_by(text('datetime desc')).first()
- tank_vacuum = 'ON' if tank_actuator.vacuum == 1 else 'OFF'
- tank_pump_waterInput = 'ON' if tank_actuator.pump_waterInput == 1 else 'OFF'
- tank_pump_waterL2L3 = 'ON' if tank_actuator.pump_waterL2L3 == 1 else 'OFF'
- tank_pump_waterL4L5 = 'ON' if tank_actuator.pump_waterL4L5 == 1 else 'OFF'
- tank_solenoid_waterL2L3 = 'ON' if tank_actuator.solenoid_waterL2L3 == 1 else 'OFF'
- tank_solenoid_waterL4L5 = 'ON' if tank_actuator.solenoid_waterL4L5 == 1 else 'OFF'
- tank_stepping_motor = tank_actuator.stepping_motor
-
- # 致動器_出料儲豆槽_真空吸料機
- output_vacuum = clean_output_actuator.query.filter_by(tank_num='C'+str(tid)).order_by(text('datetime desc')).first()
- output_vacuum = 'ON' if (output_vacuum.vacuum == 1) else 'OFF'
- # 感測器_浮選清洗_超音波感測器
- tank_UltraSonic = clean_tank_UltraSonic.query.filter_by(tank_num='C'+str(tid)).order_by(text('datetime desc')).first()
-
-
- return render_template('clean_container.html', title='清洗浮選槽C' + tid + '總操作介面', **locals())
- elif request.method == 'POST':
- pass
- @main.route('/ferment_container/<tid>', methods=['GET', 'POST'])
- def ferment_container(tid):
- if request.method == 'GET':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- else:
- return render_template('oops.html', params=locals())
- # 致動器_發酵槽_ALL
- tank_actuator = ferment_tank_actuator.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- tank_vacuum = 'ON' if tank_actuator.vacuum == 1 else 'OFF'
- tank_threewayvalve_input = 'ON' if tank_actuator.threewayvalve_input == 1 else 'OFF'
- tank_diskvalve = 'ON' if tank_actuator.diskvalve == 1 else 'OFF'
- tank_solenoid_water_total = 'ON' if tank_actuator.solenoid_tank_water_total == 1 else 'OFF'
- tank_solenoid_disinfect = 'ON' if tank_actuator.solenoid_tank_disinfect == 1 else 'OFF'
- outer_solenoid_water = 'ON' if tank_actuator.solenoid_outer_water == 1 else 'OFF'
- tank_solenoid_water_in = 'ON' if tank_actuator.solenoid_tank_water_in == 1 else 'OFF'
- tank_pump_sensor = 'ON' if tank_actuator.pump_sensor == 1 else 'OFF'
- tank_threewayvalve_bean = 'ON' if tank_actuator.threewayvalve_bean == 1 else 'OFF'
- outer_threewayvalve_float = 'ON' if tank_actuator.threewayvalve_outer_float == 1 else 'OFF'
- tank_motor = tank_actuator.motor
- tank_heater1 = 'ON' if tank_actuator.heater1 == 1 else 'OFF'
- tank_heater2 = 'ON' if tank_actuator.heater2 == 1 else 'OFF'
- tank_temp_enable = 'ON' if tank_actuator.temp_enable == 1 else 'OFF'
- tank_temp = tank_actuator.temp
- # 感測器_發酵桶_SHT11
- tank_SHT11 = ferment_tank_SHT11.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- # 感測器_發酵桶_二氧化碳
- tank_CO2 = ferment_tank_CO2.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- # 感測器_發酵桶_酸鹼值
- tank_PH = ferment_tank_PH.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- tank_ORP = ferment_tank_ORP.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- tank_DO = ferment_tank_DO.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- tank_EC = ferment_tank_EC.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- # 感測器_發酵桶_氣壓
- tank_PA = ferment_tank_PA.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- # 感測器_發酵桶_超音波感測器
- tank_UltraSonic = ferment_tank_UltraSonic.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- # 感測器_發酵桶_水位計
- tank_WaterLevel = ferment_tank_WaterLevel.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- num_tank_WaterLevel = float(tank_WaterLevel.WaterLevel)
- print('tank_WaterLevel', tank_WaterLevel.WaterLevel)
- if tank_WaterLevel.WaterLevel == '1':
- WaterLevel = '滿'
- elif tank_WaterLevel.WaterLevel == '0':
- WaterLevel = '未達滿水高度'
- else:
- WaterLevel = 'ERROR'
- # 感測器_發酵桶_咖啡生豆高度
- tank_LiDAR = ferment_tank_LiDAR.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- LiDAR = tank_LiDAR.LiDAR
- # 感測器_發酵桶_水位高度
- tank_PressureWaterLevel = ferment_tank_PressureWaterLevel.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- PressureWaterLevel = '{:.2f}'.format((float(tank_PressureWaterLevel.PressureWaterLevel) -15 -90.278)/9.4214)
- if tid in ['1', '2', '3', '4', '5', '6']:
- # print("1")
- # 感測器_入料儲豆槽_超音波感測器
- input_UltraSonic = ferment_input_UltraSonic.query.filter_by(tank_num='FI1').order_by(text('datetime desc')).first()
- # 致動器_入料儲豆槽_真空吸引機
- input_vacuum = ferment_input_actuator.query.filter_by(tank_num='FI1').order_by(text('datetime desc')).first()
- input_vacuum = input_vacuum.vacuum
- # 感測器_出料儲豆槽_超音波感測器
- output_UltraSonic = ferment_output_UltraSonic.query.filter_by(tank_num='FO1').order_by(text('datetime desc')).first()
- # 致動器_出料儲豆槽_真空吸引機
- output_vacuum = ferment_output_actuator.query.filter_by(tank_num='FO1').order_by(text('datetime desc')).first()
- output_vacuum = output_vacuum.vacuum
- elif tid in ['7', '8', '9', '10', '11', '12']:
- # print("2")
- # 感測器_入料儲豆槽_超音波感測器
- input_UltraSonic = ferment_input_UltraSonic.query.filter_by(tank_num='FI2').order_by(text('datetime desc')).first()
- # 致動器_入料儲豆槽_真空吸引機
- input_vacuum = ferment_input_actuator.query.filter_by(tank_num='FI2').order_by(text('datetime desc')).first()
- input_vacuum = input_vacuum.vacuum
- print("input_vacuum", input_vacuum)
- # 感測器_出料儲豆槽_超音波感測器
- output_UltraSonic = ferment_output_UltraSonic.query.filter_by(tank_num='FO2').order_by(text('datetime desc')).first()
- # 致動器_出料儲豆槽_真空吸引機
- output_vacuum = ferment_output_actuator.query.filter_by(tank_num='FO2').order_by(text('datetime desc')).first()
- output_vacuum = output_vacuum.vacuum
- print("output_vacuum", output_vacuum)
-
- return render_template('ferment_container.html', title='發酵槽F' + tid + '總操作介面' , **locals())
- elif request.method == 'POST':
- pass
- @main.route('/ferment_container_tank/<tid>', methods=['GET', 'POST'])
- def ferment_container_tank(tid):
- if request.method == 'GET':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- else:
- return render_template('oops.html', params=locals())
- # 致動器_發酵槽_ALL
-
- tank_actuator = ferment_tank_actuator.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- tank_vacuum = 'ON' if tank_actuator.vacuum == 1 else 'OFF'
- tank_threewayvalve_input = 'ON' if tank_actuator.threewayvalve_input == 1 else 'OFF'
- tank_diskvalve = 'ON' if tank_actuator.diskvalve == 1 else 'OFF'
- solenoid_tank_pump = 'ON' if tank_actuator.solenoid_tank_pump == 1 else 'OFF'
- tank_solenoid_disinfect = 'ON' if tank_actuator.solenoid_tank_disinfect == 1 else 'OFF'
- outer_solenoid_water = 'ON' if tank_actuator.solenoid_outer_water == 1 else 'OFF'
- tank_solenoid_water_in = 'ON' if tank_actuator.solenoid_tank_water_in == 1 else 'OFF'
- tank_solenoid_water_out = 'ON' if tank_actuator.solenoid_tank_water_out == 1 else 'OFF'
- tank_pump_sensor = 'ON' if tank_actuator.pump_sensor == 1 else 'OFF'
- outer_threewayvalve_float = 'ON' if tank_actuator.threewayvalve_outer_float == 1 else 'OFF'
- tank_motor = tank_actuator.motor
- tank_heater1 = 'ON' if tank_actuator.heater1 == 1 else 'OFF'
- tank_heater2 = 'ON' if tank_actuator.heater2 == 1 else 'OFF'
- tank_temp_enable = 'ON' if tank_actuator.temp_enable == 1 else 'OFF'
- tank_temp = tank_actuator.temp
- # 感測器_發酵桶_SHT11
- tank_SHT11 = ferment_tank_SHT11.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- # 感測器_發酵桶_二氧化碳
- tank_CO2 = ferment_tank_CO2.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- # 感測器_發酵桶_酸鹼值
- tank_PH = ferment_tank_PH.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- tank_ORP = ferment_tank_ORP.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- tank_DO = ferment_tank_DO.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- tank_EC = ferment_tank_EC.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- # 感測器_發酵桶_氣壓
- tank_PA = ferment_tank_PA.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- # 感測器_發酵桶_超音波感測器
- tank_UltraSonic = ferment_tank_UltraSonic.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- # 感測器_發酵桶_水位計
- tank_WaterLevel = ferment_tank_WaterLevel.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- num_tank_WaterLevel = float(tank_WaterLevel.WaterLevel)
- if tank_WaterLevel.WaterLevel == '1':
- WaterLevel = '滿'
- elif tank_WaterLevel.WaterLevel == '0':
- WaterLevel = '未達滿水高度'
- else:
- WaterLevel = 'ERROR'
- # 感測器_發酵桶_咖啡生豆高度
- #tank_LiDAR = ferment_tank_LiDAR.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- #LiDAR = tank_LiDAR.LiDAR
- # 感測器_發酵桶_水位高度
- #tank_PressureWaterLevel = ferment_tank_PressureWaterLevel.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- #PressureWaterLevel = '{:.2f}'.format((float(tank_PressureWaterLevel.PressureWaterLevel) -15 -90.278)/9.4214)
-
- return render_template('ferment_container_tank.html', title='[操作] F' + tid + ' 發酵槽操作介面', **locals())
- elif request.method == 'POST':
- pass
- @main.route('/ferment_container_input/<tid>', methods=['GET', 'POST'])
- def ferment_container_input(tid):
- if request.method == 'GET':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- else:
- return render_template('oops.html', params=locals())
- # 感測器_入料儲豆槽_超音波感測器
- input_UltraSonic = ferment_input_UltraSonic.query.filter_by(tank_num='FI' + tid).order_by(text('datetime desc')).first()
- # 致動器_入料儲豆槽_真空吸引機
- input_vacuum = ferment_input_actuator.query.filter_by(tank_num='FI' + tid).order_by(text('datetime desc')).first()
- input_vacuum = input_vacuum.vacuum
-
- return render_template('ferment_container_input.html', title='[操作] FI' + tid + ' 發酵入料儲豆槽操作介面', **locals())
- elif request.method == 'POST':
- pass
- @main.route('/ferment_container_output/<tid>', methods=['GET', 'POST'])
- def ferment_container_output(tid):
- if request.method == 'GET':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- else:
- return render_template('oops.html', params=locals())
- # 感測器_出料儲豆槽_超音波感測器
- output_UltraSonic = ferment_output_UltraSonic.query.filter_by(tank_num='FO' + tid).order_by(text('datetime desc')).first()
- # 致動器_出料儲豆槽_真空吸引機
- output_vacuum = ferment_output_actuator.query.filter_by(tank_num='FO' + tid).order_by(text('datetime desc')).first()
- output_vacuum = output_vacuum.vacuum
- tank_LiDAR = ferment_tank_LiDAR.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- LiDAR = tank_LiDAR.LiDAR
-
- return render_template('ferment_container_output.html', title='[操作] FO' + tid + ' 發酵出料儲豆槽操作介面', **locals())
- elif request.method == 'POST':
- pass
- @main.route('/dry_container_schedule', methods=['GET', 'POST'])
- def dry_container_schedule():
- if request.method == 'GET':
- if 'id' in session and 'uname' in session:
- username = session['uname']
-
- # 感測器_入料儲豆槽_超音波感測器
- input_UltraSonic = dry_input_sensor.query.order_by(text('datetime desc')).first()
- # 感測器_乾燥桶_超音波感測器
- tank_UltraSonic = dry_tank_UltraSonic.query.order_by(text('datetime desc')).first()
-
- return render_template('dry_container_schedule.html', title='dry_container_schedule', **locals())
-
- elif request.method == 'POST':
- pass
- # 乾燥貨櫃_各致動器控制
- @main.route('/ctrl_DI_<actuator>/<tid>', methods=['GET', 'POST'])
- def ctrl_DI(actuator, tid):
- if request.method == 'GET':
- if actuator == 'Vacuum':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- else:
- return render_template('oops.html', params=locals())
- input_brake = dry_input_brake.query.filter_by(tank_num='DI'+str(tid)).order_by(text('datetime desc')).first()
- input_vacuum = input_brake.vacuum
- tank_UltraSonic = dry_input_sensor.query.filter_by(tank_num='DI'+str(tid)).order_by(text('datetime desc')).first()
- UltraSonic = tank_UltraSonic.UltraSonic
- return render_template('ctrl_DI_Vacuum.html', title='[操作]DI' + tid + '乾燥槽入料_真空吸料機', **locals())
- elif request.method == 'POST':
- pass
- @main.route('/ctrl_DO_<actuator>/<tid>', methods=['GET', 'POST'])
- def ctrl_DO(actuator, tid):
- if request.method == 'GET':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- else:
- return render_template('oops.html', params=locals())
-
- if actuator == 'Vacuum':
- tank_brake = dry_output_brake.query.filter_by(tank_num='DO'+str(tid)).order_by(text('datetime desc')).first()
- tank_vacuum = tank_brake.vacuum
- tank_UltraSonic = dry_output_sensor.query.filter_by(tank_num='DO'+str(tid)).order_by(text('datetime desc')).first()
- UltraSonic = tank_UltraSonic.UltraSonic
- return render_template('ctrl_DO_Vacuum.html', title='[操作]DI' + tid + '乾燥槽出料_真空吸料機', **locals())
- elif request.method == 'POST':
- pass
-
- @main.route('/ctrl_D_<actuator>/<tid>', methods=['GET', 'POST'])
- def ctrl_D(actuator, tid):
- if request.method == 'GET':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- else:
- return render_template('oops.html', params=locals())
- tank_brake = dry_tank_brake.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- if actuator == 'Vacuum':
- tank_vacuum = tank_brake.vacuum
- tank_UltraSonic = dry_tank_UltraSonic.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- UltraSonic = tank_UltraSonic.UltraSonic
- return render_template('ctrl_D_Vacuum.html', title='[操作]D' + tid + '乾燥槽_真空吸料機', **locals())
- elif actuator == 'ThreeWayValve':
- tank_threewayvalve = tank_brake.threewayvalve
- return render_template('ctrl_D_ThreeWayValve.html', title='[操作]D' + tid + '乾燥槽_三通閥', **locals())
- elif actuator == 'DiskValve':
- tank_diskvalve = tank_brake.diskvalve
- return render_template('ctrl_D_DiskValve.html', title='[操作]D' + tid + '乾燥槽_蝴蝶閥', **locals())
- elif actuator == 'SolenoidDisinfect':
- tank_solenoid_disinfect = tank_brake.solenoid_disinfect
- return render_template('ctrl_D_SolenoidDisinfect.html', title='[操作]D' + tid + '乾燥槽_消毒電磁閥', **locals())
- elif actuator == 'SolenoidWater':
- tank_solenoid_water = tank_brake.solenoid_water
- return render_template('ctrl_D_SolenoidWater.html', title='[操作]D' + tid + '乾燥槽_排水電磁閥', **locals())
- elif actuator == 'Motor':
- tank_motor = tank_brake.motor
- return render_template('ctrl_D_Motor.html', title='[操作]D' + tid + '乾燥槽_馬達', **locals())
- elif actuator == 'Blower':
- tank_blower = tank_brake.blower
- tank_SHT11 = dry_tank_SHT11.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- tank_Soil = dry_tank_Soil.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- return render_template('ctrl_D_Blower.html', title='[操作]D' + tid + '乾燥槽_鼓風機', **locals())
- elif actuator == 'Heater1':
- tank_heater1 = tank_brake.heater1
- tank_SHT11 = dry_tank_SHT11.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- tank_Soil = dry_tank_Soil.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- return render_template('ctrl_D_Heater1.html', title='[操作]D' + tid + '乾燥槽_加熱器 1', **locals())
- elif actuator == 'Heater2':
- tank_heater2 = tank_brake.heater2
- tank_SHT11 = dry_tank_SHT11.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- tank_Soil = dry_tank_Soil.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- return render_template('ctrl_D_Heater2.html', title='[操作]D' + tid + '乾燥槽_加熱器 2', **locals())
- elif actuator == 'TempEnable':
- tank_temp1_enable = tank_brake.temp1_enable
- return render_template('ctrl_D_TempEnable.html', title='[操作]D' + tid + '乾燥槽_溫控開關', **locals())
- elif actuator == 'Temp':
- tank_temp1_enable = tank_brake.temp1_enable
- tank_temp1 = tank_brake.temp1
- tank_SHT11 = dry_tank_SHT11.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- tank_Soil = dry_tank_Soil.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- return render_template('ctrl_D_Temp.html', title='[操作]D' + tid + '乾燥槽_設定溫度', **locals())
- elif request.method == 'POST':
- pass
- # 發酵貨櫃_各致動器控制
- @main.route('/ctrl_FI_<actuator>/<tid>', methods=['GET', 'POST'])
- def ctrl_FI(actuator, tid):
- if request.method == 'GET':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- else:
- return render_template('oops.html', params=locals())
- if actuator == 'Vacuum':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- else:
- return render_template('oops.html', params=locals())
- tank_actuator = ferment_input_actuator.query.filter_by(tank_num='FI'+str(tid)).order_by(text('datetime desc')).first()
- tank_vacuum = tank_actuator.vacuum
- tank_UltraSonic = ferment_input_UltraSonic.query.filter_by(tank_num='FI'+str(tid)).order_by(text('datetime desc')).first()
- UltraSonic = tank_UltraSonic.UltraSonic
- return render_template('ctrl_FI_Vacuum.html', title='[操作]FI' + tid + '發酵入料儲豆槽_真空吸料機', **locals())
- elif request.method == 'POST':
- pass
- @main.route('/ctrl_FO_<actuator>/<tid>', methods=['GET', 'POST'])
- def ctrl_FO(actuator, tid):
- if request.method == 'GET':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- else:
- return render_template('oops.html', params=locals())
- if actuator == 'Vacuum':
- tank_actuator = ferment_output_actuator.query.filter_by(tank_num='FO'+str(tid)).order_by(text('datetime desc')).first()
- tank_vacuum = tank_actuator.vacuum
- tank_UltraSonic = ferment_output_UltraSonic.query.filter_by(tank_num='FO'+str(tid)).order_by(text('datetime desc')).first()
- UltraSonic = tank_UltraSonic.UltraSonic
- return render_template('ctrl_FO_Vacuum.html', title='[操作]FO' + tid + '發酵出料儲豆槽_真空吸料機', **locals())
- elif request.method == 'POST':
- pass
- @main.route('/ctrl_F_<actuator>/<tid>', methods=['GET', 'POST'])
- def ctrl_F(actuator, tid):
- if request.method == 'GET':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- else:
- return render_template('oops.html', params=locals())
- tank_actuator = ferment_tank_actuator.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- if actuator == 'Vacuum':
- tank_vacuum = tank_actuator.vacuum
- tank_LiDAR = ferment_tank_LiDAR.query.filter_by(tank_num='F'+str(tid)).order_by(text('datetime desc')).first()
- LiDAR = tank_LiDAR.LiDAR
- return render_template('ctrl_F_Vacuum.html', title='[操作]F' + tid + '發酵槽_真空吸料機', **locals())
- elif actuator == 'ThreeWayValveInput':
- tank_threewayvalveinput = tank_actuator.threewayvalve_input
- return render_template('ctrl_F_ThreeWayValveInput.html', title='[操作]F' + tid + '發酵槽_入料三通閥', **locals())
- elif actuator == 'SolenoidWaterTotal':
- tank_solenoid_tank_water_total = tank_actuator.solenoid_tank_water_total
- return render_template('ctrl_F_SolenoidWaterTotal.html', title='[操作]F' + tid + '發酵槽_總進水電磁閥', **locals())
- elif actuator == 'SolenoidOuterWater':
- tank_solenoid_outer_water = tank_actuator.solenoid_outer_water
- tank_WaterLevel = ferment_tank_WaterLevel.query.filter_by(tank_num='F' + tid).order_by(text('datetime desc')).first()
- WaterLevel = tank_WaterLevel.WaterLevel
- return render_template('ctrl_F_SolenoidOuterWater.html', title='[操作]F' + tid + '發酵槽_保溫夾層進水電磁閥', **locals())
- elif actuator == 'SolenoidWaterIn':
- tank_solenoid_tank_water_in = tank_actuator.solenoid_tank_water_in
- tank_PressureWaterLevel = ferment_tank_PressureWaterLevel.query.filter_by(tank_num='F' + tid).order_by(text('datetime desc')).first()
- PressureWaterLevel = tank_PressureWaterLevel.PressureWaterLevel
- return render_template('ctrl_F_SolenoidWaterIn.html', title='[操作]F' + tid + '發酵槽_桶內進水電磁閥', **locals())
- elif actuator == 'PumpSensor':
- tank_pump_sensor = tank_actuator.pump_sensor
- tank_PH = ferment_tank_PH.query.filter_by(tank_num='F' + tid).order_by(text('datetime desc')).first()
- tank_ORP = ferment_tank_ORP.query.filter_by(tank_num='F' + tid).order_by(text('datetime desc')).first()
- tank_DO = ferment_tank_DO.query.filter_by(tank_num='F' + tid).order_by(text('datetime desc')).first()
- tank_EC = ferment_tank_EC.query.filter_by(tank_num='F' + tid).order_by(text('datetime desc')).first()
- PH = tank_PH.PH
- ORP = tank_ORP.ORP
- DO = tank_DO.DO
- EC = tank_EC.EC
- return render_template('ctrl_F_PumpSensor.html', title='[操作]F' + tid + '發酵槽_感測器抽水雙核隔膜泵', **locals())
- elif actuator == 'ThreeWayValveBean':
- tank_threewayvalve_bean = tank_actuator.threewayvalve_bean
- return render_template('ctrl_F_ThreeWayValveBean.html', title='[操作]F' + tid + '發酵槽_感測模組下豆三通閥', **locals())
- elif actuator == 'ThreeWayValveFloat':
- tank_threewayvalve_outer_float = tank_actuator.threewayvalve_outer_float
- return render_template('ctrl_F_ThreeWayValveFloat.html', title='[操作]F' + tid + '發酵槽_外桶浮選三通閥', **locals())
- elif actuator == 'SolenoidDisinfect':
- tank_solenoid_tank_disinfect = tank_actuator.solenoid_tank_disinfect
- return render_template('ctrl_F_SolenoidDisinfect.html', title='[操作]F' + tid + '發酵槽_桶內消毒電磁閥', **locals())
- elif actuator == 'Motor':
- tank_motor = tank_actuator.motor
- return render_template('ctrl_F_Motor.html', title='[操作]F' + tid + '發酵槽_馬達', **locals())
- elif actuator == 'Heater1':
- tank_heater1 = tank_actuator.heater1
- tank_SHT11 = ferment_tank_SHT11.query.filter_by(tank_num='F' + tid).order_by(text('datetime desc')).first()
- return render_template('ctrl_F_Heater1.html', title='[操作]F' + tid + '發酵槽_加熱器 1', **locals())
- elif actuator == 'Heater2':
- tank_heater2 = tank_actuator.heater2
- tank_SHT11 = ferment_tank_SHT11.query.filter_by(tank_num='F' + tid).order_by(text('datetime desc')).first()
- return render_template('ctrl_F_Heater2.html', title='[操作]F' + tid + '發酵槽_加熱器 2', **locals())
- elif actuator == 'TempEnable':
- tank_temp_enable = tank_actuator.temp_enable
- return render_template('ctrl_F_TempEnable.html', title='[操作]F' + tid + '發酵槽_溫控開關', **locals())
- elif actuator == 'Temp':
- tank_temp = tank_actuator.temp
- tank_temp_enable = tank_actuator.temp_enable
- tank_SHT11 = ferment_tank_SHT11.query.filter_by(tank_num='F' + tid).order_by(text('datetime desc')).first()
- return render_template('ctrl_F_Temp.html', title='[操作]F' + tid + '發酵槽_溫度設定', **locals())
- elif actuator == 'DiskValve':
- tank_diskvalve = tank_actuator.diskvalve
- return render_template('ctrl_F_DiskValve.html', title='[操作]F' + tid + '發酵槽_蝴蝶閥', **locals())
- @main.route('/dry_Temp/<tid>/<Temp_Weights_SHT11>/<Temp_Weights_Soil>/<temp_data>', methods=['GET', 'POST'])
- def dry_Temp(tid, Temp_Weights_SHT11, Temp_Weights_Soil, temp_data):
- if request.method == 'GET':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- else:
- return render_template('oops.html', params=locals())
- tank_SHT11 = dry_tank_SHT11.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- SHT11_Temp = float(tank_SHT11.SHT11_Temp)
- SHT11_Humidity = tank_SHT11.SHT11_Humidity
- tank_Soil = dry_tank_Soil.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- Soil_Temp = float(tank_Soil.soil_Temp)
- Soil_Humidity = tank_Soil.soil_Humidity
- Temp_Weights_SHT11= float(Temp_Weights_SHT11)
- Temp_Weights_Soil = float(Temp_Weights_Soil)
- temp_data = float(temp_data)
- present_temp = math.ceil( (SHT11_Temp*Temp_Weights_SHT11 + Soil_Temp*Temp_Weights_Soil)/(Temp_Weights_SHT11+Temp_Weights_Soil) )
- # Math.round((present_SHT11_Temp*Temp_Weights_SHT11 + present_SOIL_Temp*Temp_Weights_Soil)/(Temp_Weights_SHT11+Temp_Weights_Soil)*100) / 100
- target_temp = math.ceil(temp_data)
- TempUp = {
- 22:0, 23:6, 24:12, 25:18, 26:24, 27:28, 28:32, 29:36, 30:40, 31:44, 32:48, 33:56, 34:64, 35:72, 36:96, 37:168, 38:288, 39:384, 40:529, 41:697, 42:793, 43:865, 44:1394
- }
- if target_temp in TempUp and present_temp in TempUp:
- TempUpTime = ', 預計 ' + str(TempUp[target_temp] - TempUp[present_temp]) + ' 秒達到指定溫度'
- elif target_temp < 22 or present_temp < 22 :
- TempUpTime = '℃, 指定溫度過低, 持續升溫中'
- elif target_temp > 44 or present_temp > 44 :
- TempUpTime = '℃, 指定溫度過高, 持續升溫中'
-
- return jsonify({"SHT11_Temp":SHT11_Temp,
- "SHT11_Humidity":SHT11_Humidity,
- "Soil_Temp":Soil_Temp,
- "Soil_Humidity":Soil_Humidity,
- "present_temp":present_temp,
- "TempUpTime":TempUpTime
- })
- else:
- pass
- @main.route('/dry_container_tank/<tid>', methods=['GET', 'POST'])
- def dry_container_tank(tid):
- if request.method == 'GET':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- else:
- return render_template('oops.html', params=locals())
- # 感測器_乾燥桶_SHT11
- tank_SHT11 = dry_tank_SHT11.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- num_SHT11_temp = float(tank_SHT11.SHT11_Temp)
- # 感測器_乾燥桶_土壤三合一
- tank_Soil = dry_tank_Soil.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- num_Soil_temp = float(tank_Soil.soil_Temp)
- # 感測器_乾燥桶_氣壓
- tank_PA = dry_tank_PA.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- # 感測器_乾燥桶_超音波感測器
- tank_UltraSonic = dry_tank_UltraSonic.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- # 致動器_乾燥桶_ALL
- tank_brake = dry_tank_brake.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- tank_vacuum = tank_brake.vacuum
- tank_threewayvalve = tank_brake.threewayvalve
- tank_diskvalve = tank_brake.diskvalve
- tank_solenoid_disinfect = tank_brake.solenoid_disinfect
- tank_solenoid_water = tank_brake.solenoid_water
- tank_motor = tank_brake.motor
- tank_blower = tank_brake.blower
- tank_heater1 = tank_brake.heater1
- tank_heater2 = tank_brake.heater2
- tank_temp1_enable = tank_brake.temp1_enable
- tank_temp1 = tank_brake.temp1
- Temp_weight = num_SHT11_temp * 0.5 + num_Soil_temp * 0.5
- return render_template('dry_container_tank.html', title='[操作] D' + tid + ' 乾燥槽操作介面', **locals())
- elif request.method == 'POST':
- pass
- @main.route('/dry_container_input/<tid>', methods=['GET', 'POST'])
- def dry_container_input(tid):
- if request.method == 'GET':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- else:
- return render_template('oops.html', params=locals())
-
- input_UltraSonic = dry_input_sensor.query.filter_by(tank_num='DI'+str(tid)).order_by(text('datetime desc')).first()
- input_vacuum = dry_input_brake.query.filter_by(tank_num='DI'+str(tid)).order_by(text('datetime desc')).first()
- input_vacuum = input_vacuum.vacuum
- return render_template('dry_container_input.html', title='[操作] DI' + tid + ' 乾燥入料儲豆槽操作介面', **locals())
- elif request.method == 'POST':
- pass
- @main.route('/dry_container_output/<tid>', methods=['GET', 'POST'])
- def dry_container_output(tid):
- if request.method == 'GET':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- else:
- return render_template('oops.html', params=locals())
-
- output_UltraSonic = dry_output_sensor.query.filter_by(tank_num='DO'+str(tid)).order_by(text('datetime desc')).first()
- output_vacuum = dry_output_brake.query.filter_by(tank_num='DO'+str(tid)).order_by(text('datetime desc')).first()
- output_vacuum = output_vacuum.vacuum
- return render_template('dry_container_output.html', title='[操作] DO' + tid + ' 乾燥出料儲豆槽操作介面', **locals())
- elif request.method == 'POST':
- pass
- # 原本的乾燥貨櫃控制, 備份用
- @main.route('/dry_container/<tid>', methods=['GET', 'POST'])
- def dry_container(tid):
- if request.method == 'GET':
- if 'id' in session and 'uname' in session and 'status' in session:
- username = session['uname']
- status = session['status']
- if status == 9:
- return render_template('signin_disable.html', params=locals())
- elif status == 8:
- return render_template('signin_new.html', params=locals())
- else:
- return render_template('oops.html', params=locals())
- # Rita 參數 params 是用來取得參數的 locals=() 所有參數
- '''
- # 開啟本機 coffeetest 資料庫
- # mydb = pymysql.connect(host='127.0.0.1', port=3306, user='root', password='g53743001', database='coffeetest', charset='utf8')
- mydb = pymysql.connect(host='52.69.200.169', port=3306, user='coffee',
- password='skyeye', database='Coffee', charset='utf8')
- mycursor = mydb.cursor()
- '''
- # 感測器_乾燥桶_SHT11
- tank_SHT11 = dry_tank_SHT11.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- num_SHT11_temp = float(tank_SHT11.SHT11_Temp)
- # 感測器_乾燥桶_土壤三合一
- tank_Soil = dry_tank_Soil.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- num_Soil_temp = float(tank_Soil.soil_Temp)
- # 感測器_乾燥桶_氣壓
- tank_PA = dry_tank_PA.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- # 感測器_乾燥桶_超音波感測器
- tank_UltraSonic = dry_tank_UltraSonic.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- # 感測器_出料儲豆槽_超音波感測器
- output_UltraSonic = dry_output_sensor.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- # 致動器_乾燥桶_ALL
- tank_brake = dry_tank_brake.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- tank_vacuum = tank_brake.vacuum
- tank_threewayvalve = tank_brake.threewayvalve
- tank_diskvalve = tank_brake.diskvalve
- tank_solenoid_disinfect = tank_brake.solenoid_disinfect
- tank_solenoid_water = tank_brake.solenoid_water
- tank_motor = tank_brake.motor
- tank_blower = tank_brake.blower
- tank_heater1 = tank_brake.heater1
- tank_heater2 = tank_brake.heater2
- tank_temp1_enable = tank_brake.temp1_enable
- tank_temp1 = tank_brake.temp1
- '''
- tank_vacuum = 'ON' if tank_brake.vacuum == 1 else 'OFF'
- tank_threewayvalve = 'ON' if tank_brake.threewayvalve == 1 else 'OFF'
- tank_diskvalve = 'ON' if tank_brake.diskvalve == 1 else 'OFF'
- tank_solenoid_disinfect = 'ON' if tank_brake.solenoid_disinfect == 1 else 'OFF'
- tank_solenoid_water = 'ON' if tank_brake.solenoid_water == 1 else 'OFF'
- tank_motor = tank_brake.motor
- tank_blower = 'ON' if tank_brake.blower == 1 else 'OFF'
- tank_heater1 = 'ON' if tank_brake.heater1 == 1 else 'OFF'
- tank_heater2 = 'ON' if tank_brake.heater2 == 1 else 'OFF'
- tank_temp1_enable = 'ON' if tank_brake.temp1_enable == 1 else 'OFF'
- tank_temp1 = tank_brake.temp1
- '''
- '''
- data = mycursor.execute(
- 'SELECT * FROM dry_tank_brake ORDER BY datetime DESC;')
- data = mycursor.fetchone()
- '''
- if tid in ['1', '2', '3', '4', '5', '6']:
- # print("1")
- # 感測器_入料儲豆槽_超音波感測器
- input_UltraSonic = dry_input_sensor.query.filter_by(tank_num='DI1').order_by(text('datetime desc')).first()
- # 致動器_入料儲豆槽_真空吸引機
- input_vacuum = dry_input_brake.query.filter_by(tank_num='DI1').order_by(text('datetime desc')).first()
- input_vacuum = input_vacuum.vacuum
- # 感測器_出料儲豆槽_超音波感測器
- output_UltraSonic = dry_output_sensor.query.filter_by(tank_num='DO1').order_by(text('datetime desc')).first()
- # 致動器_出料儲豆槽_真空吸引機
- output_vacuum = dry_output_brake.query.filter_by(tank_num='DO1').order_by(text('datetime desc')).first()
- output_vacuum = output_vacuum.vacuum
- elif tid in ['7', '8', '9', '10', '11', '12']:
- print("2")
- # 感測器_入料儲豆槽_超音波感測器
- input_UltraSonic = dry_input_sensor.query.filter_by(tank_num='DI2').order_by(text('datetime desc')).first()
- # 致動器_入料儲豆槽_真空吸引機
- input_vacuum = dry_input_brake.query.filter_by(tank_num='DI2').order_by(text('datetime desc')).first()
- input_vacuum = input_vacuum.vacuum
- # 感測器_出料儲豆槽_超音波感測器
- output_UltraSonic = dry_output_sensor.query.filter_by(tank_num='DO2').order_by(text('datetime desc')).first()
- # 致動器_出料儲豆槽_真空吸引機
- output_vacuum = dry_output_brake.query.filter_by(tank_num='DO2').order_by(text('datetime desc')).first()
- output_vacuum = output_vacuum.vacuum
- '''
- # 感測器_入料儲豆槽_超音波感測器
- input_UltraSonic = dry_input_sensor.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- # 致動器_入料儲豆槽_真空吸引機
- input_vacuum = dry_input_brake.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- # print("input_vacuum:", input_vacuum)
- input_vacuum = input_vacuum.vacuum
- #print('input_vacuum:', input_vacuum.vacuum)
- # 致動器_出料儲豆槽_真空吸引機
- output_vacuum = dry_output_brake.query.filter_by(tank_num='D'+str(tid)).order_by(text('datetime desc')).first()
- #print('output_vacuum.vacuum: ', output_vacuum.vacuum)
- output_vacuum = 'ON' if (output_vacuum.vacuum == 1) else 'OFF'
- #print('output_vacuum: ', output_vacuum)
- '''
- # 傳 MQTT 給阿超, 阿超讓硬體動作, 將資料儲存到資料庫
- input_data = set_dry_input.query.order_by(text('datetime desc')).first()
- schedule_input_height = input_data.input_height
- schedule_input_entertime = input_data.input_entertime
- schedule_input_exittime = input_data.input_exittime
- schedule_tank_height = input_data.tank_height
- return render_template('dry_container.html', title='dry_container', **locals())
- elif request.method == 'POST':
- # 表單輸入處
- print('/dry_input_setting POST')
- set = set_dry_input()
- set.input_height = request.form['schedule_input_height']
- set.input_entertime = request.form['schedule_input_entertime']
- set.input_exittime = request.form['schedule_input_exittime']
- set.tank_height = request.form['schedule_tank_height']
- #將數據保存進資料庫 - 註冊
- db.session.add(set)
- # 手動提交,目的是為了獲取提交後的user的id
- db.session.commit()
- # 當user成功插入進資料庫之後,程序會自動將所有信息取出來在賦值給user
- # 完成登入的操作
- # setting = Set_dry_input.query.order_by(text('datetime desc')).first()
- #session['id'] = set.userID
- #session['uname'] = set.username
- return redirect('/dry_container')
- # 登入頁面的訪問路徑
- @main.route('/login', methods=['GET', 'POST'])
- def login_views():
- if request.method == 'GET':
- if 'id' in session and 'uname' in session and 'status' in session:
- return redirect('/')
- else:
- return render_template('sign_in.html')
- else:
- # 接收前端傳過來的資料
- username = request.form['username']
- password = request.form['password']
- # 使用接收的用戶和密碼到資料庫中查詢
- user = User.query.filter_by(
- username=username, password=password).first()
- # 如果用戶存在,將信息保存置session並重定向回首頁,否則重定向回登入頁
- if user:
- resp = redirect('/')
- # 判斷是否有記住密碼
- if 'rem' in request.form:
- userID = str(user.userID)
- max_age = 60*60*24*365
- status = str(user.status)
- print('status: ', status)
- # Rita 以秒為單位, 一年
- # Rita 功能和 expires 很像,但此參數並非所有瀏覽器均支持,所以建議使用 expires 參數。
- # Rita expires:指定 Cookie 的有效日期, 當過了有效日期後就不會儲存在瀏覽器
- resp.set_cookie("username", username, max_age=max_age)
- resp.set_cookie("userID", userID, max_age=max_age)
- resp.set_cookie("status", status, max_age=max_age)
- session['uname'] = user.username
- session['id'] = user.userID
- session['status'] = user.status
- return resp
- else:
- errMsg = "Wrong login or password"
- return render_template('sign_in.html', errMsg=errMsg)
- # 登入重設密碼的頁面
- # Rita reset_pwd1 - Email
- # Rita reset_pwd2 - New password / Confirm password
- @main.route('/reset_password', methods=['POST', 'GET'])
- def reset_password_views():
- if request.method == 'GET':
- if 'mail' in session:
- del session['mail']
- return render_template('reset_pwd1.html')
- else:
- # POST
- # 如果有id在session裡,代表從reset_pwd2過來的 ? 對, reset_pwd2 POST (但也有其他可能)
- if "mail" in session:
- new_pwd = request.form['new_pwd']
- confirm_pwd = request.form['confirm_pwd']
- # 判斷密碼是否一致
- if new_pwd == confirm_pwd:
- mail = session['mail']
- user = User.query.filter_by(mail=mail).first()
- print("user: ", user)
- print("user.password_before: ", user.password)
- print("new_pwd: ", new_pwd)
- user.password = new_pwd
- print("user.password_after: ", user.password)
- db.session.add(user)
- db.session.commit()
- del session['mail']
- # 修改完後回登入頁
- return redirect('/login')
- else:
- errMsg = "Passwords does not match"
- # Rita 前面的 errMsg 是指網頁上的 {{errMsg}} 位置
- return render_template('reset_pwd2.html', errMsg=errMsg)
- email = request.form['email']
- user = User.query.filter_by(mail=email).first()
- if user: # Rita 有找到對應 email
- session['mail'] = user.mail
- return render_template('reset_pwd2.html')
- else:
- errMsg = "Wrong email.Please try again"
- return render_template('reset_pwd1.html', errMsg=errMsg)
- # 註冊頁面的訪問路徑
- @main.route('/register', methods=['POST', "GET"])
- def register_views():
- if request.method == 'GET':
- return render_template('registration.html')
- else:
- # 獲取文本框的值並賦值給user實體對象
- user = User()
- user.firstname = request.form['firstname']
- user.lastname = request.form['lastname']
- user.mail = request.form['email']
- user.phone = request.form['phone']
- user.username = request.form['username']
- user.password = request.form['password']
- user.status = 8 # Rita app\models.py 設定 0:admin;1:new;9:disable [0906 更新] 0:admin;1:superuser;2:enduser;8:new;9:disable
- #將數據保存進資料庫 - 註冊
- db.session.add(user)
- # 手動提交,目的是為了獲取提交後的user的id
- db.session.commit()
- # 當user成功插入進資料庫之後,程序會自動將所有信息取出來在賦值給user
- # 完成登入的操作
- user = User.query.filter_by(username=user.username).first()
- session['status'] = user.status
- session['id'] = user.userID
- session['uname'] = user.username
- return redirect('/')
- # 驗證email訪問路徑
- @main.route('/check_email')
- def check_email_views():
- email = request.args['email']
- user = User.query.filter_by(mail=email).first()
- if user:
- # Rita email 錯誤時會顯示 Incorrect email address
- result = {"errMsg": " "}
- else:
- result = {"pass": " "}
- return json.dumps(result)
- # 驗證username訪問路徑
- @main.route('/check_username')
- def check_username_views():
- username = request.args['username']
- user = User.query.filter_by(username=username).first()
- if user:
- result = {"errMsg": " "}
- else:
- result = {"pass": " "}
- return json.dumps(result)
- # 咖啡貨櫃的訪問路徑
- @main.route('/cargo_list', methods=['GET', 'POST'])
- def cargo_list_views():
- username = session['uname']
- if request.method == 'GET':
- return render_template('cargo_list.html', params=locals())
- else:
- pass
- # 貨櫃1的訪問路徑
- @main.route('/cargo1', methods=['GET', 'POST'])
- def cargo1_views():
- username = session['uname']
- if request.method == 'GET':
- return render_template('cargo1.html', params=locals())
- else:
- pass
- # 貨櫃1排程的訪問路徑
- @main.route('/cargo1_schedule', methods=['GET', 'POST'])
- def cargo1_schedule_views():
- username = session['uname']
- if request.method == 'GET':
- # 將已儲存的排程資料傳給前端
- # 進豆閥
- try:
- bean = BeanValve.query.order_by(text('datetime desc')).first()
- datetime = bean.datetime
- beans = BeanValve.query.filter_by(
- datetime=datetime).all()
- except Exception as e:
- pass
- # 清洗機
- try:
- wash = WashMachine.query.order_by(text('datetime desc')).first()
- datetime = wash.datetime
- washes = WashMachine.query.filter_by(datetime=datetime).all()
- except Exception as e:
- pass
- # 輸送帶1
- try:
- belt1 = ConveyorBelt1.query.order_by(text('datetime desc')).first()
- datetime = belt1.datetime
- belts1 = ConveyorBelt1.query.filter_by(datetime=datetime).all()
- except Exception as e:
- pass
- # ///////////////////////////////////////////////////////////////////////////////////////////
- # 消毒機
- try:
- disinfect = Cargo1Disinfect.query.order_by(
- text('datetime desc')).first()
- datetime = disinfect.datetime
- disinfects = Cargo1Disinfect.query.filter_by(
- datetime=datetime).all()
- except Exception as e:
- pass
- # 色選機
- try:
- color = ColorMachine.query.order_by(text('datetime desc')).first()
- datetime = color.datetime
- colors = ColorMachine.query.filter_by(datetime=datetime).all()
- except Exception as e:
- pass
- # 輸送帶2
- try:
- belt2 = ConveyorBelt2.query.order_by(text('datetime desc')).first()
- datetime = belt2.datetime
- belts2 = ConveyorBelt2.query.filter_by(datetime=datetime).all()
- except Exception as e:
- pass
- # 去皮機
- try:
- peeling = PeelingMachine.query.order_by(
- text('datetime desc')).first()
- datetime = peeling.datetime
- peelings = PeelingMachine.query.filter_by(datetime=datetime).all()
- except Exception as e:
- pass
- # 輸送帶3
- try:
- belt3 = ConveyorBelt3.query.order_by(text('datetime desc')).first()
- datetime = belt3.datetime
- belts3 = ConveyorBelt3.query.filter_by(datetime=datetime).all()
- except Exception as e:
- pass
- return render_template('cargo1_schedule.html', params=locals())
- else:
- current_time = dt.now()
- # 循環從前端提交過來的資料
- for i in request.form:
- # 進豆閥
- if i[:10] == 'inletValve':
- if i[:19] == 'inletValve_duration':
- bean = BeanValve()
- bean.duration = request.form[i]
- elif i[:18] == 'inletValve_from_hr':
- iv_from_hr = request.form[i]
- elif i[:19] == 'inletValve_from_min':
- iv_from_min = request.form[i]
- bean.start = iv_from_hr + ":" + iv_from_min
- elif i[:16] == 'inletValve_to_hr':
- iv_to_hr = request.form[i]
- elif i[:17] == 'inletValve_to_min':
- iv_to_min = request.form[i]
- bean.end = iv_to_hr + ":" + iv_to_min
- bean.datetime = current_time
- db.session.add(bean)
- db.session.commit()
- # 清洗機
- elif i[:4] == 'wash':
- if i[:13] == 'wash_duration':
- wash = WashMachine()
- wash.duration = request.form[i]
- elif i[:12] == 'wash_from_hr':
- wash_from_hr = request.form[i]
- elif i[:13] == 'wash_from_min':
- wash_from_min = request.form[i]
- wash.start = wash_from_hr + ":" + wash_from_min
- elif i[:10] == 'wash_to_hr':
- wash_to_hr = request.form[i]
- elif i[:11] == 'wash_to_min':
- wash_to_min = request.form[i]
- wash.end = wash_to_hr + ":" + wash_to_min
- wash.datetime = current_time
- db.session.add(wash)
- db.session.commit()
- # 輸送帶1
- elif i[:5] == 'belt1':
- if i[:14] == 'belt1_duration':
- belt1 = ConveyorBelt1()
- belt1.duration = request.form[i]
- elif i[:13] == 'belt1_from_hr':
- belt1_from_hr = request.form[i]
- elif i[:14] == 'belt1_from_min':
- belt1_from_min = request.form[i]
- belt1.start = belt1_from_hr + ":" + belt1_from_min
- elif i[:11] == 'belt1_to_hr':
- belt1_to_hr = request.form[i]
- elif i[:12] == 'belt1_to_min':
- belt1_to_min = request.form[i]
- belt1.end = belt1_to_hr + ":" + belt1_to_min
- belt1.datetime = current_time
- db.session.add(belt1)
- db.session.commit()
- # 消毒
- elif i[:9] == 'disinfect':
- if i[:18] == 'disinfect_duration':
- disinfect = Cargo1Disinfect()
- disinfect.duration = request.form[i]
- elif i[:17] == 'disinfect_from_hr':
- di_from_hr = request.form[i]
- elif i[:18] == 'disinfect_from_min':
- di_from_min = request.form[i]
- disinfect.start = di_from_hr + ":" + di_from_min
- elif i[:15] == 'disinfect_to_hr':
- di_to_hr = request.form[i]
- elif i[:16] == 'disinfect_to_min':
- di_to_min = request.form[i]
- disinfect.end = di_to_hr + ":" + di_to_min
- disinfect.datetime = current_time
- db.session.add(disinfect)
- db.session.commit()
- # 色選機
- elif i[:5] == 'color':
- if i[:14] == 'color_duration':
- color = ColorMachine()
- color.duration = request.form[i]
- elif i[:13] == 'color_from_hr':
- color_from_hr = request.form[i]
- elif i[:14] == 'color_from_min':
- color_from_min = request.form[i]
- color.start = color_from_hr + ":" + color_from_min
- elif i[:11] == 'color_to_hr':
- color_to_hr = request.form[i]
- elif i[:12] == 'color_to_min':
- color_to_min = request.form[i]
- color.end = color_to_hr + ":" + color_to_min
- color.datetime = current_time
- db.session.add(color)
- db.session.commit()
- # 輸送帶2
- elif i[:5] == 'belt2':
- if i[:14] == 'belt2_duration':
- belt2 = ConveyorBelt2()
- belt2.duration = request.form[i]
- elif i[:13] == 'belt2_from_hr':
- belt2_from_hr = request.form[i]
- elif i[:14] == 'belt2_from_min':
- belt2_from_min = request.form[i]
- belt2.start = belt2_from_hr + ":" + belt2_from_min
- elif i[:11] == 'belt2_to_hr':
- belt2_to_hr = request.form[i]
- elif i[:12] == 'belt2_to_min':
- belt2_to_min = request.form[i]
- belt2.end = belt2_to_hr + ":" + belt2_to_min
- belt2.datetime = current_time
- db.session.add(belt2)
- db.session.commit()
- # 去皮機
- elif i[:6] == 'peeled':
- if i[:15] == 'peeled_duration':
- peeling = PeelingMachine()
- peeling.duration = request.form[i]
- elif i[:14] == 'peeled_from_hr':
- peeled_from_hr = request.form[i]
- elif i[:15] == 'peeled_from_min':
- peeled_from_min = request.form[i]
- peeling.start = peeled_from_hr + ":" + peeled_from_min
- elif i[:12] == 'peeled_to_hr':
- peeled_to_hr = request.form[i]
- elif i[:13] == 'peeled_to_min':
- peeled_to_min = request.form[i]
- peeling.end = peeled_to_hr + ":" + peeled_to_min
- peeling.datetime = current_time
- db.session.add(peeling)
- db.session.commit()
- # 輸送帶3
- elif i[:5] == 'belt3':
- if i[:14] == 'belt3_duration':
- belt3 = ConveyorBelt3()
- belt3.duration = request.form[i]
- elif i[:13] == 'belt3_from_hr':
- belt3_from_hr = request.form[i]
- elif i[:14] == 'belt3_from_min':
- belt3_from_min = request.form[i]
- belt3.start = belt3_from_hr + ":" + belt3_from_min
- elif i[:11] == 'belt3_to_hr':
- belt3_to_hr = request.form[i]
- elif i[:12] == 'belt3_to_min':
- belt3_to_min = request.form[i]
- belt3.end = belt3_to_hr + ":" + belt3_to_min
- belt3.datetime = current_time
- db.session.add(belt3)
- db.session.commit()
- return render_template('cargo1.html', params=locals())
- # 貨櫃2的訪問路徑
- @main.route('/cargo2', methods=['GET', 'POST'])
- def cargo2_views():
- username = session['uname']
- if request.method == 'GET':
- return render_template('cargo2.html', params=locals())
- else:
- pass
- # 貨櫃2排程的發酵槽訪問路徑
- @main.route('/cargo2_schedule_tanks', methods=['GET', 'POST'])
- def cargo2_schedule_tanks_views():
- username = session['uname']
- if request.method == 'GET':
- return render_template('cargo2_schedule_tanks.html', params=locals())
- else:
- pass
- # 貨櫃2排程發酵槽的清單訪問路徑
- @main.route('/cargo2_schedule/<tid>', methods=['GET', 'POST'])
- def cargo2_schedule_views(tid):
- username = session['uname']
- if request.method == 'GET':
- # 將已儲存的排程資料傳給前端
- # 打菌
- try:
- bacteria = Bacteria.query.filter_by(tank_num=int(
- tid)).order_by(text('datetime desc')).first()
- datetime = bacteria.datetime
- bacterias = Bacteria.query.filter_by(datetime=datetime).all()
- except Exception as e:
- pass
- # 消毒
- try:
- disinfect = Cargo2Disinfect.query.filter_by(
- tank_num=int(tid)).order_by(text('datetime desc')).first()
- datetime = disinfect.datetime
- disinfects = Cargo2Disinfect.query.filter_by(
- datetime=datetime).all()
- except Exception as e:
- pass
- # 加熱
- try:
- heating = Heating.query.filter_by(tank_num=int(
- tid)).order_by(text('datetime desc')).first()
- datetime = heating.datetime
- heatings = Heating.query.filter_by(datetime=datetime).all()
- except Exception as e:
- pass
- # 攪拌
- try:
- stir = Stir.query.filter_by(tank_num=int(tid)).order_by(
- text('datetime desc')).first()
- datetime = stir.datetime
- stirs = Stir.query.filter_by(datetime=datetime).all()
- except Exception as e:
- pass
- # 注水
- try:
- water = WaterInjection.query.filter_by(
- tank_num=int(tid)).order_by(text('datetime desc')).first()
- datetime = water.datetime
- waters = WaterInjection.query.filter_by(datetime=datetime).all()
- except Exception as e:
- pass
- # 開上閥
- try:
- top = TopValve.query.filter_by(tank_num=int(
- tid)).order_by(text('datetime desc')).first()
- datetime = top.datetime
- tops = TopValve.query.filter_by(datetime=datetime).all()
- except Exception as e:
- pass
- # 開下閥
- try:
- bottom = BottomValve.query.filter_by(tank_num=int(
- tid)).order_by(text('datetime desc')).first()
- datetime = bottom.datetime
- bottoms = BottomValve.query.filter_by(datetime=datetime).all()
- except Exception as e:
- pass
- # 溫度
- try:
- tem = Temperature.query.filter_by(tank_num=int(
- tid)).order_by(text('datetime desc')).first()
- datetime = tem.datetime
- tems = Temperature.query.filter_by(datetime=datetime).all()
- except Exception as e:
- pass
- return render_template('cargo2_schedule.html', params=locals())
- else:
- current_time = dt.now()
- # 循環從前端提交過來的資料
- for i in request.form:
- # 打菌
- if i[:8] == 'bacteria':
- if i[:17] == 'bacteria_duration':
- bacteria = Bacteria()
- bacteria.duration = request.form[i]
- elif i[:16] == 'bacteria_from_hr':
- bac_from_hr = request.form[i]
- elif i[:17] == 'bacteria_from_min':
- bac_from_min = request.form[i]
- bacteria.start = bac_from_hr + ":" + bac_from_min
- elif i[:14] == 'bacteria_to_hr':
- bac_to_hr = request.form[i]
- elif i[:15] == 'bacteria_to_min':
- bac_to_min = request.form[i]
- bacteria.end = bac_to_hr + ":" + bac_to_min
- bacteria.datetime = current_time
- bacteria.tank_num = int(tid)
- db.session.add(bacteria)
- db.session.commit()
- # 消毒
- elif i[:9] == 'disinfect':
- if i[:18] == 'disinfect_duration':
- disinfect = Cargo2Disinfect()
- disinfect.duration = request.form[i]
- elif i[:17] == 'disinfect_from_hr':
- di_from_hr = request.form[i]
- elif i[:18] == 'disinfect_from_min':
- di_from_min = request.form[i]
- disinfect.start = di_from_hr + ":" + di_from_min
- elif i[:15] == 'disinfect_to_hr':
- di_to_hr = request.form[i]
- elif i[:16] == 'disinfect_to_min':
- di_to_min = request.form[i]
- disinfect.end = di_to_hr + ":" + di_to_min
- disinfect.datetime = current_time
- disinfect.tank_num = int(tid)
- db.session.add(disinfect)
- db.session.commit()
- # 加熱
- elif i[:7] == 'heating':
- if i[:16] == 'heating_duration':
- heating = Heating()
- heating.duration = request.form[i]
- elif i[:15] == 'heating_from_hr':
- heat_from_hr = request.form[i]
- elif i[:16] == 'heating_from_min':
- heat_from_min = request.form[i]
- heating.start = heat_from_hr + ":" + heat_from_min
- elif i[:13] == 'heating_to_hr':
- heat_to_hr = request.form[i]
- elif i[:14] == 'heating_to_min':
- heat_to_min = request.form[i]
- heating.end = heat_to_hr + ":" + heat_to_min
- heating.datetime = current_time
- heating.tank_num = int(tid)
- db.session.add(heating)
- db.session.commit()
- # 攪拌
- elif i[:4] == 'stir':
- if i[:13] == 'stir_duration':
- stir = Stir()
- stir.duration = request.form[i]
- elif i[:12] == 'stir_from_hr':
- stir_from_hr = request.form[i]
- elif i[:13] == 'stir_from_min':
- stir_from_min = request.form[i]
- stir.start = stir_from_hr + ":" + stir_from_min
- elif i[:10] == 'stir_to_hr':
- stir_to_hr = request.form[i]
- elif i[:11] == 'stir_to_min':
- stir_to_min = request.form[i]
- stir.end = stir_to_hr + ":" + stir_to_min
- stir.datetime = current_time
- stir.tank_num = int(tid)
- db.session.add(stir)
- db.session.commit()
- # 注水
- elif i[:5] == 'water':
- if i[:14] == 'water_duration':
- water = WaterInjection()
- water.duration = request.form[i]
- elif i[:13] == 'water_from_hr':
- water_from_hr = request.form[i]
- elif i[:14] == 'water_from_min':
- water_from_min = request.form[i]
- water.start = water_from_hr + ":" + water_from_min
- elif i[:11] == 'water_to_hr':
- water_to_hr = request.form[i]
- elif i[:12] == 'water_to_min':
- water_to_min = request.form[i]
- water.end = water_to_hr + ":" + water_to_min
- water.datetime = current_time
- water.tank_num = int(tid)
- db.session.add(water)
- db.session.commit()
- # 開上閥
- elif i[:9] == 'highValve':
- if i[:18] == 'highValve_duration':
- top = TopValve()
- top.duration = request.form[i]
- elif i[:17] == 'highValve_from_hr':
- h_valve_from_hr = request.form[i]
- elif i[:18] == 'highValve_from_min':
- h_valve_from_min = request.form[i]
- top.start = h_valve_from_hr + ":" + h_valve_from_min
- elif i[:15] == 'highValve_to_hr':
- h_valve_to_hr = request.form[i]
- elif i[:16] == 'highValve_to_min':
- h_valve_to_min = request.form[i]
- top.end = h_valve_to_hr + ":" + h_valve_to_min
- top.datetime = current_time
- top.tank_num = int(tid)
- db.session.add(top)
- db.session.commit()
- # 開下閥
- elif i[:8] == 'lowValve':
- if i[:17] == 'lowValve_duration':
- bottom = BottomValve()
- bottom.duration = request.form[i]
- elif i[:16] == 'lowValve_from_hr':
- l_valve_from_hr = request.form[i]
- elif i[:17] == 'lowValve_from_min':
- l_valve_from_min = request.form[i]
- bottom.start = l_valve_from_hr + ":" + l_valve_from_min
- elif i[:14] == 'lowValve_to_hr':
- l_valve_to_hr = request.form[i]
- elif i[:15] == 'lowValve_to_min':
- l_valve_to_min = request.form[i]
- bottom.end = l_valve_to_hr + ":" + l_valve_to_min
- bottom.datetime = current_time
- bottom.tank_num = int(tid)
- db.session.add(bottom)
- db.session.commit()
- # 溫度
- elif i[:3] == 'tem':
- if i[:12] == 'tem_duration':
- tem = Temperature()
- tem.duration = request.form[i]
- elif i[:11] == 'tem_from_hr':
- tem_from_hr = request.form[i]
- elif i[:12] == 'tem_from_min':
- tem_from_min = request.form[i]
- tem.start = tem_from_hr + ":" + tem_from_min
- elif i[:9] == 'tem_to_hr':
- tem_to_hr = request.form[i]
- elif i[:10] == 'tem_to_min':
- tem_to_min = request.form[i]
- tem.end = tem_to_hr + ":" + tem_to_min
- tem.datetime = current_time
- tem.tank_num = int(tid)
- db.session.add(tem)
- db.session.commit()
- return render_template('cargo2.html', params=locals())
- # 貨櫃2感測器的發酵槽訪問路徑
- @main.route('/cargo2_sensor_tanks', methods=['GET', 'POST'])
- def cargo2_sensor_tanks_views():
- username = session['uname']
- if request.method == 'GET':
- return render_template('cargo2_sensor_tanks.html', params=locals())
- else:
- pass
- # 貨櫃2感測器發酵槽的清單訪問路徑
- @main.route('/cargo2_sensor/<tid>', methods=['GET', 'POST'])
- def s_tank_views(tid):
- # 判斷用戶是否已關閉瀏覽器或登出後,在訪問這個route,如果沒有session就回登入頁
- try:
- username = session['uname']
- except KeyError:
- return redirect('/')
- if request.method == 'GET':
- # Rita 網頁端 params.tank_tem.tem
- # Coffee/CoffeeProject/app/templates/cargo2_sensor.html
- tank_tem = TankTemSensor.query.filter_by(tank_num=int(tid)).order_by(text('datetime desc')).first()
- tank_ph = TankPHSensor.query.filter_by(tank_num=int(tid)).order_by(text('datetime desc')).first()
- tank_ec = TankECSensor.query.filter_by(tank_num=int(tid)).order_by(text('datetime desc')).first()
- tank_sonic = TankSonicSensor.query.filter_by(tank_num=int(tid)).order_by(text('datetime desc')).first()
- return render_template('cargo2_sensor.html', params=locals())
- else:
- pass
- # 貨櫃2感測器發酵槽歷史數據的訪問路徑
- @main.route('/history_data', methods=['GET', 'POST'])
- def history_data_views():
- if request.method == 'GET':
- # json
- # tid:tid_D1
- # sensor_name:soil_Temp
- # avg:1
- # max:1
- # min:1
- # time-interval:month
- # date-start:2021-07-01
- # date-end:2021-07-28
- info = request.args.to_dict()
- evt = info['evt']
- avg = int(info['avg'])
- max = int(info['max'])
- min = int(info['min'])
- time_interval = info['time-interval']
- print(info)
- # Rita {'evt': '1-溫濕度', 'avg': '1', 'max': '0', 'min': '0', 'time-interval': 'month',
- # 'date-start': '2021-05-04', 'date-end': '2021-05-18'} {'all': [], 'avg': []}
- # print(info)
- # {'evt': '1-溫濕度', 'avg': '1', 'max': '0', 'min': '0', 'time-interval': 'hour', 'date-start': '2021-01-01', 'date-end': '2021-07-27'}
- # print(D)
- # {'all': [['2021-Feb-19_16:46:10', '24.4'], ['2021-Feb-19_16:46:20', '24.4'], ['2021-Feb-19_16:46:30', '24.4'], ['2021-Feb-19_16:46:41', '24.4'], ['2021-Feb-19_16:46:50', '24.4'], ['2021-Feb-19_16:47:00', '24.4'], ['2021-Feb-19_16:47:10', '24.4'], ['2021-Feb-19_16:47:20', '24.4'], ['2021-Feb-19_16:47:30', '24.4'], ['2021-Feb-19_16:47:40', '24.5'], ['2021-Feb-19_16:47:50', '24.5'], ['2021-Feb-19_16:48:00', '24.5'], ['2021-Feb-19_16:48:10', '24.5'], ['2021-Feb-19_16:48:20', '24.5'], ['2021-Feb-19_16:48:29', '24.5'], ['2021-Feb-19_16:48:39', '24.5'], ['2021-Feb-19_16:48:50', '24.5'], ['2021-Feb-19_16:49:00', '24.5'], ['2021-Feb-19_16:49:10', '24.5'], ['2021-Feb-19_16:49:19', '24.5'], ['2021-Feb-19_16:49:29', '24.5'], ['2021-Feb-19_16:49:39', '24.5'], ['2021-Feb-19_16:49:49', '24.5'], ['2021-Feb-19_16:49:59', '24.5'], ['2021-Feb-19_16:50:10', '24.5'], ['2021-Feb-19_16:50:19', '24.5'], ['2021-Feb-19_16:50:29', '24.5'], ['2021-Feb-19_16:50:39', '24.5'], ['2021-Feb-19_16:50:49', '24.5'], ['2021-Feb-19_16:50:59', '24.5'], ['2021-Feb-19_18:07:10', '25.3'], ['2021-Feb-19_18:07:20', '25.3'], ['2021-Feb-19_18:07:30', '25.3'], ['2021-Feb-19_18:07:40', '25.3'], ['2021-Feb-19_18:07:49', '25.3'], ['2021-Feb-19_18:07:59', '25.3'], ['2021-Feb-19_18:08:10', '25.3'], ['2021-Feb-19_18:08:20', '25.3'], ['2021-Feb-19_18:08:30', '25.2'], ['2021-Feb-19_18:08:39', '25.2'], ['2021-Feb-19_18:08:49', '25.2']],
- # 'avg': [['2021-02-19 16:00:00', '24.5'], ['2021-02-19 18:00:00', '25.3']]}
- # 192.168.50.65 - - [27/Jul/2021 11:57:23] "GET /history_data?evt=1-溫濕度&avg=1&max=0&min=0&time-interval=hour&date-start=2021-01-01&date-end=2021-07-27 HTTP/1.1" 200 -
- date_start = info['date-start']
- date_end_list = info['date-end'].split('-') # 先把 'date-end' 的 '2021-05-18' 拆成 ['2021', '05', '18']
- date_end_list[2] = str(int(date_end_list[2]) + 1) # 18 + 1 = 19 再轉成 str → '19'
- date_end = '-'.join(date_end_list) # '2021-05-19'
- tank_num = evt.split('-')[0] # 1
- sensor = evt.split('-')[1] # 溫濕度
- L = []
- D = {}
- maxData = []
- minData = []
- avgData = []
- def sensorData(data_name): # data_name = "tem"
- def dataResample(time_interval, how, data_name): # dataResample('month', how???, "tem") # 下方 "hour"
- interval = 0
- # 設置resample的第一個參數,要按照逐月、逐日或逐時
- if time_interval == 'month':
- interval = "M" # interval = "M"
- elif time_interval == 'day':
- interval = "D"
- elif time_interval == 'hour':
- interval = "H"
- if how == "max":
- # data = df.resample(interval, how={data_name:how})
- # 最新版的pandas
- data = df.resample(interval).max() # 取樣頻率 'H'
- # 刪除有 NaN 的列, any 任何一欄位為空則刪 (all 全部欄位為空值才刪)
- data = data.dropna(axis=0, how='any')
-
- if time_interval == ('hour' or 'day'):
- data.index = pd.to_datetime(
- data.index, format='%Y-%b-%d_%H:%M:%S') # 将数据类型转换为日期类型
- for a in range(0, len(data.index)):
- l = []
- # 如果是逐時,才顯示小時分秒
- if time_interval == 'hour':
- l.append(str(data.index[a]))
- else:
- l.append(str(data.index[a]).split(' ')[0])
- l.append(str(data[data_name][a]))
- maxData.append(l)
- D['max'] = maxData
- elif how == "mean":
- # data = df.resample(interval, how={data_name:how})
- # 最新版的pandas
- data = df.resample(interval).mean()
- # 刪除具有NaN的值
- data = data.dropna(axis=0, how='any')
- # 將平均數取自小數1位
- data = data.round({data_name: 1})
- for a in range(0, len(data.index)):
- l = []
- # 如果是逐時,才顯示小時分秒
- if time_interval == 'hour':
- l.append(str(data.index[a]))
- else:
- l.append(str(data.index[a]).split(' ')[0])
- l.append(str(data[data_name][a]))
- avgData.append(l)
- D['avg'] = avgData
- elif how == "min":
- # data = df.resample(interval, how={data_name:how})
- # 最新版的pandas
- data = df.resample(interval).min()
- # 刪除具有NaN的值
- data = data.dropna(axis=0, how='any')
- for a in range(0, len(data.index)):
- # print(data.index[a])
- l = []
- # 如果是逐時,才顯示小時分秒
- if time_interval == 'hour':
- l.append(str(data.index[a]))
- else:
- l.append(str(data.index[a]).split(' ')[0])
- l.append(str(data[data_name][a]))
- minData.append(l)
- D['min'] = minData
- df = pd.DataFrame(L, columns=["datetime", data_name]) # 指定欄標籤名稱 為 ["datetime", "tem"]
- df['datetime'] = pd.to_datetime(
- df['datetime'], format='%Y-%b-%d_%H:%M:%S') # 将数据类型转换为日期类型
- # print(df['datetime']) # 0 2021-02-19 16:46:10
- # 1 2021-02-19 16:46:20
- # 2 2021-02-19 16:46:30
- # 3 2021-02-19 16:46:41
- df[data_name] = df[data_name].astype(float)
- df = df.set_index('datetime') # 将datetime设置为index
- # print(df) # datetime tem
- # 2021-02-19 16:46:10 24.4
- # 2021-02-19 16:46:20 24.4
- if time_interval == 'month':
- if max:
- dataResample(time_interval, "max", data_name)
- if avg:
- dataResample(time_interval, "mean", data_name)
- if min:
- dataResample(time_interval, "min", data_name)
- elif time_interval == 'day':
- if max:
- dataResample(time_interval, "max", data_name)
- if avg:
- dataResample(time_interval, "mean", data_name)
- if min:
- dataResample(time_interval, "min", data_name)
- elif time_interval == 'hour':
- if max:
- dataResample(time_interval, "max", data_name)
- if avg:
- dataResample(time_interval, "mean", data_name)
- if min:
- dataResample(time_interval, "min", data_name)
- if sensor == '溫濕度':
- # tank_tem = TankTemSensor.query.filter_by(tank_num=int(tank_num)).order_by(text('datetime desc')).all()
- # [7/27 Benson] tank_tem = TankTemSensor.query.filter_by(tank_num=int(tank_num)).filter(TankTemSensor.datetime.between(date_start, date_end)).all()
- tank_tem = dry_tank_SHT11.query.filter(dry_tank_SHT11.datetime.between(date_start, date_end)).all()
- # .filter_by(tank_num="D"+tank_num)
- for tem in tank_tem:
- l = [] # l = []
- time = dt.strftime(tem.datetime, '%Y-%b-%d_%H:%M:%S') # time = '2021-Feb-19_16:46:10' 轉換時間格式
- # time = dt.strftime(tem.datetime, '%Y-%m-%d')
- l.append(time) # l = ['2021-Feb-19_16:46:10']
- #l.append(tem.tem) # l = ['2021-Feb-19_16:46:10', '24.4']
- l.append(tem.SHT11_Temp)
- L.append(l) # L = [['2021-Feb-19_16:46:10', '24.4']]
- # print(L)
- D['all'] = L # D = {'all': [['2021-Feb-19_16:46:10', '24.4']]} # all 所有符合數據
- sensorData("tem")
- elif sensor == '酸鹼值':
- tank_ph = TankPHSensor.query.filter_by(tank_num=int(tank_num)).filter(
- TankPHSensor.datetime.between(date_start, date_end)).all()
- for ph in tank_ph:
- l = []
- time = dt.strftime(ph.datetime, '%Y-%b-%d_%H:%M:%S')
- # time = dt.strftime(tem.datetime, '%Y-%m-%d')
- l.append(time)
- l.append(ph.ph)
- L.append(l)
- # print(L)
- D['all'] = L
- sensorData("ph")
- elif sensor == 'EC值':
- tank_ec = TankECSensor.query.filter_by(tank_num=int(tank_num)).filter(
- TankECSensor.datetime.between(date_start, date_end)).all()
- for ec in tank_ec:
- l = []
- time = dt.strftime(ec.datetime, '%Y-%b-%d_%H:%M:%S')
- # time = dt.strftime(tem.datetime, '%Y-%m-%d')
- l.append(time)
- l.append(ec.ec)
- L.append(l)
- # print(L)
- D['all'] = L
- sensorData("ec")
- elif sensor == '超音波':
- tank_sonic = TankSonicSensor.query.filter_by(tank_num=int(tank_num)).filter(
- TankSonicSensor.datetime.between(date_start, date_end)).all()
- for sonic in tank_sonic:
- l = []
- time = dt.strftime(sonic.datetime, '%Y-%b-%d_%H:%M:%S')
- # time = dt.strftime(tem.datetime, '%Y-%m-%d')
- l.append(time)
- l.append(sonic.sonic)
- L.append(l)
- # print(L)
- D['all'] = L
- sensorData("sonic")
- print(D)
- return json.dumps(D)
- else:
- pass
- # Rita 改寫
- @main.route('/history_data_new', methods=['GET', 'POST'])
- def history_data_new_views():
- if request.method == 'GET':
- # json
- # tid:tid_D1
- # sensor_name:soil_Temp
- # avg:1
- # max:1
- # min:1
- # time-interval:month
- # date-start:2021-07-01
- # date-end:2021-07-28
- info = request.args.to_dict()
- # evt = info['evt']
- tid = info['tid']
- sensor_name = info['sensor_name']
- avg = int(info['avg'])
- max = int(info['max'])
- min = int(info['min'])
- time_interval = info['time-interval']
- print("info:", info)
- # Rita {'evt': '1-溫濕度', 'avg': '1', 'max': '0', 'min': '0', 'time-interval': 'month',
- # 'date-start': '2021-05-04', 'date-end': '2021-05-18'} {'all': [], 'avg': []}
- # print(info)
- # {'evt': '1-溫濕度', 'avg': '1', 'max': '0', 'min': '0', 'time-interval': 'hour', 'date-start': '2021-01-01', 'date-end': '2021-07-27'}
- # print(D)
- # {'all': [['2021-Feb-19_16:46:10', '24.4'], ['2021-Feb-19_16:46:20', '24.4'], ['2021-Feb-19_16:46:30', '24.4'], ['2021-Feb-19_16:46:41', '24.4'], ['2021-Feb-19_16:46:50', '24.4'], ['2021-Feb-19_16:47:00', '24.4'], ['2021-Feb-19_16:47:10', '24.4'], ['2021-Feb-19_16:47:20', '24.4'], ['2021-Feb-19_16:47:30', '24.4'], ['2021-Feb-19_16:47:40', '24.5'], ['2021-Feb-19_16:47:50', '24.5'], ['2021-Feb-19_16:48:00', '24.5'], ['2021-Feb-19_16:48:10', '24.5'], ['2021-Feb-19_16:48:20', '24.5'], ['2021-Feb-19_16:48:29', '24.5'], ['2021-Feb-19_16:48:39', '24.5'], ['2021-Feb-19_16:48:50', '24.5'], ['2021-Feb-19_16:49:00', '24.5'], ['2021-Feb-19_16:49:10', '24.5'], ['2021-Feb-19_16:49:19', '24.5'], ['2021-Feb-19_16:49:29', '24.5'], ['2021-Feb-19_16:49:39', '24.5'], ['2021-Feb-19_16:49:49', '24.5'], ['2021-Feb-19_16:49:59', '24.5'], ['2021-Feb-19_16:50:10', '24.5'], ['2021-Feb-19_16:50:19', '24.5'], ['2021-Feb-19_16:50:29', '24.5'], ['2021-Feb-19_16:50:39', '24.5'], ['2021-Feb-19_16:50:49', '24.5'], ['2021-Feb-19_16:50:59', '24.5'], ['2021-Feb-19_18:07:10', '25.3'], ['2021-Feb-19_18:07:20', '25.3'], ['2021-Feb-19_18:07:30', '25.3'], ['2021-Feb-19_18:07:40', '25.3'], ['2021-Feb-19_18:07:49', '25.3'], ['2021-Feb-19_18:07:59', '25.3'], ['2021-Feb-19_18:08:10', '25.3'], ['2021-Feb-19_18:08:20', '25.3'], ['2021-Feb-19_18:08:30', '25.2'], ['2021-Feb-19_18:08:39', '25.2'], ['2021-Feb-19_18:08:49', '25.2']],
- # 'avg': [['2021-02-19 16:00:00', '24.5'], ['2021-02-19 18:00:00', '25.3']]}
- # 192.168.50.65 - - [27/Jul/2021 11:57:23] "GET /history_data?evt=1-溫濕度&avg=1&max=0&min=0&time-interval=hour&date-start=2021-01-01&date-end=2021-07-27 HTTP/1.1" 200 -
- date_start = info['date-start']
- date_end_list = info['date-end'].split('-') # 先把 'date-end' 的 '2021-05-18' 拆成 ['2021', '05', '18']
- date_end_list[2] = str(int(date_end_list[2]) + 1) # 18 + 1 = 19 再轉成 str → '19'
- date_end = '-'.join(date_end_list) # '2021-05-19'
- # tank_num = evt.split('-')[0] # 1
- # sensor = evt.split('-')[1] # 溫濕度
- tank_num = tid # D1
- sensor = sensor_name # soil_Temp
- L = []
- D = {}
- maxData = []
- minData = []
- avgData = []
- def sensorData(data_name): # data_name = "tem"
- def dataResample(time_interval, how, data_name): # dataResample('month', how???, "tem") # 下方 "hour"
- interval = 0
- # 設置resample的第一個參數,要按照逐月、逐日或逐時
- if time_interval == 'month':
- interval = "M" # interval = "M"
- elif time_interval == 'day':
- interval = "D"
- elif time_interval == 'hour':
- interval = "H"
- if how == "max":
- # data = df.resample(interval, how={data_name:how})
- # 最新版的pandas
- data = df.resample(interval).max() # 取樣頻率 'H'
- # 刪除有 NaN 的列, any 任何一欄位為空則刪 (all 全部欄位為空值才刪)
- data = data.dropna(axis=0, how='any')
-
- if time_interval == ('hour' or 'day'):
- data.index = pd.to_datetime(
- data.index, format='%Y-%b-%d_%H:%M:%S') # 将数据类型转换为日期类型
- for a in range(0, len(data.index)):
- l = []
- # 如果是逐時,才顯示小時分秒
- if time_interval == 'hour':
- l.append(str(data.index[a]))
- else:
- l.append(str(data.index[a]).split(' ')[0])
- l.append(str(data[data_name][a]))
- maxData.append(l)
- D['max'] = maxData
- elif how == "mean":
- # data = df.resample(interval, how={data_name:how})
- # 最新版的pandas
- data = df.resample(interval).mean()
- # 刪除具有NaN的值
- data = data.dropna(axis=0, how='any')
- # 將平均數取自小數1位
- data = data.round({data_name: 1})
- for a in range(0, len(data.index)):
- l = []
- # 如果是逐時,才顯示小時分秒
- if time_interval == 'hour':
- l.append(str(data.index[a]))
- else:
- l.append(str(data.index[a]).split(' ')[0])
- l.append(str(data[data_name][a]))
- avgData.append(l)
- D['avg'] = avgData
- elif how == "min":
- # data = df.resample(interval, how={data_name:how})
- # 最新版的pandas
- data = df.resample(interval).min()
- # 刪除具有NaN的值
- data = data.dropna(axis=0, how='any')
- for a in range(0, len(data.index)):
- # print(data.index[a])
- l = []
- # 如果是逐時,才顯示小時分秒
- if time_interval == 'hour':
- l.append(str(data.index[a]))
- else:
- l.append(str(data.index[a]).split(' ')[0])
- l.append(str(data[data_name][a]))
- minData.append(l)
- D['min'] = minData
- df = pd.DataFrame(L, columns=["datetime", data_name]) # 指定欄標籤名稱 為 ["datetime", "tem"]
- df['datetime'] = pd.to_datetime(
- df['datetime'], format='%Y-%b-%d_%H:%M:%S') # 将数据类型转换为日期类型
- # print(df['datetime']) # 0 2021-02-19 16:46:10
- # 1 2021-02-19 16:46:20
- # 2 2021-02-19 16:46:30
- # 3 2021-02-19 16:46:41
- df[data_name] = df[data_name].astype(float)
- df = df.set_index('datetime') # 将datetime设置为index
- # print(df) # datetime tem
- # 2021-02-19 16:46:10 24.4
- # 2021-02-19 16:46:20 24.4
- if time_interval == 'month':
- if max:
- dataResample(time_interval, "max", data_name)
- if avg:
- dataResample(time_interval, "mean", data_name)
- if min:
- dataResample(time_interval, "min", data_name)
- elif time_interval == 'day':
- if max:
- dataResample(time_interval, "max", data_name)
- if avg:
- dataResample(time_interval, "mean", data_name)
- if min:
- dataResample(time_interval, "min", data_name)
- elif time_interval == 'hour':
- if max:
- dataResample(time_interval, "max", data_name)
- if avg:
- dataResample(time_interval, "mean", data_name)
- if min:
- dataResample(time_interval, "min", data_name)
- if tank_num[:2] == 'DI':
- # 乾燥入料儲豆槽
- if sensor == 'UltraSonic':
- tank_UltraSonic = dry_input_sensor.query.filter_by(tank_num=tank_num).filter(dry_input_sensor.datetime.between(date_start, date_end)).all()
- for sonic in tank_UltraSonic:
- l = []
- time = dt.strftime(sonic.datetime, '%Y-%b-%d_%H:%M:%S')
- l.append(time)
- l.append(sonic.UltraSonic)
- L.append(l)
- D['all'] = L
- sensorData("UltraSonic")
- elif tank_num[:2] == 'DO':
- # 乾燥出料儲豆槽
- if sensor == 'UltraSonic':
- tank_UltraSonic = dry_output_sensor.query.filter_by(tank_num=tank_num).filter(dry_output_sensor.datetime.between(date_start, date_end)).all()
- for sonic in tank_UltraSonic:
- l = []
- time = dt.strftime(sonic.datetime, '%Y-%b-%d_%H:%M:%S')
- l.append(time)
- l.append(sonic.UltraSonic)
- L.append(l)
- D['all'] = L
- sensorData("UltraSonic")
- elif tank_num[:1] == 'D':
- # 乾燥槽
- if sensor == 'SHT11_Temp':
- tank_tem = dry_tank_SHT11.query.filter_by(tank_num=tank_num).filter(dry_tank_SHT11.datetime.between(date_start, date_end)).all()
- for tem in tank_tem:
- l = [] # l = []
- time = dt.strftime(tem.datetime, '%Y-%b-%d_%H:%M:%S') # time = '2021-Feb-19_16:46:10' 轉換時間格式
- # time = dt.strftime(tem.datetime, '%Y-%m-%d')
- l.append(time) # l = ['2021-Feb-19_16:46:10']
- #l.append(tem.tem) # l = ['2021-Feb-19_16:46:10', '24.4']
- l.append(tem.SHT11_Temp)
- L.append(l) # L = [['2021-Feb-19_16:46:10', '24.4']]
- # print(L)
- D['all'] = L # D = {'all': [['2021-Feb-19_16:46:10', '24.4']]} # all 所有符合數據
- sensorData("SHT11_Temp")
- elif sensor == 'SHT11_Humidity':
- tank_hum = dry_tank_SHT11.query.filter_by(tank_num=tank_num).filter(dry_tank_SHT11.datetime.between(date_start, date_end)).all()
- for hum in tank_hum:
- l = []
- time = dt.strftime(hum.datetime, '%Y-%b-%d_%H:%M:%S')
- l.append(time)
- l.append(hum.SHT11_Humidity)
- L.append(l)
- D['all'] = L
- sensorData("SHT11_Humidity")
-
- elif sensor == 'UltraSonic':
- tank_UltraSonic = dry_tank_UltraSonic.query.filter_by(tank_num=tank_num).filter(dry_tank_UltraSonic.datetime.between(date_start, date_end)).all()
- for sonic in tank_UltraSonic:
- l = []
- time = dt.strftime(sonic.datetime, '%Y-%b-%d_%H:%M:%S')
- l.append(time)
- l.append(sonic.UltraSonic)
- L.append(l)
- D['all'] = L
- sensorData("UltraSonic")
- elif sensor == 'PA':
- tank_PA = dry_tank_PA.query.filter_by(tank_num=tank_num).filter(dry_tank_PA.datetime.between(date_start, date_end)).all()
- for pa in tank_PA:
- l = []
- time = dt.strftime(pa.datetime, '%Y-%b-%d_%H:%M:%S')
- l.append(time)
- l.append(pa.PA)
- L.append(l)
- D['all'] = L
- sensorData("PA")
-
- elif sensor == 'soil_Temp':
- tank_soiltemp = dry_tank_Soil.query.filter_by(tank_num=tank_num).filter(dry_tank_Soil.datetime.between(date_start, date_end)).all()
- for temp in tank_soiltemp:
- l = []
- time = dt.strftime(temp.datetime, '%Y-%b-%d_%H:%M:%S')
- l.append(time)
- l.append(temp.soil_Temp)
- L.append(l)
- D['all'] = L
- sensorData("soil_Temp")
- elif sensor == 'soil_Humidity':
- tank_soilHum = dry_tank_Soil.query.filter_by(tank_num=tank_num).filter(dry_tank_Soil.datetime.between(date_start, date_end)).all()
- for hum in tank_soilHum:
- l = []
- time = dt.strftime(hum.datetime, '%Y-%b-%d_%H:%M:%S')
- l.append(time)
- l.append(hum.soil_EC)
- L.append(l)
- D['all'] = L
- sensorData("soil_Humidity")
- elif sensor == 'soil_EC':
- tank_soilec = dry_tank_Soil.query.filter_by(tank_num=tank_num).filter(dry_tank_Soil.datetime.between(date_start, date_end)).all()
- for ec in tank_soilec:
- l = []
- time = dt.strftime(ec.datetime, '%Y-%b-%d_%H:%M:%S')
- # time = dt.strftime(tem.datetime, '%Y-%m-%d')
- l.append(time)
- l.append(ec.soil_EC)
- L.append(l)
- D['all'] = L
- sensorData("soil_EC")
- elif tank_num[:2] == 'FI':
- if sensor == 'UltraSonic':
- input_UltraSonic = ferment_input_UltraSonic.query.filter_by(tank_num=tank_num).filter(ferment_input_UltraSonic.datetime.between(date_start, date_end)).all()
- for UltraSonic in input_UltraSonic:
- l = []
- time = dt.strftime(UltraSonic.datetime, '%Y-%b-%d_%H:%M:%S')
- l.append(time)
- l.append(UltraSonic.UltraSonic)
- L.append(l)
- D['all'] = L
- sensorData("UltraSonic")
- elif tank_num[:2] == 'FO':
- if sensor == 'UltraSonic':
- output_UltraSonic = ferment_output_UltraSonic.query.filter_by(tank_num=tank_num).filter(ferment_output_UltraSonic.datetime.between(date_start, date_end)).all()
- for UltraSonic in output_UltraSonic:
- l = []
- time = dt.strftime(UltraSonic.datetime, '%Y-%b-%d_%H:%M:%S')
- l.append(time)
- l.append(UltraSonic.UltraSonic)
- L.append(l)
- D['all'] = L
- sensorData("UltraSonic")
- elif tank_num[:1] == 'F':
- if sensor == 'LiDAR':
- tank_LiDAR = ferment_tank_LiDAR.query.filter_by(tank_num = tank_num)\
- .filter(ferment_tank_LiDAR.datetime.between(date_start, date_end)).all()
- for LiDAR in tank_LiDAR:
- l = []
- time = dt.strftime(LiDAR.datetime, '%Y-%b-%d_%H:%M:%S')
- l.append(time)
- l.append(LiDAR.LiDAR)
- L.append(l)
- D['all'] = L
- sensorData("LiDAR")
- elif sensor == 'PressureWaterLevel':
- tank_PressureWaterLevel = ferment_tank_PressureWaterLevel.query.filter_by(tank_num = tank_num)\
- .filter(ferment_tank_PressureWaterLevel.datetime.between(date_start, date_end)).all()
- for PressureWaterLevel in tank_PressureWaterLevel:
- l = []
- time = dt.strftime(PressureWaterLevel.datetime, '%Y-%b-%d_%H:%M:%S')
- l.append(time)
- l.append(PressureWaterLevel.PressureWaterLevel)
- l.append('{:.2f}'.format((float(PressureWaterLevel.PressureWaterLevel) -10 -90.278)/9.4214))
- L.append(l)
- D['all'] = L
- sensorData("PressureWaterLevel")
- elif sensor == 'SHT11_Temp':
- tank_Temp = ferment_tank_SHT11.query.filter_by(tank_num = tank_num)\
- .filter(ferment_tank_SHT11.datetime.between(date_start, date_end)).all()
- for Temp in tank_Temp:
- l = []
- time = dt.strftime(Temp.datetime, '%Y-%b-%d_%H:%M:%S')
- l.append(time)
- l.append(Temp.SHT11_Temp)
- L.append(l)
- D['all'] = L
- sensorData("SHT11_Temp")
- elif sensor == 'SHT11_Humidity':
- tank_Humidity = ferment_tank_SHT11.query.filter_by(tank_num = tank_num)\
- .filter(ferment_tank_SHT11.datetime.between(date_start, date_end)).all()
- for Humidity in tank_Humidity:
- l = []
- time = dt.strftime(Humidity.datetime, '%Y-%b-%d_%H:%M:%S')
- l.append(time)
- l.append(Humidity.SHT11_Humidity)
- L.append(l)
- D['all'] = L
- sensorData("SHT11_Humidity")
- elif sensor == 'CO2':
- tank_CO2 = ferment_tank_CO2.query.filter_by(tank_num = tank_num)\
- .filter(ferment_tank_CO2.datetime.between(date_start, date_end)).all()
- for CO2 in tank_CO2:
- l = []
- time = dt.strftime(CO2.datetime, '%Y-%b-%d_%H:%M:%S')
- l.append(time)
- l.append(CO2.CO2)
- L.append(l)
- D['all'] = L
- sensorData("CO2")
- elif sensor == 'PH':
- tank_PH = ferment_tank_PH.query.filter_by(tank_num = tank_num)\
- .filter(ferment_tank_PH.datetime.between(date_start, date_end)).all()
- for PH in tank_PH:
- l = []
- time = dt.strftime(PH.datetime, '%Y-%b-%d_%H:%M:%S')
- l.append(time)
- l.append(PH.PH)
- L.append(l)
- D['all'] = L
- sensorData("PH")
- elif sensor == 'ORP':
- tank_ORP = ferment_tank_ORP.query.filter_by(tank_num = tank_num)\
- .filter(ferment_tank_ORP.datetime.between(date_start, date_end)).all()
- for ORP in tank_ORP:
- l = []
- time = dt.strftime(ORP.datetime, '%Y-%b-%d_%H:%M:%S')
- l.append(time)
- l.append(ORP.ORP)
- L.append(l)
- D['all'] = L
- sensorData("ORP")
- elif sensor == 'DO':
- tank_DO = ferment_tank_DO.query.filter_by(tank_num = tank_num)\
- .filter(ferment_tank_DO.datetime.between(date_start, date_end)).all()
- for DO in tank_DO:
- l = []
- time = dt.strftime(DO.datetime, '%Y-%b-%d_%H:%M:%S')
- l.append(time)
- l.append(DO.DO)
- L.append(l)
- D['all'] = L
- sensorData("DO")
- elif sensor == 'EC':
- tank_EC = ferment_tank_EC.query.filter_by(tank_num = tank_num)\
- .filter(ferment_tank_EC.datetime.between(date_start, date_end)).all()
- for EC in tank_EC:
- l = []
- time = dt.strftime(EC.datetime, '%Y-%b-%d_%H:%M:%S')
- l.append(time)
- l.append(EC.EC)
- L.append(l)
- D['all'] = L
- sensorData("EC")
- elif sensor == 'PA':
- tank_PA = ferment_tank_PA.query.filter_by(tank_num = tank_num)\
- .filter(ferment_tank_PA.datetime.between(date_start, date_end)).all()
- for PA in tank_PA:
- l = []
- time = dt.strftime(PA.datetime, '%Y-%b-%d_%H:%M:%S')
- l.append(time)
- l.append(PA.PA)
- L.append(l)
- D['all'] = L
- sensorData("PA")
-
-
- print(D)
- return json.dumps(D)
- else:
- pass
- # 貨櫃2致動器的發酵槽訪問路徑
- @main.route('/cargo2_actuator_tanks', methods=['GET', 'POST'])
- def cargo2_actuator_tanks_views():
- username = session['uname']
- if request.method == 'GET':
- return render_template('cargo2_actuator_tanks.html', params=locals())
- else:
- pass
- # 貨櫃2致動器發酵槽的清單訪問路徑
- @main.route('/cargo2_actuator/<tid>', methods=['GET', 'POST'])
- def cargo2_actuator_views(tid):
- username = session['uname']
- if request.method == 'GET':
- return render_template('cargo2_actuator.html', params=locals())
- else:
- pass
- # 貨櫃3的訪問路徑
- @main.route('/cargo3', methods=['GET', 'POST'])
- def cargo3_views():
- username = session['uname']
- if request.method == 'GET':
- return render_template('cargo3.html', params=locals())
- else:
- pass
- # 貨櫃3排程的訪問路徑
- @main.route('/cargo3_schedule', methods=['GET', 'POST'])
- def cargo3_schedule_views():
- username = session['uname']
- if request.method == 'GET':
- # 將已儲存的排程資料傳給前端
- # 提升機
- try:
- hoist = Hoist.query.order_by(text('datetime desc')).first()
- datetime = hoist.datetime
- hoists = Hoist.query.filter_by(datetime=datetime).all()
- except Exception as e:
- pass
- # 烘乾機
- try:
- dryer = Dryer.query.order_by(text('datetime desc')).first()
- datetime = dryer.datetime
- dryers = Dryer.query.filter_by(datetime=datetime).all()
- except Exception as e:
- pass
- return render_template('cargo3_schedule.html', params=locals())
- else:
- # Rita: "POST /b_cargo3 HTTP/1.1" 404 -
- current_time = dt.now()
- # 循環從前端提交過來的資料
- for i in request.form:
- print('Rita test i :', i)
- # 堤升機
- if i[:5] == 'hoist':
- if i[:14] == 'hoist_duration':
- hoist = Hoist()
- hoist.duration = request.form[i]
- elif i[:13] == 'hoist_from_hr':
- ho_from_hr = request.form[i]
- elif i[:14] == 'hoist_from_min':
- ho_from_min = request.form[i]
- hoist.start = ho_from_hr + ":" + ho_from_min
- elif i[:11] == 'hoist_to_hr':
- ho_to_hr = request.form[i]
- elif i[:12] == 'hoist_to_min':
- ho_to_min = request.form[i]
- hoist.end = ho_to_hr + ":" + ho_to_min
- hoist.datetime = current_time
- db.session.add(hoist)
- db.session.commit()
- # 烘乾機
- elif i[:5] == 'dryer':
- if i[:14] == 'dryer_duration':
- dryer = Dryer()
- dryer.duration = request.form[i]
- elif i[:13] == 'dryer_from_hr':
- dry_from_hr = request.form[i]
- elif i[:14] == 'dryer_from_min':
- dry_from_min = request.form[i]
- dryer.start = dry_from_hr + ":" + dry_from_min
- elif i[:11] == 'dryer_to_hr':
- dry_to_hr = request.form[i]
- elif i[:12] == 'dryer_to_min':
- dry_to_min = request.form[i]
- dryer.end = dry_to_hr + ":" + dry_to_min
- dryer.datetime = current_time
- db.session.add(dryer)
- db.session.commit()
- return render_template('cargo3.html', params=locals())
- # 影像串流的訪問路徑
- @main.route('/video', methods=['GET', 'POST'])
- def video_views():
- username = session['uname']
- if request.method == 'GET':
- return render_template('video.html', params=locals())
- else:
- pass
- # 影像的訪問路徑
- @main.route('/learn', methods=['GET', 'POST'])
- def learn_views():
- username = session['uname']
- if request.method == 'GET':
- return render_template('learn.html', params=locals())
- else:
- pass
- # 獲取relay狀態路徑
- @main.route('/relay', methods=['GET', 'POST'])
- def relay_views():
- if request.method == 'GET':
- relay = Relay.query.order_by(text('datetime desc')).first()
- relay_status = relay.status
- return jsonify({"relay": relay_status})
- else:
- pass
- # 獲取脫皮機狀態路徑
- @main.route('/peel', methods=['GET', 'POST'])
- def peeling_views():
- if request.method == 'GET':
- peeling = PeelingMachineRPM.query.order_by(
- text('datetime desc')).first()
- peeling_rpm = peeling.rpm
- return jsonify({"peeling": peeling_rpm})
- else:
- pass
- # 退出的訪問路徑
- @main.route('/logout')
- def logout_views():
- if 'id' in session and 'uname' in session:
- del session['id']
- del session['uname']
- return redirect('/')
- @main.route("/udp_client", methods=['POST', 'GET'])
- def udp_views():
- # sl(0.5)
- global c_sock
- if request.method == 'GET':
- # def close():
- # global c_sock
- # sl(600)
- # c_sock.close()
- # c_sock = 0
- # print("c_sock is closing")
- max_length = 65000
- # max_length = 95000
- # lab1的IP
- host = "192.168.50.65"
- # lab2的IP
- # host = "192.168.51.160"
- port = 8000
- c_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- # t = threading.Thread(target=close)
- # t.daemon = True
- # t.start()
- print("test")
- # dict = request.args.to_dict()
- # nr = int(dict['nr'])
- # if nr == 1:
- # camara = 0
- # elif nr == 2:
- # camara = 'rtsp://admin:admin@192.168.50.182/av2_0'
- # elif nr == 3:
- # camara = 'rtsp://admin:abcd1234@192.168.51.101/av2_0'
- # 地下室小兵
- # cap = cv2.VideoCapture('rtsp://admin:abcd1234@192.168.51.48/av2_0')
- # 主機攝像頭
- # cap = cv2.VideoCapture(0)
- # 外面小兵
- # cap = cv2.VideoCapture('rtsp://admin:admin@192.168.50.182/av2_0')
- cap = cv2.VideoCapture('rtsp://192.168.50.182/av0_0')
- # cap = cv2.VideoCapture(0)
- # cap = cv2.VideoCapture(camara)
- ret, frame = cap.read()
- while ret:
- # compress frame
- frame = cv2.resize(frame, (550, 400), interpolation=cv2.INTER_AREA)
- retval, buffer = cv2.imencode(".jpg", frame)
- if retval:
- # convert to byte array
- buffer = buffer.tobytes()
- # get size of the frame
- buffer_size = len(buffer)
- num_of_packs = 1
- if buffer_size > max_length:
- num_of_packs = math.ceil(buffer_size / max_length)
- frame_info = {"packs": num_of_packs}
- # send the number of packs to be expected
- # print("Number of packs:", num_of_packs)
- c_sock.sendto(pickle.dumps(frame_info), (host, port))
- left = 0
- right = max_length
- for i in range(num_of_packs):
- # print("left:", left)
- # print("right:", right)
- # truncate data to send
- data = buffer[left:right]
- left = right
- right += max_length
- # send the frames accordingly
- c_sock.sendto(data, (host, port))
- ret, frame = cap.read()
- print("done")
- return "done"
- else:
- c_sock.shutdown(2)
- c_sock.close()
- c_sock = 0
- print("c_sock is closing")
- # 影像串流的路徑
- @main.route("/video_feed", methods=['POST', 'GET'])
- def video_feed_views():
- print("test2")
- global s_sock
- if request.method == 'GET':
- # 於10分鐘之後,自動關閉socket server
- # if s_sock == 0:
- # def socket_server_views():
- # global s_sock
- # print("test")
- # print(s_sock)
- # sl(600)
- # if s_sock != 0:
- # s_sock.close()
- # s_sock = 0
- # print('s_sock is closed')
- #
- # pool.submit(socket_server_views)
- host = "192.168.50.65"
- port = 8000
- max_length = 65540
- # max_length = 95540
- s_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- s_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- s_sock.bind((host, port))
- frame_info = None
- buffer = None
- frame = None
- encodedImage = None
- print("-> waiting for connection")
- # 影像生成器函數,將影像以jpg格式傳給前端
- def generate():
- while True:
- with lock:
- global s_sock, frame_info, buffer, frame, encodedImage
- if s_sock == 0:
- break
- data, address = s_sock.recvfrom(max_length)
- if len(data) < 100:
- frame_info = pickle.loads(data)
- if frame_info:
- nums_of_packs = frame_info["packs"]
- for i in range(nums_of_packs):
- if s_sock == 0:
- break
- data, address = s_sock.recvfrom(max_length)
- if i == 0:
- buffer = data
- else:
- buffer += data
- frame = np.frombuffer(buffer, dtype=np.uint8)
- frame = frame.reshape(frame.shape[0], 1)
- frame = cv2.imdecode(frame, cv2.IMREAD_UNCHANGED)
- # print(frame)
- # 如果frame為None就跳過
- if frame is None:
- continue
- frame = cv2.resize(
- frame, (640, 360), interpolation=cv2.INTER_AREA)
- # encode the frame in JPEG format
- (flag, encodedImage) = cv2.imencode(".jpg", frame)
- # ensure the frame was successfully encoded
- if not flag:
- continue
- # yield the output frame in the byte format
- yield (b'--frame\r\n' b'Content-Type: image/jpeg\r\n\r\n' +
- bytearray(encodedImage) + b'\r\n')
- # return the response generated along with the specific media
- # type (mime type)
- return Response(generate(), mimetype="multipart/x-mixed-replace; boundary=frame")
- else:
- if s_sock != 0:
- s_sock.close()
- s_sock = 0
- print('s_sock is closed')
- return "s_sock is closed"
- print("test")
- return "s_sock is closed"
- D = {"input_vacuum_status": 0,
- "tank_vacuum_status": 0,
- "tank_threewayvalve_status": 0,
- "tank_diskvalve_status": 0,
- "tank_solenoid_disinfect_status": 0,
- "tank_solenoid_water_status": 0,
- "tank_motor_status": 'none',
- "tank_blower_status": 0,
- "tank_heater1_status": 0,
- "tank_heater2_status": 0,
- "temp1_enable": 0,
- "temp1": 0,
- "output_vacuum_status": 0,
- "tank_threewayvalve_input_status":0,
- "tank_solenoid_water_total_status": 0,
- "tank_solenoid_disinfect_status": 0,
- "outer_solenoid_water_status": 0,
- "tank_solenoid_water_in_status":0,
- "tank_pump_sensor_status": 0,
- "tank_threewayvalve_bean_status":0,
- "outer_threewayvalve_float_status":0,
- "tank_temp_enable_status":0,
- "tank_temp_status": 'none',
- "tank_pump_waterFloat_status": 0,
- "tank_pump_waterL2_status": 0,
- "tank_pump_waterL4_status": 0,
- "tank_solenoid_waterL3_status": 0,
- "tank_solenoid_waterL5_status": 0,
- "tank_stepping_motor_status": 'none',
- }
- pub_topic = 'AISKY/Coffee/MK-G/b8:27:eb:b4:59:3e'
- # sub_topic = 'AISKY/Coffee/MK-G/b8:27:eb:b4:59:3e/Log'
- # mqttObj = MQTT('aisky-client', 'aiskyc', '60.250.156.234', 1883, 60, sub_topic)
- mqttObj = MQTT()
- # mqtt發布
- # @main.route('/mqtt/<tid>', methods=['POST'])
- @main.route('/mqtt/<tid>', methods=['POST'])
- def mqtt_views(tid):
- import json
- dict = request.form.to_dict()
- json = json.dumps(dict)
- # print('dict:', dict) # dict: {'tank-number': '1', 'command': 'tank_vacuum_status', 'value': 'on'}
- # print('json:', json) # json: {"tank-number": "1", tank_vacuum_status", "value": "on"}
- topic = 'AISKY/Coffee/MK-G/b8:27:eb:b4:59:3e'
- # res = mqttObj.mqttPublish(pub_topic, json)
- # print(res)
- # sl(2)
- # print(mqttObj.res)
- #
- # print('test')
- mqtt.publish(topic, json)
- # 入料儲豆槽真空吸料機(ON吸料/OFF排氣)
- if dict['command'] == 'input_vacuum_status':
- time.sleep(1)
- # D[input_vacuum_status]: 0
- print('D[input_vacuum_status]:', D['input_vacuum_status'])
- if D['input_vacuum_status'] == 'on':
- return 'on'
- elif D['input_vacuum_status'] == 'off':
- return 'off'
- else:
- return "input_vacuum_status signal was not received"
- # 真空吸料機
- elif dict['command'] == 'tank_vacuum_status':
- time.sleep(1)
- if D['tank_vacuum_status'] == 'on':
- return 'on'
- elif D['tank_vacuum_status'] == 'off':
- return 'off'
- else:
- return "tank_vacuum_status signal was not received"
- # 三通閥(ON吸料/OFF排氣)
- elif dict['command'] == 'tank_threewayvalve_status':
- time.sleep(1)
- if D['tank_threewayvalve_status'] == 'on':
- return 'on'
- elif D['tank_threewayvalve_status'] == 'off':
- return 'off'
- else:
- return "tank_threewayvalve_status signal was not received"
- # 蝴蝶閥(ON開/OFF關)
- elif dict['command'] == 'tank_diskvalve_status':
- time.sleep(1)
- print("D['tank_diskvalve_status']", D['tank_diskvalve_status'])
- if D['tank_diskvalve_status'] == 'on':
- return 'on'
- elif D['tank_diskvalve_status'] == 'off':
- return 'off'
- else:
- return "tank_diskvalve_status signal was not received"
- # 電磁閥(ON噴灑消毒/OFF關)
- elif dict['command'] == 'tank_solenoid_disinfect_status':
- time.sleep(1)
- if D['tank_solenoid_disinfect_status'] == 'on':
- return 'on'
- elif D['tank_solenoid_disinfect_status'] == 'off':
- return 'off'
- else:
- return "tank_solenoid_disinfect_status signal was not received"
- # 電磁閥(ON排水/OFF關)
- elif dict['command'] == 'tank_solenoid_water_status':
- time.sleep(1)
- if D['tank_solenoid_water_status'] == 'on':
- return 'on'
- elif D['tank_solenoid_water_status'] == 'off':
- return 'off'
- else:
- return "tank_solenoid_water_status signal was not received"
- # 馬達(單位RPM)
- elif dict['command'] == 'tank_motor_status':
- print("D['tank_motor_status']", D['tank_motor_status'])
- time.sleep(1)
- if D['tank_motor_status'] == '0':
- return 'off'
- elif type(D['tank_motor_status']) == int:
- return 'on'
- else:
- return "tank_motor_status signal was not received"
- # 鼓風機(ON開/OFF關)
- elif dict['command'] == 'tank_blower_status':
- time.sleep(1)
- if D['tank_blower_status'] == 'on':
- return 'on'
- elif D['tank_blower_status'] == 'off':
- return 'off'
- else:
- return "tank_blower_status signal was not received"
- # 加熱棒 1(ON開/OFF關)
- elif dict['command'] == 'tank_heater1_status':
- time.sleep(1)
- if D['tank_heater1_status'] == 'on':
- return 'on'
- elif D['tank_heater1_status'] == 'off':
- return 'off'
- else:
- return "tank_heater1_status signal was not received"
- # 加熱棒 2(ON開/OFF關)
- elif dict['command'] == 'tank_heater2_status':
- time.sleep(1)
- if D['tank_heater2_status'] == 'on':
- return 'on'
- elif D['tank_heater2_status'] == 'off':
- return 'off'
- else:
- return "tank_heater2_status signal was not received"
- # 溫度控制(ON開/OFF關)
- elif dict['command'] == 'temp1_enable':
- time.sleep(1)
- if D['temp1_enable'] == 'on':
- return 'on'
- elif D['temp1_enable'] == 'off':
- return 'off'
- else:
- return "temp1_enable_status signal was not received"
- # 設定溫度 (限整數)
- elif dict['command'] == 'temp1':
- time.sleep(1)
- if D['temp1'] == '0':
- return 'off'
- elif type(D['temp1']) == int:
- return 'on'
- else:
- return "temp1 signal was not received"
- # 出料儲豆槽真空吸料機(ON吸料/OFF排氣)
- elif dict['command'] == 'output_vacuum_status':
- time.sleep(1)
- if D['output_vacuum_status'] == 'on':
- return 'on'
- elif D['output_vacuum_status'] == 'off':
- return 'off'
- else:
- return "output_vacuum_status signal was not received"
- # 發酵槽 入料三通閥
- elif dict['command'] == 'tank_threewayvalve_input_status':
- time.sleep(1)
- if D['tank_threewayvalve_input_status'] == 'on':
- return 'on'
- elif D['tank_threewayvalve_input_status'] == 'off':
- return 'off'
- else:
- return "tank_threewayvalve_input_status signal was not received"
- # 發酵槽 總進水
- elif dict['command'] == 'tank_solenoid_water_total_status':
- time.sleep(1)
- if D['tank_solenoid_water_total_status'] == 'on':
- return 'on'
- elif D['tank_solenoid_water_total_status'] == 'off':
- return 'off'
- else:
- return "tank_solenoid_water_total_status signal was not received"
- # 發酵槽 桶內消毒/打菌
- elif dict['command'] == 'tank_solenoid_disinfect_status':
- time.sleep(1)
- if D['tank_solenoid_disinfect_status'] == 'on':
- return 'on'
- elif D['tank_solenoid_disinfect_status'] == 'off':
- return 'off'
- else:
- return "tank_solenoid_disinfect_status signal was not received"
- # 發酵槽 夾層進水
- elif dict['command'] == 'outer_solenoid_water_status':
- time.sleep(1)
- if D['outer_solenoid_water_status'] == 'on':
- return 'on'
- elif D['outer_solenoid_water_status'] == 'off':
- return 'off'
- else:
- return "outer_solenoid_water_status signal was not received"
- # 發酵槽 桶內進水
- elif dict['command'] == 'tank_solenoid_water_in_status':
- time.sleep(1)
- if D['tank_solenoid_water_in_status'] == 'on':
- return 'on'
- elif D['tank_solenoid_water_in_status'] == 'off':
- return 'off'
- else:
- return "tank_solenoid_water_in_status signal was not received"
- # 發酵槽 雙核隔膜泵
- elif dict['command'] == 'tank_pump_sensor_status':
- time.sleep(1)
- if D['tank_pump_sensor_status'] == 'on':
- return 'on'
- elif D['tank_pump_sensor_status'] == 'off':
- return 'off'
- else:
- return "tank_pump_sensor_status signal was not received"
- # 發酵槽 感測器下豆三通閥
- elif dict['command'] == 'tank_threewayvalve_bean_status':
- time.sleep(1)
- if D['tank_threewayvalve_bean_status'] == 'on':
- return 'on'
- elif D['tank_threewayvalve_bean_status'] == 'off':
- return 'off'
- else:
- return "tank_threewayvalve_bean_status signal was not received"
- # 發酵槽 外桶浮選三通閥
- elif dict['command'] == 'outer_threewayvalve_float_status':
- time.sleep(1)
- if D['outer_threewayvalve_float_status'] == 'on':
- return 'on'
- elif D['outer_threewayvalve_float_status'] == 'off':
- return 'off'
- else:
- return "outer_threewayvalve_float_status signal was not received"
- # 發酵槽 溫控開關
- elif dict['command'] == 'tank_temp_enable_status':
- time.sleep(1)
- if D['tank_temp_enable_status'] == 'on':
- return 'on'
- elif D['tank_temp_enable_status'] == 'off':
- return 'off'
- else:
- return "tank_temp_enable_status signal was not received"
- # 發酵槽 設定溫度
- elif dict['command'] == 'tank_temp_status':
- time.sleep(1)
- if D['tank_temp_status'] == '0':
- return 'off'
- elif type(D['tank_temp_status']) == int:
- return 'on'
- else:
- return "tank_temp_status signal was not received"
- # 清洗浮選槽 浮選槽注水
- elif dict['command'] == 'tank_pump_waterFloat_status':
- time.sleep(1)
- if D['tank_pump_waterFloat_status'] == 'on':
- return 'on'
- elif D['tank_pump_waterFloat_status'] == 'off':
- return 'off'
- else:
- return "tank_pump_waterFloat_status signal was not received"
-
- # 清洗浮選槽 清洗第 2 層灑水
- elif dict['command'] == 'tank_pump_waterL2_status':
- time.sleep(1)
- if D['tank_pump_waterL2_status'] == 'on':
- return 'on'
- elif D['tank_pump_waterL2_status'] == 'off':
- return 'off'
- else:
- return "tank_pump_waterL2_status signal was not received"
- # 清洗浮選槽 清洗第 4 層灑水
- elif dict['command'] == 'tank_pump_waterL4_status':
- time.sleep(1)
- if D['tank_pump_waterL4_status'] == 'on':
- return 'on'
- elif D['tank_pump_waterL4_status'] == 'off':
- return 'off'
- else:
- return "tank_pump_waterL4_status signal was not received"
- # 清洗浮選槽 清洗第 3 層電磁閥
- elif dict['command'] == 'tank_solenoid_waterL3_status':
- time.sleep(1)
- if D['tank_solenoid_waterL3_status'] == 'on':
- return 'on'
- elif D['tank_solenoid_waterL3_status'] == 'off':
- return 'off'
- else:
- return "tank_solenoid_waterL3_status signal was not received"
- # 清洗浮選槽 清洗第 5 層電磁閥
- elif dict['command'] == 'tank_solenoid_waterL5_status':
- time.sleep(1)
- if D['tank_solenoid_waterL5_status'] == 'on':
- return 'on'
- elif D['tank_solenoid_waterL5_status'] == 'off':
- return 'off'
- else:
- return "tank_solenoid_waterL5_status signal was not received"
- # 清洗浮選槽 步進馬達
- elif dict['command'] == 'tank_stepping_motor_status':
- time.sleep(1)
- if D['tank_stepping_motor_status'] == '0':
- return 'off'
- elif type(D['tank_stepping_motor_status']) == int:
- return 'on'
- else:
- return "tank_stepping_motor_status signal was not received"
- return "publish done"
- # --- 10/19 ------------------------------------------ start
- # mqtt發布
- # @main.route('/mqtt/<tid>', methods=['POST'])
- @main.route('/mqtt_f/<tid>', methods=['POST'])
- def mqtt_f(data):
- import json
- # dict = request.form.to_dict()
- json = json.dumps(data)
- # print('dict:', dict) # dict: {'tank-number': '1', 'command': 'tank_vacuum_status', 'value': 'on'}
- # print('json:', json) # json: {"tank-number": "1", tank_vacuum_status", "value": "on"}
- print('json:', json)
- topic = 'AISKY/Coffee/MK-G/b8:27:eb:b4:59:3e'
- # res = mqttObj.mqttPublish(pub_topic, json)
- # print(res)
- # sl(2)
- # print(mqttObj.res)
- #
- # print('test')
- mqtt.publish(topic, json)
- # 入料儲豆槽真空吸料機(ON吸料/OFF排氣)
- if dict['command'] == 'input_vacuum_status':
- time.sleep(1)
- # D[input_vacuum_status]: 0
- print('D[input_vacuum_status]:', D['input_vacuum_status'])
- if D['input_vacuum_status'] == 'on':
- return 'on'
- elif D['input_vacuum_status'] == 'off':
- return 'off'
- else:
- return "input_vacuum_status signal was not received"
- # 真空吸料機
- elif dict['command'] == 'tank_vacuum_status':
- time.sleep(1)
- if D['tank_vacuum_status'] == 'on':
- return 'on'
- elif D['tank_vacuum_status'] == 'off':
- return 'off'
- else:
- return "tank_vacuum_status signal was not received"
- # 三通閥(ON吸料/OFF排氣)
- elif dict['command'] == 'tank_threewayvalve_status':
- time.sleep(1)
- if D['tank_threewayvalve_status'] == 'on':
- return 'on'
- elif D['tank_threewayvalve_status'] == 'off':
- return 'off'
- else:
- return "tank_threewayvalve_status signal was not received"
- # 蝴蝶閥(ON開/OFF關)
- elif dict['command'] == 'tank_diskvalve_status':
- time.sleep(1)
- print("D['tank_diskvalve_status']", D['tank_diskvalve_status'])
- if D['tank_diskvalve_status'] == 'on':
- return 'on'
- elif D['tank_diskvalve_status'] == 'off':
- return 'off'
- else:
- return "tank_diskvalve_status signal was not received"
- # 電磁閥(ON噴灑消毒/OFF關)
- elif dict['command'] == 'tank_solenoid_disinfect_status':
- time.sleep(1)
- if D['tank_solenoid_disinfect_status'] == 'on':
- return 'on'
- elif D['tank_solenoid_disinfect_status'] == 'off':
- return 'off'
- else:
- return "tank_solenoid_disinfect_status signal was not received"
- # 電磁閥(ON排水/OFF關)
- elif dict['command'] == 'tank_solenoid_water_status':
- time.sleep(1)
- if D['tank_solenoid_water_status'] == 'on':
- return 'on'
- elif D['tank_solenoid_water_status'] == 'off':
- return 'off'
- else:
- return "tank_solenoid_water_status signal was not received"
- # 馬達(單位RPM)
- elif dict['command'] == 'tank_motor_status':
- print("D['tank_motor_status']", D['tank_motor_status'])
- time.sleep(1)
- if D['tank_motor_status'] == '0':
- return 'off'
- elif type(D['tank_motor_status']) == int:
- return 'on'
- else:
- return "tank_motor_status signal was not received"
- # 鼓風機(ON開/OFF關)
- elif dict['command'] == 'tank_blower_status':
- time.sleep(1)
- if D['tank_blower_status'] == 'on':
- return 'on'
- elif D['tank_blower_status'] == 'off':
- return 'off'
- else:
- return "tank_blower_status signal was not received"
- # 加熱棒 1(ON開/OFF關)
- elif dict['command'] == 'tank_heater1_status':
- time.sleep(1)
- if D['tank_heater1_status'] == 'on':
- return 'on'
- elif D['tank_heater1_status'] == 'off':
- return 'off'
- else:
- return "tank_heater1_status signal was not received"
- # 加熱棒 2(ON開/OFF關)
- elif dict['command'] == 'tank_heater2_status':
- time.sleep(1)
- if D['tank_heater2_status'] == 'on':
- return 'on'
- elif D['tank_heater2_status'] == 'off':
- return 'off'
- else:
- return "tank_heater2_status signal was not received"
- # 溫度控制(ON開/OFF關)
- elif dict['command'] == 'temp1_enable':
- time.sleep(1)
- if D['temp1_enable'] == 'on':
- return 'on'
- elif D['temp1_enable'] == 'off':
- return 'off'
- else:
- return "temp1_enable_status signal was not received"
- # 設定溫度 (限整數)
- elif dict['command'] == 'temp1':
- time.sleep(1)
- if D['temp1'] == '0':
- return 'off'
- elif type(D['temp1']) == int:
- return 'on'
- else:
- return "temp1 signal was not received"
- # 出料儲豆槽真空吸料機(ON吸料/OFF排氣)
- elif dict['command'] == 'output_vacuum_status':
- time.sleep(1)
- if D['output_vacuum_status'] == 'on':
- return 'on'
- elif D['output_vacuum_status'] == 'off':
- return 'off'
- else:
- return "output_vacuum_status signal was not received"
- # 發酵槽 入料三通閥
- elif dict['command'] == 'tank_threewayvalve_input_status':
- time.sleep(1)
- if D['tank_threewayvalve_input_status'] == 'on':
- return 'on'
- elif D['tank_threewayvalve_input_status'] == 'off':
- return 'off'
- else:
- return "tank_threewayvalve_input_status signal was not received"
- # 發酵槽 總進水
- elif dict['command'] == 'tank_solenoid_water_total_status':
- time.sleep(1)
- if D['tank_solenoid_water_total_status'] == 'on':
- return 'on'
- elif D['tank_solenoid_water_total_status'] == 'off':
- return 'off'
- else:
- return "tank_solenoid_water_total_status signal was not received"
- # 發酵槽 桶內消毒/打菌
- elif dict['command'] == 'tank_solenoid_disinfect_status':
- time.sleep(1)
- if D['tank_solenoid_disinfect_status'] == 'on':
- return 'on'
- elif D['tank_solenoid_disinfect_status'] == 'off':
- return 'off'
- else:
- return "tank_solenoid_disinfect_status signal was not received"
- # 發酵槽 夾層進水
- elif dict['command'] == 'outer_solenoid_water_status':
- time.sleep(1)
- if D['outer_solenoid_water_status'] == 'on':
- return 'on'
- elif D['outer_solenoid_water_status'] == 'off':
- return 'off'
- else:
- return "outer_solenoid_water_status signal was not received"
- # 發酵槽 桶內進水
- elif dict['command'] == 'tank_solenoid_water_in_status':
- time.sleep(1)
- if D['tank_solenoid_water_in_status'] == 'on':
- return 'on'
- elif D['tank_solenoid_water_in_status'] == 'off':
- return 'off'
- else:
- return "tank_solenoid_water_in_status signal was not received"
- # 發酵槽 雙核隔膜泵
- elif dict['command'] == 'tank_pump_sensor_status':
- time.sleep(1)
- if D['tank_pump_sensor_status'] == 'on':
- return 'on'
- elif D['tank_pump_sensor_status'] == 'off':
- return 'off'
- else:
- return "tank_pump_sensor_status signal was not received"
- # 發酵槽 感測器下豆三通閥
- elif dict['command'] == 'tank_threewayvalve_bean_status':
- time.sleep(1)
- if D['tank_threewayvalve_bean_status'] == 'on':
- return 'on'
- elif D['tank_threewayvalve_bean_status'] == 'off':
- return 'off'
- else:
- return "tank_threewayvalve_bean_status signal was not received"
- # 發酵槽 外桶浮選三通閥
- elif dict['command'] == 'outer_threewayvalve_float_status':
- time.sleep(1)
- if D['outer_threewayvalve_float_status'] == 'on':
- return 'on'
- elif D['outer_threewayvalve_float_status'] == 'off':
- return 'off'
- else:
- return "outer_threewayvalve_float_status signal was not received"
- # 發酵槽 溫控開關
- elif dict['command'] == 'tank_temp_enable_status':
- time.sleep(1)
- if D['tank_temp_enable_status'] == 'on':
- return 'on'
- elif D['tank_temp_enable_status'] == 'off':
- return 'off'
- else:
- return "tank_temp_enable_status signal was not received"
- # 發酵槽 設定溫度
- elif dict['command'] == 'tank_temp_status':
- time.sleep(1)
- if D['tank_temp_status'] == '0':
- return 'off'
- elif type(D['tank_temp_status']) == int:
- return 'on'
- else:
- return "tank_temp_status signal was not received"
- # 清洗浮選槽 浮選槽注水
- elif dict['command'] == 'tank_pump_waterFloat_status':
- time.sleep(1)
- if D['tank_pump_waterFloat_status'] == 'on':
- return 'on'
- elif D['tank_pump_waterFloat_status'] == 'off':
- return 'off'
- else:
- return "tank_pump_waterFloat_status signal was not received"
-
- # 清洗浮選槽 清洗第 2 層灑水
- elif dict['command'] == 'tank_pump_waterL2_status':
- time.sleep(1)
- if D['tank_pump_waterL2_status'] == 'on':
- return 'on'
- elif D['tank_pump_waterL2_status'] == 'off':
- return 'off'
- else:
- return "tank_pump_waterL2_status signal was not received"
- # 清洗浮選槽 清洗第 4 層灑水
- elif dict['command'] == 'tank_pump_waterL4_status':
- time.sleep(1)
- if D['tank_pump_waterL4_status'] == 'on':
- return 'on'
- elif D['tank_pump_waterL4_status'] == 'off':
- return 'off'
- else:
- return "tank_pump_waterL4_status signal was not received"
- # 清洗浮選槽 清洗第 3 層電磁閥
- elif dict['command'] == 'tank_solenoid_waterL3_status':
- time.sleep(1)
- if D['tank_solenoid_waterL3_status'] == 'on':
- return 'on'
- elif D['tank_solenoid_waterL3_status'] == 'off':
- return 'off'
- else:
- return "tank_solenoid_waterL3_status signal was not received"
- # 清洗浮選槽 清洗第 5 層電磁閥
- elif dict['command'] == 'tank_solenoid_waterL5_status':
- time.sleep(1)
- if D['tank_solenoid_waterL5_status'] == 'on':
- return 'on'
- elif D['tank_solenoid_waterL5_status'] == 'off':
- return 'off'
- else:
- return "tank_solenoid_waterL5_status signal was not received"
- # 清洗浮選槽 步進馬達
- elif dict['command'] == 'tank_stepping_motor_status':
- time.sleep(1)
- if D['tank_stepping_motor_status'] == '0':
- return 'off'
- elif type(D['tank_stepping_motor_status']) == int:
- return 'on'
- else:
- return "tank_stepping_motor_status signal was not received"
- return "publish done"
- # ---10/19 ------------------------------------------- end
- # 處理mqtt訂閱的信息
- @mqtt.on_message()
- def handle_mqtt_message(client, userdata, message):
- payload = message.payload.decode()
- payload = json.loads(payload)
- # print("-------msg-------")
- # print('name :', p['name'])
- # print('email :', p['email'])
- print('payload:', payload)
- # 入料儲豆槽真空吸料機(ON吸料/OFF排氣)
- if payload['command'] == 'input_vacuum_status':
- if payload['response'] == 'on':
- D['input_vacuum_status'] = 'on'
- else:
- D['input_vacuum_status'] = 'off'
- # 真空吸料機
- elif payload['command'] == 'tank_vacuum_status':
- if payload['response'] == 'on':
- # print('test')
- D['tank_vacuum_status'] = 'on'
- else:
- D['tank_vacuum_status'] = 'off'
- # 三通閥(ON吸料/OFF排氣)
- elif payload['command'] == 'tank_threewayvalve_status':
- if payload['response'] == 'on':
- # print('test')
- D['tank_threewayvalve_status'] = 'on'
- else:
- D['tank_threewayvalve_status'] = 'off'
- # 蝴蝶閥(ON開/OFF關)
- elif payload['command'] == 'tank_diskvalve_status':
- if payload['response'] == 'on':
- # print('test')
- D['tank_diskvalve_status'] = 'on'
- else:
- D['tank_diskvalve_status'] = 'off'
- # 電磁閥(ON噴灑消毒/OFF關)
- elif payload['command'] == 'tank_solenoid_disinfect_status':
- if payload['response'] == 'on':
- # print('test')
- D['tank_solenoid_disinfect_status'] = 'on'
- else:
- D['tank_solenoid_disinfect_status'] = 'off'
- # 電磁閥(ON排水/OFF關)
- elif payload['command'] == 'tank_solenoid_water_status':
- if payload['response'] == 'on':
- # print('test')
- D['tank_solenoid_water_status'] = 'on'
- else:
- D['tank_solenoid_water_status'] = 'off'
- # 馬達(單位RPM)
- elif payload['command'] == 'tank_motor_status':
- if payload['response'] == 'off':
- D['tank_motor_status'] = '0'
- else:
- D['tank_motor_status'] = payload['response']
- # 鼓風機(ON開/OFF關)
- elif payload['command'] == 'tank_blower_status':
- if payload['response'] == 'on':
- # print('test')
- D['tank_blower_status'] = 'on'
- else:
- D['tank_blower_status'] = 'off'
- # 加熱棒 1(ON開/OFF關)
- elif payload['command'] == 'tank_heater1_status':
- if payload['response'] == 'on':
- # print('test')
- D['tank_heater1_status'] = 'on'
- else:
- D['tank_heater1_status'] = 'off'
- # 加熱棒 2(ON開/OFF關)
- elif payload['command'] == 'tank_heater2_status':
- if payload['response'] == 'on':
- # print('test')
- D['tank_heater2_status'] = 'on'
- else:
- D['tank_heater2_status'] = 'off'
- # 出料儲豆槽真空吸料機(ON吸料/OFF排氣)
- elif payload['command'] == 'output_vacuum_status':
- if payload['response'] == 'on':
- # print('test')
- D['output_vacuum_status'] = 'on'
- else:
- D['output_vacuum_status'] = 'off'
- # 發酵槽 入料三通閥
- elif payload['command'] == 'tank_threewayvalve_input_status':
- if payload['response'] == 'on':
- # print('test')
- D['tank_threewayvalve_input_status'] = 'on'
- else:
- D['tank_threewayvalve_input_status'] = 'off'
- # 發酵槽 總進水
- elif payload['command'] == 'tank_solenoid_water_total_status':
- if payload['response'] == 'on':
- D['tank_solenoid_water_total_status'] = 'on'
- else:
- D['tank_solenoid_water_total_status'] = 'off'
- # 發酵槽 桶內消毒/打菌
- elif payload['command'] == 'tank_solenoid_disinfect_status':
- if payload['response'] == 'on':
- D['tank_solenoid_disinfect_status'] = 'on'
- else:
- D['tank_solenoid_disinfect_status'] = 'off'
- # 發酵槽 夾層進水
- elif payload['command'] == 'outer_solenoid_water_status':
- if payload['response'] == 'on':
- D['outer_solenoid_water_status'] = 'on'
- else:
- D['outer_solenoid_water_status'] = 'off'
- # 發酵槽 桶內進水
- elif payload['command'] == 'tank_solenoid_water_in_status':
- if payload['response'] == 'on':
- D['tank_solenoid_water_in_status'] = 'on'
- else:
- D['tank_solenoid_water_in_status'] = 'off'
- # 發酵槽 雙核隔膜泵
- elif payload['command'] == 'tank_pump_sensor_status':
- if payload['response'] == 'on':
- D['tank_pump_sensor_status'] = 'on'
- else:
- D['tank_pump_sensor_status'] = 'off'
- # 發酵槽 感測器下豆三通閥
- elif payload['command'] == 'tank_threewayvalve_bean_status':
- if payload['response'] == 'on':
- D['tank_threewayvalve_bean_status'] = 'on'
- else:
- D['tank_threewayvalve_bean_status'] = 'off'
- # 發酵槽 外桶浮選三通閥
- elif payload['command'] == 'outer_threewayvalve_float_status':
- if payload['response'] == 'on':
- D['outer_threewayvalve_float_status'] = 'on'
- else:
- D['outer_threewayvalve_float_status'] = 'off'
- # 發酵槽 溫控開關
- elif payload['command'] == 'tank_temp_enable_status':
- if payload['response'] == 'on':
- D['tank_temp_enable_status'] = 'on'
- else:
- D['tank_temp_enable_status'] = 'off'
- # 發酵槽 設定溫度
- elif payload['command'] == 'tank_temp_status':
- if payload['response'] == 'off':
- D['tank_temp_status'] = '0'
- else:
- D['tank_temp_status'] = payload['response']
- # 清洗浮選槽 浮選槽注水
- elif payload['command'] == 'tank_pump_waterFloat_status':
- if payload['response'] == 'on':
- D['tank_temp_status'] = 'on'
- else:
- D['tank_temp_status'] = 'off'
-
- # 清洗浮選槽 清洗第 2 層灑水
- elif payload['command'] == 'tank_pump_waterL2_status':
- if payload['response'] == 'on':
- D['tank_pump_waterL2_status'] = 'on'
- else:
- D['tank_pump_waterL2_status'] = 'off'
- # 清洗浮選槽 清洗第 4 層灑水
- elif payload['command'] == 'tank_pump_waterL4_status':
- if payload['response'] == 'on':
- D['tank_pump_waterL4_status'] = 'on'
- else:
- D['tank_pump_waterL4_status'] = 'off'
- # 清洗浮選槽 清洗第 3 層電磁閥
- elif payload['command'] == 'tank_solenoid_waterL3_status':
- if payload['response'] == 'on':
- D['tank_solenoid_waterL3_status'] = 'on'
- else:
- D['tank_solenoid_waterL3_status'] = 'off'
- # 清洗浮選槽 清洗第 5 層電磁閥
- elif payload['command'] == 'tank_solenoid_waterL5_status':
- if payload['response'] == 'on':
- D['tank_solenoid_waterL5_status'] = 'on'
- else:
- D['tank_solenoid_waterL5_status'] = 'off'
- # 清洗浮選槽 步進馬達
- elif payload['command'] == 'tank_stepping_motor_status':
- if payload['response'] == 'off':
- D['tank_stepping_motor_status'] = '0'
- else:
- D['tank_stepping_motor_status'] = payload['response']
|