.net core 学习笔记

2017年03月11日

1.学习环境/系统环境

  • Linux 4.4.0-21-generic #37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

  • vscode 1.10.2

  • .net core 1.0.1 下载地址

系统是linux minit, ide为微软的vscode,.net core的版本为1.0.1。

通过上面的超链接地址和安装说明,跟着敲就完成了.net core的安装。

2.helloworld并在vscode中运行调试

1
2
3
4
dotnet new console -o hwapp
cd hwapp
dotnet restore
dotnet run

上面代码运行了一个hello world的demo,接着用vscode打开,安装好c#的扩展,运行调试是按F5,第一次需要修改launch.json中的program值。

原来的如下:

1
"program": "${workspaceRoot}/bin/Debug/<target-framework>/<project-name.dll>"

修改为:

1
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.1/hwapp.dll"

再按F5,已经能在vscode中输出Hello World了!

scrapy学习笔记

1.安装就遇到问题

pip install scrapy
会遇到缺少openssl的问题,所以需要提前安装openssl

1
sudo apt-get install libssl-dev

如果还是不放心,直接把所有依赖都先安装:

1
sudo apt-get install python-dev python-pip libxml2-dev libxslt1-dev zlib1g-dev libffi-dev libssl-dev

docker学习笔记

一.Q&A

1.更改Docker的默认存储位置

在ubuntu中默认的位置是/var/lib/docker,更改可以使用Linux软连接的方式。
例如搬移到/media/disk2/docker

迁移docker存储目录
1
2
3
4
$ sudo /etc/init.d/docker stop
$ sudo mv /var/lib/docker /media/disk2/
$ sudo ln -s /media/disk2/docker/ /var/lib/docker
$ sudo /etc/init.d/docker start

注意:由于我的disk2是ntfs的外接硬盘,把docker的根目录通过软连接指定到ntfs目录下后,运行docker run -it ubuntu bash 是没反应的。

把/var/lib/docker/ 目录删除后,重新启动docker,是会自动重新建立的。

esp8266实验:搭建最小系统,刷nodemcu固件,dht11温度读取并上传服务器

1.材料清单

  • esp8266-12E模块
  • esp8266转接板
  • cp2102模块 or ch304g模块
  • 轻触开关
  • 洞洞板
  • HT7533A-1 3.3v稳压芯片
  • 3.7v锂电池
  • DHT11温度湿度模块

2.焊接esp8266转接板,制作测试底板

esp8266模块不是特别小,实际使用可以直接把它焊在洞洞板上,但是作为反复使用的话,建议焊接到转接板上。洞洞板上主要元件有左右各两排排针,引出所有io口,两个按钮,左边按钮按下拉低rest口,实现重启,右边按钮拉低GPIO0(模块右边第五个引脚)口,刷入固件的时候需要按下该按钮。左边有一个ht7533稳压管和2个10uf的电容组成的稳压电路。下面有个排针,用来插入cp2102 usb转串口模块。

Read More

arduino读取ps2摇杆值

ps2摇杆可以任意方向操作,原理是2个可变电位器组成,任意方向分别用X和Y轴表示。

使用arduino的读取摇杆模块的2个模拟输出值,需要注意的是,从模拟口uno的A0-A5读取的模拟值为0-1023,但是由于模块的电位器质量或者电器干扰问题,摇杆不动的情况下,读取的数值也是不断在一个区间跳动的,所以需要做个优化。
通过对数值跳动的观察,发现她在498-497,493-494之间跳动,把摇杆按到尽头,也常在1023-1022之间跳动。因此只需要一个简单的map函数可以把读数稳定到一个稳定的区间上,这里的关键语句是:int tmp_x_value =map(analogRead(XPIN),0,1023,0,255);
具体代码如下:

