Navigation

    M5Stack Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. mario
    M
    • Continue chat with mario
    • Start new chat with mario
    • Flag Profile
    • Profile
    • Following
    • Followers
    • Blocks
    • Topics
    • Posts
    • Best
    • Groups
    Save
    Saving

    mario

    @mario

    2
    Reputation
    14
    Posts
    2285
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    mario Follow

    Posts made by mario

    • RE: ESP-NOW and two M5Stick C

      Well, I hadn't thought of that! It reminded me of my MSX programming days. :D

      I'll try your proposal and I'll let you know.

      Thank you very much @world101 for your reply.

      posted in General
      M
      mario
    • ESP-NOW and two M5Stick C

      I am experimenting with ESP-NOW and two M5Stick Cs.

      The application is designed for two people living in the same house. The two people are often in their own rooms studying. And they scare each other to death when they enter the room to discuss something.

      The application is designed so that when one of the two people goes to visit the other, clicks on button A, a 5-second timer starts. If the other person does not want the visit because they are in a moment of concentration, they press the A button on their device and a message appears on the device of the person who sent the request that it is not a good time with a red circle. If he/she does nothing, a green circle shows that the invitation to the meeting is agreed by both.

      I have been able to get it, except for the part where the other person clicks the A button, it does nothing. It continues the counter and does not show the red circle.

      I don't know if it's the nature of the ESP-NOW communication or if it's because something is wrong with my programming.

      0_1612696956071_a.png
      0_1612696967603_b.png

      from m5ui import *
      from uiflow import *
      import espnow
      import wifiCfg
      import time
      
      setScreenColor(0x111111)
      
      
      status_str = None
      my_mac_addr = None
      a = None
      d = None
      f = None
      status = None
      mynameis = None
      i = None
      
      wifiCfg.wlan_ap.active(True)
      wifiCfg.wlan_sta.active(True)
      espnow.init()
      circle0 = M5Circle(40, 115, 32, 0xe60909, 0xFFFFFF)
      status_label = M5TextBox(74, 6, "status_label", lcd.FONT_Default, 0xFFFFFF, rotate=90)
      count_label = M5TextBox(17, 83, "5", lcd.FONT_DejaVu72, 0xFFFFFF, rotate=0)
      console_log = M5TextBox(12, 11, "console_log", lcd.FONT_DefaultSmall, 0xa9a4e6, rotate=90)
      mynameis_label = M5TextBox(52, 11, "My name is:", lcd.FONT_DefaultSmall, 0xFFFFFF, rotate=90)
      
      
      def longblink():
        global status_str, my_mac_addr, f, a, d, status, mynameis, i
        M5Led.on()
        wait_ms(500)
        M5Led.off()
      
      def hello_from_the_other():
        global status_str, my_mac_addr, f, a, d, status, mynameis, i
        count_label.hide()
        shortblink()
        circle0.show()
        for i in range(6):
          circle0.setBgColor(0xffffff)
          circle0.setSize((i * 6 + 8))
          wait(1)
          if status != 'hello':
            circle0.setBgColor(0xff0000)
            longblink()
            break
          if i == 5:
            circle0.show()
            circle0.setBgColor(0x33cc00)
            shortblink()
        restart()
      
      def inicialize():
        global status_str, my_mac_addr, f, a, d, status, mynameis, i
        mynameis_label.setText(str(mynameis))
        count_label.hide()
        circle0.hide()
        status = 'waiting'
        status_label.setText(str(status))
      
      def hello():
        global status_str, my_mac_addr, f, a, d, status, mynameis, i
        count_label.show()
        shortblink()
        for i in range(5, -1, -1):
          count_label.setText(str(i))
          wait(1)
          if status != 'hello':
            circle0.show()
            circle0.setBgColor(0xff0000)
            longblink()
            break
          if i == 0:
            circle0.show()
            circle0.setBgColor(0x33cc00)
        restart()
      
      def shortblink():
        global status_str, my_mac_addr, f, a, d, status, mynameis, i
        M5Led.on()
        wait_ms(50)
        M5Led.off()
      
      def restart():
        global status_str, my_mac_addr, f, a, d, status, mynameis, i
        wait(6)
        inicialize()
      
      def change_status(status_str):
        global my_mac_addr, f, a, d, status, mynameis, i
        status = status_str
        status_label.setText(str(status))
        espnow.send(id=1, data=str(status))
      
      
      
      my_mac_addr = str((espnow.get_mac_addr()))
      if my_mac_addr==:
        mynameis = 'Alice'
        espnow.add_peer('24:a1:60:45:6a:3d', id=1)
      elif my_mac_addr==my_mac_addr:
        mynameis = 'Bob'
        espnow.add_peer('d8:a0:1d:56:b9:59', id=1)
      else:
        mynameis = "I don't know"
      inicialize()
      
      def buttonA_wasPressed():
        global my_mac_addr, f, a, d, status, mynameis, status_str, i
        if status=='waiting':
          change_status('hello')
          hello()
        elif status=='hello':
          change_status('right_now_no_thanks')
        else:
          pass
        pass
      btnA.wasPressed(buttonA_wasPressed)
      
      
      def send_cb(flag):
        global my_mac_addr,f,a,d,status,mynameis,status_str,i
        f = flag
        if f:
          shortblink()
        else:
          status = 'not connected'
          status_label.setText(str(status))
          longblink()
          shortblink()
          longblink()
          shortblink()
      
        pass
      espnow.send_cb(send_cb)
      
      
      
      def recv_cb(_):
        global my_mac_addr,f,a,d,status,mynameis,status_str,i
        a, _, d = espnow.recv_data(encoder='str')
        shortblink()
        console_log.setText(str(d))
        if d=='hello':
          status = 'hello'
          status_label.setText(str(status))
          hello_from_the_other()
        elif d=='right_now_no_thanks':
          status = 'right_now_no_thanks'
          status_label.setText(str(status))
        else:
          pass
      
        pass
      espnow.recv_cb(recv_cb)
      

      esp_now_busy.m5f file in MEGA

      posted in General
      M
      mario
    • RE: Ayuda para encontrar "Manual"

      Hola.

      De momento la única documentación disponible está en inglés (que yo sepa): https://docs.m5stack.com/#/

      Saludos

      posted in Foro español
      M
      mario
    • M5Stick C, label with font DejaVuSans72 and rotation 90 you can't see on screen

      Device: M5Stick C
      Firmware: v1.7.2
      Version of UIFLow: UIFlow-Desktop-IDE v1.4.5 and UIFlow-Desktop-IDE Beta V1.6.6
      Steps: Label with font DejaVuSans72 and rotation 90 you can't see on screen
      Code: https://pastebin.com/5gR7dB0f

      IDE:
      0_1612457290178_test_font_dejavu.PNG
      What you get:
      0_1612457439937_what_you_get_font_dejavu.PNG

      posted in Bug Report
      M
      mario
    • RE: Gracias

      @amiimag Claro!: https://discord.gg/PFff5b tienes 24 horas (no tiene mucho movimiento, no te vamos a engañar)

      posted in Foro español
      M
      mario
    • http - get method - It does not send pairs name-value

      Hi,
      I am an accredited rookie ;-)

      When I try to send data through http, with the get method, it doesn't send the names and values pairs.

      UIflow with blocks:
      0_1580587604450_fba0daa1-709d-44d3-90cb-a8c1c9a73f2f-image.png

      When I look at the code, I don't see it send the string with the name and value pair.
      0_1580587570327_24d07e1c-3e64-4456-ac06-7f9982fede37-image.png

      According to this web page, the program would have to send you the data arguments.
      https://makeblock-micropython-api.readthedocs.io/en/latest/public_library/Third-party-libraries/urequests.html#urequests.request
      I have tried to write by hand, without success.

      Have any of the readers succeeded, send data to a server via http?

      This is the server code, written for node js, in case you want to try it at: https://repl.it/ o en https://glitch.com/

      var http = require('http');
      var url = require('url');
      
      var x_gyr = 0.0;
      
      /* https://echo-data-get-method-http-get.mariomoreno2020.repl.run/t.htm?x=15 */
      
      http.createServer(function (req, res) {
        // Set CORS headers
      	res.setHeader('Access-Control-Allow-Origin', '*');
      	res.setHeader('Access-Control-Request-Method', '*');
      	res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET, POST, PUT');
      	res.setHeader('Access-Control-Allow-Headers', '*');
        res.statusCode = 200;
        //
        res.writeHead(200, {'Content-Type': 'text/html'});
        var q = url.parse(req.url, true);
        console.log(q.href);
        if (q.pathname == '/t.html') {
          q = q.query;
          x_gyr = q.x;
        }   
        var txt = 'x= ' + x_gyr;
        res.end(txt);
      }).listen(8080);
      

      Remember that the http block, the url is 'http' instead of 'https'.

      And if you want to try the UIFlow code, here is a download link. You can see how in the blocks it sends data and in the python code no.
      https://mega.nz/#!YY82UIrB!fskiB3YAn1hQH6rCcbwzjiuJO5-Fz0H4LBr6LZ4WtjI

      posted in General
      M
      mario
    • RE: Enviar datos de M5Stick C al exterior.

      El cabrito de UIflow, no pone nada en el código sobre mis datos (los pares, nombre-valor, x=1.5) cuando convierto los bloques a código:

      0_1580585081634_f21746ed-ae79-46db-b336-6344c9cf0218-image.png

      El codigo:

      0_1580585209155_d7bf9b85-9f61-40b6-bab9-cc243506fd1e-image.png

      Leyendo sobre mycropython, tendria que haber un argumento 'data' que no aparece: https://makeblock-micropython-api.readthedocs.io/en/latest/public_library/Third-party-libraries/urequests.html#urequests.request

      En fin, si descubro algo sigo compartiendo.

      posted in Foro español
      M
      mario
    • RE: Enviar datos de M5Stick C al exterior.

      @mario said in Enviar datos de M5Stick C al exterior.:

      Por otro lado, me muestra el circulo verde, como si que ha conseguido la conexión o ha recibido un OK del servidor, pero a continuación me muestra el círculo rojo, como que no.

      Bueno, este comportamiento lo he corregido, poniendo la url con 'http://' en lugar del 'https://'

      Lo publico aquí por si a alguien le puede ser de utilidad.

      (sique sin enviar los pares nombre y valor, lo que va detrás de '?')

      posted in Foro español
      M
      mario
    • Enviar datos de M5Stick C al exterior.

      Estoy con los primeros pasos de un proyecto mayor.
      ¿Habéis conseguido enviar datos por internet de con M5Stick C a un servidor?
      Por ejemplo, los valores del giroscopio.


      MQTT

      En un primer momento, lo he intentado con el protocolo MQTT (territorio desconocido para mí) siguiendo este tutorial:
      https://www.youtube.com/watch?v=5RozKI-3i4Q
      No me acabó de funcionar, aunque el comportamiento en pruebas hechas en días diferentes me hizo pensar que quizás era un problema del servicio gratuito online.

      Además me ocurría que no podía reproducir el programa cuando hacía cambios, necesité grabar la imagen con el M5Burner varias veces para poder enviar a través de la web del UIFlow los cambios de mi código a M5Stick C. Mi hipótesis es que entraba en bucle o se saturaba de conexiones y no permití conectarse via UIFlow via web.

      ¡Todo esto desde el desconocimiento y mis primeros pasos!

      (Por cierto, si lo hacéis el tutorial hay que hacer download, para que baje también la librería de MQTT, no basta con dar a reproducir -el triangulo-)


      HTTP

      Ahora estoy probando por aquí, pero bueno también soy nuevo en node js [...], así que no sé si alguien de vosotros o vosotras tiene alguna pista.

      0_1580239874401_imagen-datos-giroscopio.JPG

      Código de node js:

      var http = require('http');
      var url = require('url');
      
      var x_gyr = 0.0;
      var y_gyr = 0.0;
      var z_gyr = 0.0;
      
      http.createServer(function (req, res) {
        // Set CORS headers
      	res.setHeader('Access-Control-Allow-Origin', '*');
      	res.setHeader('Access-Control-Request-Method', '*');
      	res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET, POST, PUT');
      	res.setHeader('Access-Control-Allow-Headers', '*');
        //
        res.writeHead(200, {'Content-Type': 'text/html'});
        var q = url.parse(req.url, true);
        console.log(q.href);
        if (q.pathname == '/toma.htm') {
          q = q.query;
          x_gyr = q.x;
          y_gyr = q.y;
          z_gyr = q.z;
        }   
        var txt = x_gyr + ',' + y_gyr + ',' + z_gyr;
        res.end(txt);
      }).listen(8080);
      

      La idea es que cuando se accede a la url, se pueden leer los valores del giroscopio, si se hace con la url acabada en toma.htm?x=1.5&y=0.6&z=-0.12 se escriben los valores.

      repl.it está muy bien por que te permite editar el código, ver el resultado y consultar el terminal (en mi caso en node js).

      El problema que me estoy trabajando es que si que parece que se conecta a la url, pero no envia los datos después del '?'. He probado el método POST y GET.

      En la consola me aparece que si que accede a la URL acabada en toma.html, pero si pasar los datos:
      0_1580240591896_imagen-datos-nodejs-consola.JPG

      En cambio, si en el navegador abro una ventana de incognito, pongo la URL acabado como en ejemplo, toma.htm?x=1.5&y=0.6&z=-0.12, en la consola si que me aparece los números y el programa node js parece funcionar.

      Por otro lado, me muestra el circulo verde, como si que ha conseguido la conexión o ha recibido un OK del servidor, pero a continuación me muestra el círculo rojo, como que no. Sospecho que esto tiene que ver con el programa de nodejs, que es una jardín para otro foro...

      Os pongo el código en micropython por si quereis probar:

      from m5stack import *
      from m5ui import *
      from uiflow import *
      import imu
      import urequests
      
      setScreenColor(0x111111)
      
      
      
      imu0 = imu.IMU()
      title0 = M5Title(title="Datos", x=3 , fgcolor=0xFFFFFF, bgcolor=0xcb1a02)
      label_x_Gyr = M5TextBox(5, 23, "x_gyr", lcd.FONT_Default,0xFFFFFF, rotate=0)
      label_y_gyr = M5TextBox(5, 40, "y_gyr", lcd.FONT_Default,0xFFFFFF, rotate=0)
      circle0 = M5Circle(60, 143, 10, 0xFFFFFF, 0xFFFFFF)
      label_z_gyr = M5TextBox(4, 57, "z_gyr", lcd.FONT_Default,0xFFFFFF, rotate=0)
      
      enmarcha = None
      x_gyr = None
      y_gyr = None
      z_gyr = None
      
      
      def buttonA_wasPressed():
        global enmarcha, x_gyr, y_gyr, z_gyr
        enmarcha = not enmarcha
        if enmarcha:
          title0.setBgColor(0x33cc00)
        else:
          title0.setBgColor(0xff0000)
        pass
      btnA.wasPressed(buttonA_wasPressed)
      
      
      enmarcha = False
      while True:
        while enmarcha:
          x_gyr = imu0.gyro[0]
          y_gyr = imu0.gyro[1]
          z_gyr = imu0.gyro[2]
          label_y_gyr.setText(str(y_gyr))
          label_x_Gyr.setText(str(x_gyr))
          label_z_gyr.setText(str(z_gyr))
          try:
            req = urequests.request(method='GET', url='https://pon-aqui-tu-url.de.repl.co/toma.htm', headers={'Content-Type':'text/html'})
            circle0.setBgColor(0x006600)
          except:
            circle0.setBgColor(0xff0000)
          wait(1)
      

      El proyecto mayor es replicar el movimiento de M5Stick C, en la web: enviando los datos a un servidor y renderizando con la librería de javascript Three js, el modelo 3D en pantalla. Busco el WOW de amigos (estoy un poco loco, no? :D )
      Una idea inspirada en le proyecto de naninunenoy (https://github.com/naninunenoy/AxisOrange/blob/master/README.md, realizado en Unity y conectando por Bluetooth el M5Stick C y el ordenador, si lo he interpretado bien). Y si funciona bien y es fluido, hacer un juego! Por qué no? :D

      Ya lo compartiré, si lo consigo ;-)

      posted in Foro español
      M
      mario
    • Gracias

      Hola,

      en primer lugar, quiero dar las gracias por abrir el foro en español y también por este fantástico desarrollo de M5Stack.

      Me hubiera gustado descubrir antes M5Stack que el mundo Arduino,¡ no os quiero engañar!
      Después de hacer los primeros tutoriales (incluye el semáforo :) cuando quieres hacer un proyecto propio, al final necesitas más y más componentes.

      Por ejemplo, M5Stick C contiene todo lo que necesito para mi proyecto: autonomía con su bateria, comunicación con el exterior mediante wifi, y pantalla, entre otras cosas!
      Además con el fantástico interface UIFlow (programación por bloques), que te permite desarrollar rápidamente cualquier proyecto sin cerrar la puerta a aprender más cosas como micropython o arduino!.

      Aprovecho para abrir varias consultas y abriré en temas diferentes.

      ¡Saludos!

      posted in Foro español
      M
      mario