2月 16

stun服务器解决穿私网问题

未解决VOIP电话传私网问题(NAT),搭建stun服务器。简要记录如下

https://sourceforge.net/projects/boost/files/boost/1.63.0/boost_1_63_0.tar.gz
./bootstrap.sh
./bjam install

http://www.stunprotocol.org/
http://www.stunprotocol.org/stunserver-1.2.12.tgz
tar zxvf stunserver-1.2.12.tgz
cd stunserver-1.2.12
make
编译完成直接启动
./stunserver &

查看端口
lsof -i:3478

端口已经监听,配置到VOIP设备测试,一切正常。

2月 11

nodemcu esp8266 micropython 学习

购买esp8266学习python开发单片机。
esp6288板子

下载windows用的刷固件工具
https://github.com/nodemcu/nodemcu-flasher
下载编译文件的下载位置
http://micropython.org/download#esp8266

启动刷固件工具选择固件
esp8266选择固件
开始刷机
esp8266刷固件

使用串口调试工具或者putty连上后就可以写代码了。我的串口是com4。
esp6288串口配置1
esp6288串口配置2
esp6288串口连接

刷新完毕,直接用3三色led实验GPIO。
esp6288测试led
代码如下,板子上表示的序号有误,测试了多次才对上。

from machine import Pin
import time
ll = [0, 4, 5]
for oneline in ll:
    Pin(oneline, Pin.OUT, value=1)
    time.sleep(3)
    Pin(oneline, Pin.OUT, value=0)
    time.sleep(1)

代码测试正常。开始测试无线。

使用help()可以看到连接WiFi部分和ap部分
import network
sta_if = network.WLAN(network.STA_IF); sta_if.active(True)
sta_if.scan() # Scan for available access points
sta_if.connect(““, ““) # Connect to an AP
sta_if.isconnected() # Check for successful connection
# Change name/password of ESP8266’s AP:
ap_if = network.WLAN(network.AP_IF)
ap_if.config(essid=”“, authmode=network.AUTH_WPA_WPA2_PSK, password=”“)

开启启动并上传文件。
将之前代码保存文件命名为main.py。使用http://www.w2bc.com/article/191374开发的小工据上传。
上传完毕,实验结果正常。查看系统main.py在系统中。
esp8266启动文件

收集文档
推荐站点
http://www.zhimadiy.top/

python的lib库
https://github.com/micropython/micropython-lib

固件
https://github.com/micropython/micropython

控制机械臂
http://forum.micropython.org/viewtopic.php?t=2441&p=14251

文档
http://docs.micropython.org/en/latest/esp8266/

开发图形 IDE

ESPlorer

1月 10

网页产生二级菜单的SQL优化

将菜单放一张表中,查询时通过用户id查到组id,然后再用组id查权限表,获得有权限的菜单id。
最后组装成两级菜单的数据。
数据列为菜单名,菜单链接,菜单级别,父菜单id,该级菜单的排序。sql如下:

CREATE TABLE `column` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(45) COLLATE utf8_bin DEFAULT NULL,
  `code` varchar(45) COLLATE utf8_bin DEFAULT NULL,
  `parent_id` int(11) DEFAULT NULL,
  `sort_no` int(11) DEFAULT NULL,
  `tree_path` varchar(300) COLLATE utf8_bin DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id_UNIQUE` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;


INSERT INTO `column` VALUES ('1', '网络运营', 'p0', '0', '1', null);
INSERT INTO `column` VALUES ('2', '系统管理', 'p9', '0', '9', null);
INSERT INTO `column` VALUES ('3', '开账户', 'p4', '1', '1', null);
INSERT INTO `column` VALUES ('4', '开业务', 'p66', '1', '2', null);
INSERT INTO `column` VALUES ('5', '财务', 'p2', '0', '2', null);
INSERT INTO `column` VALUES ('6', '用户查业务', 'p33', '5', '1', null);
INSERT INTO `column` VALUES ('7', '业务查用户', 'p55', '5', '2', null);
INSERT INTO `column` VALUES ('8', '查缴费', 'p99', '5', '3', null);
INSERT INTO `column` VALUES ('9', '客服', 'p44', '0', '4', null);

最初想是将表关联然后查找,sql如下:

select xc1.id as id1, xc1.name as name1, xc1.code as code1, xc1.parent_id as pid1, 
xc2.name as name2,xc2.code as code2 from column as xc1 
LEFT JOIN column as xc2 on xc2.parent_id = xc1.id 
where xc1.id in ( 
  select column_id from group_column as gr where group_id in( 
   select group_id from group_user where user_id=1
  ) 
) and xc2.id in ( 
  select column_id from group_column as gr where group_id in( 
   select group_id from group_user where user_id=1
  )  
) 
and xc1.parent_id=0 ORDER BY xc1.parent_id,xc1.sort_no,xc2.sort_no

这个sql有个缺点,一比较长,二获得权限部分写了两次。然后换个写法,先把有权限的选出然后再关联。

select xc2.id as id1, xc2.name as name1, xc2.code as code1, xc2.parent_id as pid1, 
  xc1.name as name2, xc1.code as code2 from (
	 select id,name,code,parent_id,sort_no from column where id in ( 
		select column_id from group_column as gr where group_id in( 
		  select group_id from group_user where user_id=1
		 ) 
    ) and parent_id <>0 ORDER BY parent_id,sort_no 
) as xc1
left join column as xc2 on xc1.parent_id=xc2.id 

因为只有10条数据,所以通过多次手动执行也没有发现性能差多少,但是短了不少。