arduino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
摇杆读取
摇杆为两个可变电位器组成
arduino 模拟端口读取的值为0-1023
pwm的值为0-255
用map映射值后摇杆不动值为124,122
*/
#include <stdio.h>
#define XPIN A0
#define YPIN A1
#define XSTOPNUM 124
#define YSTOPNUM 122
void setup() {
// put your setup code here, to run once:
pinMode(XPIN, INPUT);
pinMode(YPIN, INPUT);
Serial.begin(9600);
Serial.println("setup success");
}
int x_value;
int y_value;
void loop() {
// put your main code here, to run repeatedly:
int tmp_x_value =map(analogRead(XPIN),0,1023,0,255);
int tmp_y_value=map(analogRead(YPIN),0,1023,0,255);
if (tmp_x_value != x_value || tmp_y_value!=y_value) {
x_value=tmp_x_value;
y_value=tmp_y_value;
char msg[6];
sprintf(msg,"x:%3d",x_value);
Serial.print(msg);
sprintf(msg,",y:%3d",y_value);
Serial.println(msg);
}
}

搬迁腾讯存储

一开始个人网站使用的是wordpress部署,后来发觉低浏览确购买一台虚拟机还是不够环保,就静态化后放到aws上,可惜国内访问不稳定,s3在国内对大点的图片访问很慢。

后来换成阿里云的oss,速度很快价格也很便宜,不过有2个很大的问题,第一个是必须备案且备案的公司必须是阿里云,第二是支持的默认页面index.html不是相对地址。例如浏览http://wwww.lixin.me 会定位到http://wwww.lixin.me/index.html ,而浏览http://wwww.lixin.me/blog/ 不会显示http://www.lixin.me/blog/index.html 内容而是同上面的首页,这就比较麻烦了,又写了个脚步吧所有网址加上index.html。

用了段时间,想换个hexo的模板,发觉模板的一些内容还是没能够配置为index.html结尾,所以只能搬迁,上了腾讯云看了看,是支持相对目录的index.html 首页的,于是切换过来,而且腾讯云的cos存储要求低一点点,只要有备案就好。同时发现腾讯的cos存储网页控制端,可以直接拖放上传多个文件夹,操作十分方便,而阿里云则需要使用工具才能上传多个文件夹及文件。
为了每次方便更新文件到腾讯云存储,使用腾讯云提供的python sdk编写一个自动上传网站的脚本。
我的博客是放在存储bucket对象下的/blog目录之下,blog中使用的资源存放在/blog/static目录下。

自动上传博客文件到腾讯云存储
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
import os
import qcloud_cos
'''
发布博客到腾讯云cos上面去
腾讯云上面对应的根目录为/blog
'''
COS_APPID=125100066
COS_SECRET_ID=u'<>'
COS_SECRET_KEY=u'<>'
COS_REGION_INFO='guangzhou'
currentPath=os.path.dirname(os.path.abspath(__file__))
cos_client=None
lastChange={}#文件路径和最后修改时间
if os.path.exists(os.path.join(currentPath,'lastchange.txt')):
with open(os.path.join(currentPath,'lastchange.txt'),'r') as f:
for line in f:
item=line.split(',')
lastChange[unicode(item[0],'utf-8')] = float(item[1])
def upload(remotePath,localPath):
global cos_client
if cos_client==None:
cos_client=qcloud_cos.CosClient(COS_APPID,COS_SECRET_ID,COS_SECRET_KEY,COS_REGION_INFO)
request=qcloud_cos.UploadFileRequest(u'wwwlixinme',unicode(remotePath) ,unicode( localPath))
request.set_insert_only(0)
upload_file_ret = cos_client.upload_file(request)
print upload_file_ret
def scanPath(pathname,remotePre=''):
for root,path,filelist in os.walk(os.path.join(currentPath,pathname)):
for filename in filelist:
fullPath =unicode( os.path.join(root, filename),'utf-8')
mtime=float(os.path.getmtime(fullPath))
if fullPath in lastChange:
if mtime-lastChange[fullPath]>1:
lastChange[fullPath]=float(mtime)
remotePath=fullPath.replace(os.path.join(currentPath,pathname),'/blog/'+remotePre)
upload(remotePath,fullPath)
else:
lastChange[fullPath]=float(mtime)
remotePath=fullPath.replace(os.path.join(currentPath,pathname),'/blog/'+remotePre)
upload(remotePath,fullPath)
if not os.path.exists(os.path.join(currentPath,'static')) or not os.path.exists(os.path.join(currentPath,'blog')):
print '当前目录不存在./blog或者./static目录'
exit(1)
scanPath('blog/public/')
scanPath('static/','static/')
with open(os.path.join(currentPath,'lastchange.txt'),'w') as f2:
for key in lastChange:
f2.write('%s,%f\n' % (key.encode('utf-8'), lastChange[key]))

