Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Errors using _thread, why?

    Scheduled Pinned Locked Moved LoPy
    lopythread
    4 Posts 2 Posters 1.1k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Z Offline
      zceld
      last edited by zceld

      Why is this error? It's the first test I do with _thread and everything was working fine but it has been putting the file in a different Lopy and it does not work out those errors:

      0_1524764912125_Captura de pantalla 2018-04-26 19.00.32.png

      The code is this:

      #   Revisado y actualizado el 26 de Abril de 2018 By Jotxee
      import _thread
      import machine
      import math
      import network
      import os
      import time
      import utime
      import pycom
      
      #Iniciar nuevo thread:  _thread.start_new_thread
      # setup LoRa:
      from network import LoRa
      import socket
      lora = LoRa(mode=LoRa.LORA)
      s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
      
      ### Funciones
      
      def iniciarWifi(dorsal):
          try:
              import network
              from network import WLAN
              wlan = network.WLAN(mode=network.WLAN.STA)
              wlan.init(mode=WLAN.AP, ssid=dorsal, auth=(WLAN.WPA2,'witeklab@2018'), channel=1, antenna=WLAN.INT_ANT)
              from network import Server
              server = Server(login=('micro', 'python'), timeout=600)
              server.timeout(300)
              server.timeout()
              server.isrunning()
              return True
          except:
              return False
      
      def existe(arg):
          try:
              fichero = open(arg)
              fichero.close()
              return True
          except:
              return False
      
      def pulsaciones(color):
          for x in range(3):
              pycom.rgbled(color)
              time.sleep(0.1)
              pycom.heartbeat(False)
              time.sleep(0.1)
      
      def ConfirmacionLed(funcion):
          funciones={'bluetooth':0x0007F,'gpsok':0xfffe02,'nogps':0x7f0000,'encendido':0x7f700,'sendalert':0xC011EB,'buscandoalerta':0xffffff}# wifi(azul) | gpsok(Amarillo) | nogps(rojo) | encendido(verde) | sendalert(lila)| -gpsok(amarillo) | buscandoalerta(blanco)
          pulsaciones(funciones[funcion])
      
      
      def resetDocument():
          #Lista de documentos posible: alerta.txt | dorsal.txt | myposition.txt | registro.txt | seguidores.txt
          lista = ['alerta','dorsal','myposition','registro','seguidores']
          for i in lista:
              if existe(i+'.txt'):
                  print('Borrando',i+'.txt')
                  os.remove(i+'.txt')
      
      def buscarMensajes(dorsal):
          alertas=[]
          while True:
              ConfirmacionLed('buscandoalerta')
              tiempo = time.time()
              s.setblocking(True)
              data = s.recv(128)
              if existe('dorsal.txt'):
                  a = open('dorsal.txt')
                  dorsal = a.read()
              print("Mensaje recibido:",data)
              ide =data.decode("utf-8")  #identificacion
              ide = ide.split('-')
              if ide[0] == 'alerta':
                  if ide[1] not in alertas:
                      tmp = tiempo
                      alertas.append(ide[1])
                      cuenta = 0
                      for z in ide[1]:
                          if z ==";":
                              cuenta+=1
                              #print("Cuenta-->",cuenta)
                      if cuenta == 1:
                          print("Este mensaje es personalizado:",ide[1])
                          dor = ide[1].split(';')
                          if dor[0]==dorsal:
                              ConfirmacionLed('bluetooth')
                              f = open ('alertapersonalizada.txt', 'a')#Modo 'a' Para a�adir no sobre escribir
                              #print("Mensaje que se guardara = ",dor[1])
                              f.write(dor[1]+"|")
                              f.close()
                      else:
                          print("Alerta Generica",ide[0])
                          ConfirmacionLed('bluetooth')
                          f = open ('alerta.txt', 'a')#Modo 'a' Para a�adir no sobre escribir
                          f.write(ide[1]+"|")
                          f.close()
                  else:
                      print("Tiempo-",tiempo,"tmp",tmp,"=",tiempo-tmp)
                      if tiempo-tmp >= 300:
                          #Si han pasado 5 minutos Borramos array alertas y ficheros del LoPy:
                          if existe('alerta.txt'):
                              os.remove('alerta.txt')
                          elif existe('alertapersonalizada.txt'):
                              os.remove('alertapersonalizada.txt')
                          del alertas[:]
                          tmp = tiempo
                  print("Asi estan las alertas=",alertas)
              elif ide[0] == 'seguidores':
                  dor = ide[1]
                  ide = ide[1].split(';')
                  print("Dorsal destino:",ide[0])
                  if ide[0]==dorsal:
                      print("dentro del mismo dorsal: ",dor)
                      ConfirmacionLed('bluetooth')
                      f = open ('seguidores.txt', 'w')#Modo 'a' Para a�adir no sobre escribir
                      f.write(dor)
                      f.close()
      def recogerPosGPSMovil():
          x = open('myposition.txt')
          x = x.read().split(';')
          lat_d = x[0]
          lon_d = x[1]
          return(lat_d, lon_d)
      
      def enviarPos(dorsal):
          j=0
          while True:
              if existe('myposition.txt'):
                  coord = recogerPosGPSMovil()
              else:
                  coord = (0,0)
              if existe('dorsal.txt'):
                  a = open('dorsal.txt')
                  dorsal = a.read()
                  print("Dorsal:",dorsal)
              x = "witeklab-"+str(j)+"-"+str(dorsal)+"-"+str(coord[0]) + "-"+str(coord[1])
              
              time.sleep(5)
              s.send(x)
              ConfirmacionLed('gpsok')
              print("Coordenadas enviadas:",x)
              j+=1
              time.sleep(30) #Pausa entre toma de coordenadas.
      
      ###     Variables
      dorsal = "Runner3NoGPS"
      
      ###     Main
      resetDocument()
      iniciarWifi(dorsal)
      print('1-> Iniciamos primer hilo Con la busqueda de mensajes:')
      _thread.start_new_thread(buscarMensajes, (dorsal,))
      print('2-> Iniciamos la busqueda de GPS (Fichero o localización)')
      _thread.start_new_thread(enviarPos,(dorsal,))
      print("-----")
      

      Enlargement of the image of the errors, in case it does not look good:

      0_1524765405136_Captura de pantalla 2018-04-26 19.50.22.png

      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jmarcelino @zceld
        last edited by

        @zceld
        From the log it looks like you're running a very old version of the firmware (November 2017), maybe the other LoPy was more up to date?

        Z 1 Reply Last reply Reply Quote 0
        • Z Offline
          zceld @jmarcelino
          last edited by

          @jmarcelino

          hi!

          Well ... it can be, although if that is the case, the firmware update program does not work correctly.

          I wanted to check at the time if it had been updated correctly. But I gave failures (1) as I happened in his day and I think it was because I did not have the pycoproc library and I assumed that it had been done well.

          (1) The failures I gave was because I could not find the library inside the module.

          • The code that petaba me when I wanted to look at the version is this:
          from pytrack import Pytrack
          py = Pytrack()
          py.read_fw_version()
          print("Version=",py.read_fw_version())
          
          • La herramienta que he usado para actualizar es ésta:
            0_1524771158823_Captura de pantalla 2018-04-26 21.32.28.png

          I will have to look at myself as I did in his day. Because I remember that I had problems too. Honestly the process in the documentation is not very clear.

          Because once you put the bridge on the board between port Gnd and 23, you have to keep the button pressed while you connect to the updater or not?

          In any case, try both. But the other time it seems to me that it only worked well with the terminal commands.

          I also have not had more time today to continue testing.

          1 Reply Last reply Reply Quote 0
          • Z Offline
            zceld
            last edited by

            @jmarcelino

            https://forum.pycom.io/topic/2431/lopy-with-pytrack-how-connect-use-gps

            The same thing happens to me, but indicating another error that already happened to me with the first Lopy.
            Right now they are other Lopy but theoretically updated with the software:
            0_1525354381112_Captura de pantalla 2018-05-03 15.32.33.png

            But now I get this error:
            0_1525354487312_Captura de pantalla 2018-05-03 15.34.38.png

            I have tried all the ways I've seen of how to update the Lopy board or the expansion Board 2.0.

            If I try to update the expansion board as I did in its day, it does not detect it anymore:
            0_1525354676638_39b2c6d3-3f17-438f-8d3b-e419a0dc5c88-image.png Captura de pantalla 2018-05-03 15.37.08

            and if I do the lopy update for the official software it says 'done' but it still does not work ... Does anyone know what's going on?

            0_1525356197239_Captura de pantalla 2018-05-03 15.42.03.png

            0_1525356215493_Captura de pantalla 2018-05-03 16.02.42.png

            Another curious fact is that I put the program file main.py or boot.py with the program that I have set does not work. but sometimes that other without jumping the error that I just porner up sometimes runs it well from Atom ...?

            I sincerely believe I have tried all the ways to update the Lopy and supposedly the expansion board is updated. Therefore, I do not know what is failing.

            If someone can tell me what would be the process of update contract both the expansion board and the Lopy on Mac or Windows I do not care. But to verify that it can happen.

            regards.

            1 Reply Last reply Reply Quote 0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • 1 / 1
            • First post
              Last post

            Pycom on Twitter

            Pycom