def Playpause_Change(request): if request.method == 'POST': sPlaypauseValue = request.POST.getlist('sPlaypauseValue') sCommand = request.POST.getlist('sCommand') sFunction = request.POST.getlist('sFunction') sAppID = request.POST.getlist('sAppID') sPlaypauseValue = str(sPlaypauseValue) sPlaypauseValue = sPlaypauseValue[2:-2] sFunction = str(sFunction) sAppID = str(sAppID) tz = pytz.timezone("Asia/Kolkata") time = (datetime.datetime.now(tz=tz)) if(sPlaypauseValue[0] == "'" and sPlaypauseValue[1] == 's'): sCommand = str(sCommand) sCommand = int(sCommand[2:-2]) sCommand = Songlist_string_Converter(sCommand) sID = int(sPlaypauseValue[7:]) sLastSong = Songs.objects.get(id =sID) slastsongstore = Getlastsong(song_name = sLastSong.name,song_id=sLastSong.id) slastsongstore.save() slog_song = sLastSong.name slog_song_id=sLastSong.id elif(sPlaypauseValue[0] == "f" and sPlaypauseValue[1] == 'm'): sCommand = str(sCommand) sCommand = sCommand[2:-2] try: sLog = Log.objects.latest('id') slastsongstore = Getlastsong(song_name = sLog.log_song,song_id=sLog.log_song_id) slastsongstore.save() sLastSong = Getlastsong.objects.latest('id') except Exception as e: sErrorlog = Errorlog(error_at = time, error_name = e) sErrorlog.save() slog_song = "FM " + sPlaypauseValue slog_song_id= 0 elif(sPlaypauseValue[0] == "m" and sPlaypauseValue[1] == 'p'): sCommand = str(sCommand) sCommand = sCommand[2:-2] try: sGetlastSong = Getlastsong.objects.latest('id') if(sPlaypauseValue == "mp3_prev"): if(sGetlastSong.song_id > 1): slog_song_id = (sGetlastSong.song_id - 1) sLastSong = Songs.objects.get(id =slog_song_id) slog_song = sLastSong.name slog_song_id = sLastSong.id slastsongstore = Getlastsong(song_name = sLastSong.name,song_id=sLastSong.id) slastsongstore.save() else: slog_song_id= sGetlastSong.song_id sLastSong = Songs.objects.get(id =slog_song_id) slog_song = sLastSong.name slog_song_id=sLastSong.id elif(sPlaypauseValue == "mp3_next"): maxsong = Songs.objects.latest('id') if(sGetlastSong.song_id < maxsong.id): slog_song_id= (sGetlastSong.song_id + 1) sLastSong = Songs.objects.get(id =slog_song_id) slog_song = sLastSong.name slog_song_id=sLastSong.id slastsongstore = Getlastsong(song_name = sLastSong.name,song_id=sLastSong.id) slastsongstore.save() else: slog_song_id= sGetlastSong.song_id sLastSong = Songs.objects.get(id =slog_song_id) slog_song = sLastSong.name slog_song_id=sLastSong.id else: slog_song_id = sGetlastSong.song_id sLastSong = Songs.objects.get(id =slog_song_id) slog_song = sLastSong.name slog_song_id = sLastSong.id except Exception as e: sErrorlog = Errorlog(error_at = time, error_name = e) sErrorlog.save() slog_song = "error" slog_song_id= 0 else: sCommand = str(sCommand) sCommand = sCommand[2:-2] slog_song = "none" slog_song_id= 0 sFunction = sFunction[2:-2] if(sFunction == "00"): sCommand = Songlist_string_Converter(int(sCommand)) sAppID = sAppID[2:-2] sSiliconid = "181E0BC8000E1440" sConfigInfo = Storeconfiginfo.objects.latest('id') sXbee = sConfigInfo.xbee_number sStringpacket = playpausecontrol.Palypause_Packet_Constractor(sAppID,sCommand,sFunction,sXbee) if (sPlaypauseValue != "get_info"): try: sLog = Log.objects.latest('id') if (sLog.action_taken == 0): sFail = Fail(fail_at = time,siliconid=sSiliconid,log_id=sLog.id) sFail.save() except Exception as e: sErrorlog = Errorlog(error_at = time, error_name = e) sErrorlog.save() sLogToDatabase = Log(log_at=time,log_value=sPlaypauseValue,log_cmd = sCommand, log_function = sFunction,log_appid = sAppID,siliconid=sSiliconid, packet_str = sStringpacket,log_song = slog_song,log_song_id=slog_song_id) sLogToDatabase.save() sAppRequest = Recent_App_Request(app_id=sAppID,app_name="playpause") sAppRequest.save() try: sLastPing = Pings.objects.latest('id') except Exception as e: sErrorlog = Errorlog(error_at = time, error_name = e) sErrorlog.save() try: sLog = Log.objects.latest('id') except Exception as e: sErrorlog = Errorlog(error_at = time, error_name = e) sErrorlog.save() try: sAction = Action.objects.latest('id') except Exception as e: sErrorlog = Errorlog(error_at = time, error_name = e) sErrorlog.save() try: sSucess = Sucess.objects.latest('id') except Exception as e: sErrorlog = Errorlog(error_at = time, error_name = e) sErrorlog.save() try: sFail = Fail.objects.latest('id') except Exception as e: sErrorlog = Errorlog(error_at = time, error_name = e) sErrorlog.save() PingTime = sLastPing.sPingAt PingTime = Last_Ping_Time_Diff(PingTime) CmdRequest = sLog.log_value if(CmdRequest[0] == "'" and CmdRequest[1] == "s"): sID = int(CmdRequest[7:]) sLastSong = Songs.objects.get(id =sID) CmdRequestTime = sLog.log_at CmdRequestTime = Last_Ping_Time_Diff(CmdRequestTime) CmdActionTime = sAction.action_at CmdActionTime = Last_Ping_Time_Diff(CmdActionTime) CmdAction = (Log.objects.get(id = sAction.log_id)).log_value CmdStatus = sSucess.sucess_status CmdStatusTime = sSucess.sucess_at CmdStatusTime = Last_Ping_Time_Diff(CmdStatusTime) CmdCmd = (Log.objects.get(id = sSucess.log_id)).log_value FailCmd = (Log.objects.get(id = sFail.log_id)).log_value FailTime = sFail.fail_at FailTime = Last_Ping_Time_Diff(FailTime) sLastPingInfo = {'pingat':PingTime,'siliconid' :sLastPing.sSiliconID, 'RSSI':99,'cmdrequest':CmdRequest,'cmdrequesttime':CmdRequestTime, 'cmdaction':CmdAction,'cmdactiontime':CmdActionTime,'cmdstatus':CmdStatus, 'cmdstatustime':CmdStatusTime,'cmdcmd':CmdCmd,'failcmd':FailCmd, 'failtime':FailTime,'lastsong':sLastSong,} tz = pytz.timezone("Asia/Kolkata") time = (datetime.datetime.now(tz=tz)) try: sLastPing = Pings.objects.latest('id') except Exception as e: sErrorlog = Errorlog(error_at = time, error_name = e) sErrorlog.save() try: sLog = Log.objects.latest('id') except Exception as e: sErrorlog = Errorlog(error_at = time, error_name = e) sErrorlog.save() try: sAction = Action.objects.latest('id') except Exception as e: sErrorlog = Errorlog(error_at = time, error_name = e) sErrorlog.save() try: sSucess = Sucess.objects.latest('id') except Exception as e: sErrorlog = Errorlog(error_at = time, error_name = e) sErrorlog.save() try: sFail = Fail.objects.latest('id') except Exception as e: sErrorlog = Errorlog(error_at = time, error_name = e) sErrorlog.save() PingTime = sLastPing.sPingAt PingTime = Last_Ping_Time_Diff(PingTime) CmdRequest = sLog.log_value if(CmdRequest[0] == "'" and CmdRequest[1] == "s"): sID = int(CmdRequest[7:]) sLastSong = Songs.objects.get(id =sID) CmdRequestTime = sLog.log_at CmdRequestTime = Last_Ping_Time_Diff(CmdRequestTime) CmdActionTime = sAction.action_at CmdActionTime = Last_Ping_Time_Diff(CmdActionTime) CmdAction = (Log.objects.get(id = sAction.log_id)).log_value CmdStatus = sSucess.sucess_status CmdStatusTime = sSucess.sucess_at CmdStatusTime = Last_Ping_Time_Diff(CmdStatusTime) CmdCmd = (Log.objects.get(id = sSucess.log_id)).log_value FailCmd = (Log.objects.get(id = sFail.log_id)).log_value FailTime = sFail.fail_at FailTime = Last_Ping_Time_Diff(FailTime) sSonglist = Songs.objects.all() try: sLastSong = sLastSong.name except Exception as e: sErrorlog = Errorlog(error_at = time, error_name = str(e)) sErrorlog.save() sLastSong = CmdRequest sLastPingInfo = {'pingat':PingTime,'siliconid' :sLastPing.sSiliconID, 'RSSI':99,'cmdrequest':CmdRequest,'cmdrequesttime':CmdRequestTime, 'cmdaction':CmdAction,'cmdactiontime':CmdActionTime,'cmdstatus':CmdStatus, 'cmdstatustime':CmdStatusTime,'cmdcmd':CmdCmd,'failcmd':FailCmd, 'failtime':FailTime,'lastsong':sLastSong,} return render(request,"playpause/playpause.html",{'sLastPingInfo': sLastPingInfo,'sSonglist': sSonglist})
def Accon_Change(request): if request.method == 'POST': sDeviceId = request.POST.getlist('sDeviceId') sValue = request.POST.getlist('sValue') sSpeed = request.POST.getlist('sSpeed') sAppID = request.POST.getlist('sAppID') sDeviceId = str(sDeviceId) sDeviceId = sDeviceId[2:-2] sValue = str(sValue) sAppID = str(sAppID) sSpeed = str(sSpeed) tz = pytz.timezone("Asia/Kolkata") time = (datetime.datetime.now(tz=tz)) sSiliconid = "181E0BC8000E1440" sValue = sValue[2:-2] sAppID = sAppID[2:-2] sSpeed = sSpeed[2:-2] sSpeed = int(sSpeed) sId,sv = Get_Device_Info(sDeviceId,sValue,sSpeed) try: sDeviceInfo = ACDetails.objects.get(id =sId) sinfo = sDeviceInfo.device_info sDeviceInfo.current_value = sv sDeviceInfo.current_scale = sv * 10 sDeviceInfo.save() except Exception as e: sinfo = "" sv = 0 sErrorlog = ACErrorlog(error_at = time, error_name = str(e)) sErrorlog.save() scale = sv * 10 try: sConfigInfo = ACStoreconfiginfo.objects.latest('id') sXbee = sConfigInfo.xbee_number except Exception as e: sErrorlog = ACErrorlog(error_at = time, error_name = str(e)) sErrorlog.save() try: sAcconDetail = ACDetails.objects.get(id =sId) sDeviceId = sAcconDetail.device_id sDevicePlace = sAcconDetail.device_place sDeviceCurrentValue = sAcconDetail.current_value except Exception as e: sErrorlog = ACErrorlog(error_at = time, error_name = str(e)) sErrorlog.save() try: sLog = ACLog.objects.latest('id') if (sLog.action_taken == 0): sFail = ACFail(fail_at = time,siliconid=sSiliconid,log_id=sLog.id) sFail.save() except Exception as e: sErrorlog = ACErrorlog(error_at = time, error_name = e) sErrorlog.save() sStringpacket = acconcontrol.Accon_Packet_Constractor(sAppID,sDeviceId,sDevicePlace,sDeviceCurrentValue,sXbee) sLogToDatabase = ACLog(log_at=time,log_deviceid=sDeviceId,log_value = sValue, log_speed = sSpeed,packet_str = sStringpacket,log_appid = sAppID, log_info_id=sId,log_info = sinfo,siliconid=sSiliconid) sLogToDatabase.save() sAppRequest = Recent_App_Request(app_id=sAppID,app_name="accon") sAppRequest.save() try: sAcconDetail = ACDetails.objects.get(id =sId) sDeviceName = sAcconDetail.device_name sDeviceInfo = sAcconDetail.device_info sDeviceId = sAcconDetail.device_id sDeviceImgOn = sAcconDetail.device_img_on sDeviceImgOff = sAcconDetail.device_img_off sDevicePlace = sAcconDetail.device_place sDeviceCurrentValue = sAcconDetail.current_value sDeviceScale = sAcconDetail.current_scale except Exception as e: sErrorlog = ACErrorlog(error_at = time, error_name = str(e)) sErrorlog.save() sAcconDetail = "" sDeviceName = "" sDeviceInfo = "" sDeviceId = "" sDeviceImgOn = "" sDeviceImgOff = "" sDevicePlace = "" sDeviceCurrentValue = "" sDeviceScale = "" try: sAcconApplied = ACLog.objects.latest('id') sAcconAppliedTime = sAcconApplied.log_at sAcconAppliedTime = Last_Ping_Time_Diff(sAcconAppliedTime) sAcconAppliedInfo = sAcconApplied.log_info sAcconAppliedValue = sAcconApplied.log_speed print (sAcconAppliedValue) except Exception as e: sErrorlog = ACErrorlog(error_at = time, error_name = str(e)) sErrorlog.save() sAcconAppliedTime ="" sAcconAppliedInfo ="" sAcconAppliedValue ="" try: sAcconAction = ACAction.objects.latest('id') sAcconActionTime = sAcconAction.action_at sAcconActionTime = Last_Ping_Time_Diff(sAcconActionTime) sAcconActionInfo = (ACLog.objects.get(id = sAcconAction.log_id)).log_info sAcconActionValue = (ACLog.objects.get(id = sAcconAction.log_id)).log_speed except Exception as e: sErrorlog = ACErrorlog(error_at = time, error_name = str(e)) sErrorlog.save() sAcconActionTime ="" sAcconActionInfo ="" sAcconActionValue ="" try: sAcconSucess = ACSucess.objects.latest('id') sAcconSucessTime = sAcconSucess.sucess_at sAcconSucessTime = Last_Ping_Time_Diff(sAcconSucessTime) sAcconSucessInfo = (ACLog.objects.get(id = sAcconSucess.log_id)).log_info sAcconSucessStatus = sAcconSucess.sucess_status except Exception as e: sErrorlog = ACErrorlog(error_at = time, error_name = str(e)) sErrorlog.save() sAcconSucessTime ="" sAcconSucessInfo ="" sAcconSucessStatus ="" try: sAcconFail = ACFail.objects.latest('id') sAcconFailTime = sAcconFail.fail_at sAcconFailTime = Last_Ping_Time_Diff(sAcconFailTime) sAcconFailInfo = (ACLog.objects.get(id = sAcconFail.log_id)).log_info sAcconFailValue = (ACLog.objects.get(id = sAcconFail.log_id)).log_speed except Exception as e: sErrorlog = ACErrorlog(error_at = time, error_name = str(e)) sErrorlog.save() sAcconFailTime ="" sAcconFailInfo ="" sAcconFailValue ="" sAcconDetail = {'devicename':sDeviceName,'deviceinfo':sDeviceInfo,'deviceid':sDeviceId, 'deviceimgon':sDeviceImgOn,'deviceimgoff':sDeviceImgOff,'deviceplace':sDevicePlace, 'devicecurrentvalue':sDeviceCurrentValue,'devicescale':sDeviceScale, 'acconfailtime': sAcconFailTime,'acconfailinfo':sAcconFailInfo,'acconfailvalue':sAcconFailValue, 'acconactiontime':sAcconActionTime,'acconactioninfo':sAcconActionInfo,'acconactionvalue':sAcconActionValue, 'acconsucesstime':sAcconSucessTime,'acconsucessinfo':sAcconSucessInfo,'acconsucessstatus':sAcconSucessStatus, 'acconappliedinfo':sAcconAppliedInfo,'acconappliedvalue':sAcconAppliedValue,'acconappliedtime':sAcconAppliedTime,} return HttpResponse(json.dumps({'saccondetail':sAcconDetail})) try: sAcconDetail = ACDetails.objects.all() except Exception as e: sErrorlog = ACErrorlog(error_at = time, error_name = str(e)) sErrorlog.save() sAcconDetail = "" return render(request,"accon/accon.html",{'sAcconDetail': sAcconDetail})