esp8266 sdk 学习笔记

安装编译环境

编译器的安装根据官方文档使用virtualBox虚拟机镜像,下载个ESP8266_lubuntu_20141021.ova的文件然后使用virtualBox导入即可使用,不需要自己折腾。

下载sdk,在官网下载了最新的esp8266_nonos_sdk_v2.0.0sdk,解压,顶层目录结构这样子:

├─bin
├─documents
├─driver_lib
├─examples
├─include
├─ld
├─lib
└─tools

这里讲一下3个目录
bin: 编译后生成的固件会在这个目录里。
driver_lib: 外围设备驱动,例如uart。
examples: 示例代码,通常自定义开发我都是在里面找一个简单的copy出来删除不需要的逻辑。

Hello world 开始

根据传统,在sdk的根目录下新建一个名字叫app的目录,实际上这个目录任何命名都是可以的,在examples目录里找一个smart_config的目录,把目录里的文件全部拷贝到app目录下,或者把smart_config目录拷贝到根目录,然后重新命名为app:
-app
├─include
├─user
├─gen_misc.bat
├─gen_misc.sh
├─Makefile

编辑app/user/user_main.c文件,删去不需要的代码,保留3个函数

user_rf_cal_sector_set
: 保留该函数和函数的内容,这个函数是必备的。

user_rf_pre_init
: 改函数也是必备的,不过空着它就行了。

user_init
: 这个是用户程序的入口,也是必备的,它就像arduino·中的setup函数一样。

第一个例子是hello world,要在串口输出“hello world”。

首先引入外围驱动的uart.h 库文件,它在driver_lib目录里,找到uart.cuart.h两个文件,把’uart.h‘文件复制到app/include目录下,把uart.c文件复制到app/user/目录下。

编辑user_init文件,引入头文件:

#include “osapi.h”

#include “driver/uart.h”

#include “user_interface.h”

user_init函数里,设定uart的波特率

1
2
> uart_init(115200,115200);
> os_printf("\nHello World\n");

命令行进入app目录下运行gen_misc.sh脚本,然后有5步选择,我前4步都是默认回车,第五步选择4,如果顺利,最后应该显示这样子:
!!!
No boot needed.
Generate eagle.flash.bin and eagle.irom0text.bin successully in folder bin.
eagle.flash.bin——–>0x00000
eagle.irom0text.bin—->0x10000
!!!

下载程序到板子

烧录的程序使用的是FLASH_DOWNLOAD_TOOLS_V3.3.4_Win 这个官方程序,首次下载需要4个bin文件,这些文件都在bin目录下
esp_init_data_default.bin
: 根据esp8266-sdk-getting_started_guide_cn.pdf 中第4.1.2节中的下载地址,选择“0x3FC000”

blank.bin
: 选择“0x3FE000”
eagle.flash.bin
: 选择“0x00000”
eagle.irom0text.bin
: 选择“0x10000”

记得勾选每行前面的复选框,这样才会下载该内容到板子上。

软件定时器使用

定义一个定时器

1
> os_timer_t myTimer;

定义定时器回调函数

1
2
3
4
void ICACHE_FLASH_ATTR
myTimer_Tick(){
os_printf("hello\n");
}

最后就是定义这个定时器

1
2
3
os_timer_disarm(&myTimer);//在设置定时器之前,应该使其停止运行
os_timer_setfn(&myTimer,&myTimer_Tick,NULL);//设置该定时器的回调函数为myTimer_Tick
os_timer_arm(&myTimer,3000,TRUE);//设置定时器的周期是3秒,并且是循环调用

diy单级电池电机

diy单级电池电机

材料:

干电池,最好是新的

强力磁铁

铜线,从电线里抽出来的

要点:

下方的弯处要能和磁铁接触到。