WeUI球猫说好就好

演示:
https://weui.io
官方:
https://github.com/weui/weui

<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0" />
<link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/1.1.3/weui.min.css" />

<body ontouchstart>

页面主操作

感觉蛮清凉的

参考:
https://www.jianshu.com/p/be2233610f80

串口还需要权限

写了个串口操作的程序,结果提示cannot open /dev/ttyS1: Permission denied

pi@NanoPi-NEO2:~$ ls /dev/ttyS* -l
crw------- 1 pi   tty     4, 64 Feb 13 16:11 /dev/ttyS0
crw-rw---- 1 root dialout 4, 65 Feb 12  2016 /dev/ttyS1
crw-rw---- 1 root dialout 4, 66 Feb 12  2016 /dev/ttyS2
crw-rw---- 1 root dialout 4, 67 Feb 12  2016 /dev/ttyS3

sudo cp /etc/udev/rules.d/50-mali.rules /etc/udev/rules.d/52-ttl.rules
sudo vi /etc/udev/rules.d/52-ttl.rules
KERNEL=="ttyS1", GROUP="pi", OWNER="pi"
sudo reboot now

pi@NanoPi-NEO2:~$ ls /dev/ttyS* -l
crw------- 1 pi   tty     4, 64 Feb 13  2020 /dev/ttyS0
crw-rw---- 1 pi   pi      4, 65 Feb 12  2016 /dev/ttyS1
crw-rw---- 1 root dialout 4, 66 Feb 12  2016 /dev/ttyS2
crw-rw---- 1 root dialout 4, 67 Feb 12  2016 /dev/ttyS3

- 阅读剩余部分 -

luat的串口库

--功耗低不需要串口时调用pm.sleep("testUart")
pm.wake("testUart")
--注册串口收到数据后以中断方式调用read接口读取数据
uart.on(UART_ID,"receive",read)
--配置并且打开串口
uart.setup(UART_ID,9600,8,uart.PAR_NONE,uart.STOP_1)
--向设备发送0x01 0x02 0x03三个字节
write(string.fromHex("010203"))

--发送串口数据
function write(s)
log.info("testuart.write",s:toHex(),s)
uart.write(UART_ID,s)
end

--接收串口数据
local function read()
local data = ""
while true do
data = uart.read(UART_ID,"*l")
--数据不存在时停止接收数据
if not data or string.len(data) == 0 then break end
--打开下面的打印会耗时
log.info("testUart.read bin",data)
log.info("testUart.read hex",data:toHex())
--真正的串口数据处理函数
proc(data)
end
end

参考文献:
https://wiki.openluat.com/doc/luatApi/#uartsetup
https://wiki.openluat.com/doc/luatApi/#uarton-id-event-callback
https://ask.openluat.com/article/25

python正则表达式

写了一段python跟踪网络文学更新的代码,球猫说用正则分析网页更好,尝试学习之

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os.path as Path
import threading
import time
import shutil
import urllib2
import urllib
import requests
import json
fn=''
def wx(ip):
  print ip
  adata = {
    "msgtype": "markdown",
    "markdown": {
        "content": ip
    }
  }
  aheaders = {'Content-Type': 'application/json'}
  url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=3fff2eb1-a575-7777-f9a2-9813c7857777"
  response = requests.post(url, headers=aheaders, data = json.dumps(adata))
  print response.text
def heart_beat():
  global fn
  url = "https://m.999xs.com/"
  ip = "0.0.0.0"
  try:
    req = urllib2.Request(url)
    res_data = urllib2.urlopen(req)
    ip = res_data.read()
  except:
    print "error"
  try:
    p1=ip.find('<p>更新')
    p2=ip.find('章</a></p>')
    ip=ip[p1:p2+24]
    p2=ip.find('</a></p>')
    ip=ip[0:p2+8]
    print('\n')
    print(ip)
    print('\n')
    if fn!='':
      if fn != ip:
        wx(ip)
        fn = ip
    else:
      fn = ip
  except:
    print "error12"
  threading.Timer(600, heart_beat).start()
wx('xiaoshuo start...')
threading.Timer(10, heart_beat).start()

- 阅读剩余部分 -

python上报IP

通过http://wy.mikuq.com/api/ip/获取本地IP上报给MikuQ

import paho.mqtt.client as mqtt
import threading
import time
import urllib2

url = "http://wy.mikuq.com/api/ip/"

client = mqtt.Client()
client.connect("mikuq", 1883, 50)

def heart_beat():
    mydt = time.strftime('%Y-%m-%d %H:%M:%S')

    ip = "0.0.0.0"

    try:
      req = urllib2.Request(url)
      res_data = urllib2.urlopen(req)
      ip = res_data.read()
    except:
      print "error"

    print mydt, ip

    global client
    client.publish("mqtt/timer", "{\"time\":\"" + mydt + "\",\"ip\":\"" + ip + "\"}")
    threading.Timer(10, heart_beat).start()

heart_beat()
client.loop_forever()

- 阅读剩余部分 -