master
iotcat 4 years ago
parent 3136f517d6
commit faa207e79b
  1. 114
      source/_posts/crown-place-erp.md
  2. 180
      source/_posts/smart-home.md
  3. 17
      source/_posts/wiot.md
  4. 301
      source/_posts/wiot2.md

@ -1,6 +1,6 @@
---
title: 公共开支结算系统
titleEN: Public expenditure settlement system
titleEN: Shared Expense Management System
display: true
date: 2019-09-22
categories:
@ -54,6 +54,7 @@ I studied in the UK and shared with 4 roommates. In order to better control and
- 监视各成员间支出不均衡程度,计算方差,并可视化显示
- 对比本周与上周的开支,给出增减比例
- 当存在一人支出超出均值阈值,并且存在至少一人支出少于均值阈值,则会邮件这两个人产生一次内部交易
- 邮件通知内部交易的双方
- 当上例中收款人收到款项后,需要到平台确认收到
- 平台所有历史公共开支及发票可查
@ -84,6 +85,60 @@ mail系统使用[Yimian Mail API](https://www.eee.dog/tech/mail-api.html)快速
![imgbed_a8b3adb0](https://api.yimian.xyz/img/?path=imgbed/img_a8b3adb0_1080x2160_8_null_normal.jpeg)
-----------------------
**2020-03-22 更新**
由于疫情原因,考虑到大家都已撤回中国。为节约服务器费用,停止提供服务。
结合过去半年运行状况,我做了一些分析总结:
## 主要收获
1. 分析客户真需求的经验
2. 快速搭建生产环境网站工具的能力
3. 室友对我能力的认可
## 开发方法论
1. 基于一系列自己过去的项目,3天时间快速立项并投入使用
2. 仔细研究需求,判断哪些是真需求,哪些是伪需求。
## 遇到的挑战
1. 快速开发,因为大家在抵达英国后已经开始大量花钱买公共用品,因此,急需使用这个系统
2. 算法一定要稳定可靠,因为是牵扯到大家钱的东西
3. 本系统的目的是为了更加方便,把会计的工作交给系统来自动化处理。以此一定要在保证公平的前提下,使得大家之间的内部交易的次数尽可能少,且指示明确。
4. 如何让大家对系统产生信任。
## 解决方法
1. 基于大量自己先前的项目。用1天开发成型,1天测试debug,1天优化前端,加入方差,百分比等功能。
2. 参考记账表,使用了表格模式。每次有新的上传,就会实时计算出新的状态。多次测试,充分验证后才投入使用。
3. 使用“平衡”的构想,关注差异,当差异过大时使支出最多者和支出最少者产生内部交易。且内部交易值为整数。比如我们生产场景应用的是20磅。
4. 在系统算法稳定的情况下,参考支付宝的设计。内部交易有两个步骤。首选支出者和收入者都收到邮件,告知给谁(从谁收),多少钱。然后在支出者把钱给收入者后,收入者需要登录网页或从邮件链接进行确认。截至此时,系统才认为一笔内部交易完成。
-------------------------------
**2020-9-8 更新**
基于Ushio用户系统,结合过去半年的运行情况和大家的需求变化,我重构并开发出了新一版的公共支出系统。
## 新功能
- 实现了Ushio用户系统的接入
- 用户能够随时注册并新建公共账单
- 同一个用户能够同时在多个账单
- 用户能够随时加入公共账单
- 用户能够随时结算并退出某个公共账单
- 更加智能的结算算法
- 使用LocalStorage优化了二次访问的速度
## 体验
cp-acc现在已经对公众开放,您可以进入其[网站](https://cp-acc.yimian.xyz)进行体验。不过在体验前,您需要先通过ushio用户系统使用您的邮箱登录,以便接收账单消息。
{% raw %}</span>{% endraw %}
@ -119,10 +174,65 @@ Directly quote the code of [呓喵酱の图床](https://imgbed.yimian.xyz) with
At present, it is simple to implement with additional web pages, waiting for the [ushio-auth project](https://github.com/iotcat/ushio-auth) to complete the unified integration.
## 3. Appearance
Nothing to say, show the picture, see for yourself
![imgbed_ed08c497](https://api.yimian.xyz/img/?path=imgbed/img_ed08c497_1080x6654_8_null_normal.jpeg)
![imgbed_ea04ad82](https://api.yimian.xyz/img/?path=imgbed/img_ea04ad82_1080x5082_8_null_normal.jpeg)
![imgbed_a8b3adb0](https://api.yimian.xyz/img/?path=imgbed/img_a8b3adb0_1080x2160_8_null_normal.jpeg)
-----------------------
**2020-03-22 update**
Due to the epidemic, considering that everyone has withdrawn to China. To save server costs, stop providing services.
Combining the operation status of the past six months, I have made some analysis and summary:
## Main gains
1. Experience in analyzing the real needs of customers
2. Ability to quickly build production environment website tools
3. My roommate's recognition of my ability
## Development Methodology
1. Based on a series of past projects, quickly set up and put into use in 3 days
2. Carefully study the requirements and determine which are true and which are false.
## Challenges encountered
1. Rapid development, because everyone has started to spend a lot of money on public goods after arriving in the UK, so there is an urgent need to use this system
2. The algorithm must be stable and reliable, because it involves everyone's money
3. The purpose of this system is to make it more convenient to delegate the accounting work to the system for automated processing. In this way, the number of internal transactions between everyone must be as few as possible and the instructions must be clear under the premise of ensuring fairness.
4. How to make everyone trust the system.
## Solution
1. Based on a large number of own previous projects. It takes 1 day to develop and form, 1 day to test debug, 1 day to optimize the front-end, add variance, percentage and other functions.
2. Refer to the accounting table and use the table mode. Every time there is a new upload, the new status will be calculated in real time. Tested many times and put into use after full verification.
3. Use the concept of "balance" and pay attention to differences. When the differences are too large, make internal transactions between those who spend the most and those who spend the least. And the internal transaction value is an integer. For example, our production scenario uses 20 pounds.
4. When the system algorithm is stable, refer to the design of Alipay. There are two steps to internal transactions. Both the first-choice payer and the earner receive emails telling to whom (from whom) and how much money. Then after the payer gives the money to the earner, the earner needs to log in to the web page or confirm it from the email link. As of this time, the system considers that an internal transaction is complete.
-------------------------------
**2020-9-8 update**
Based on the Ushio user system, combined with the operation of the past six months and the changes in everyone's needs, I reconstructed and developed a new version of the public expenditure system.
## New features
- Achieved access to Ushio user system
- Users can register and create new public bills at any time
- The same user can be in multiple bills at the same time
- Users can join the public bill at any time
- Users can settle and exit a public bill at any time
- Smarter settlement algorithm
- Use LocalStorage to optimize the speed of secondary access
## Experience
cp-acc is now open to the public, you can go to its [website](https://cp-acc.yimian.xyz) to experience it. But before the experience, you need to log in with your email address through the ushio user system in order to receive bill messages.
{% raw %}</span>{% endraw %}

@ -52,130 +52,250 @@ Based on Home Assisstant, build a smart home with integrated home lighting syste
结合所学知识,运用前沿技术,造福生活,是我长期以来的不懈追求。为了让家人体验到更加稳定、舒适智能的生活方式,同时也为了巩固憨实先前在学校smartfarm项目和我自己的ushio系统中所积累的技术基础以及架构经验,我决定在出国前,使用20到23整天时间,重构家中老旧的物联网系统。采用分层架构和面向接口、面向测试、**面向文档**开发原则,以**稳定性(Available)**,**可靠性(Reliable)**为最优先指标,搭建一个运行目标3年以上的高度模块化的,易于远程操控的,开源的家庭软件硬件智能传感控制系统。
## 0 架构综述
## 背景:
大一上学期,初接触单片机,使用Arduino Uno搭建了一个宿舍中的智慧窗帘系统(细节可以参考[这篇blog](https://www.eee.dog/tech/build-236-iot-platform-on-wifiduino.html)),积累了一定的经验。
## 1 硬件设计
## 方法:
1. 向专家请教(水管问题向五金店老板请教,LoRa向欧朗研发部请教)
2. 做轮子,不断迭代,在重构中优化系统,获取经验
3. 认真调研客户(家人)的需求,在设计时重视客户需求,多于客户沟通
4. 在设计某一系统时,一定要假设与其交互的其它系统不稳定。让系统之间的交互就像君子相交一样,像水一样。从而提高整个系统的裕度。
5. 持续运维。比如三轮开发前曾经发生过,我妈在打扫卫生时碰掉了一个人体传感器,导致整个灯控系统紊乱。当时在苏州的我通过远程ssh连接到家里的服务器,将坏掉的传感器踢出控制系统进而解决了问题。因此,一定要让自己在任何时候都可以接入到系统进行运维。一定要在设计时充分考虑之后的运维。
### 1.1 单片机选材
## 过程综述:
### 一轮开发
大一暑假,开始尝试使用WiFiduino在家中控制一些物体,实现了对(坏了的)太阳能加水(通过电磁阀)的控制(修改了原先家里的管道,加入了电磁阀。跑了好多趟五金店,收获了不少关于水管的知识和实践经验。之后做surf的水泵也有用到。)以及对走廊灯(通过光电耦合器)的控制。找到一台废弃的10年前的我爸的IBM笔记本,装上了win server 2008, 并配置好了mysql数据库,并定期使用http从单片机采集数据。我用php写了一个简单的web界面,来展示相关信息,并实现网页控制。由于家里被分配的是中国移动分配的大NAT内网IP,因此使用frp来实现内网穿透,使外界可以访问家里服务器上的web网页。
### 二轮开发
大二寒假,改进先前的固件,使用wifiduino陆续实现了对厨房,客厅,餐厅的灯体的控制,并部署了一系列传感器,并接入网络。由于先前太阳能管道的单片机WiFi信号弱,于是在附近使用路由器做了桥接。值得一提的是,年三十晚上春晚开始前2分钟我还在家里停电施工,,不知道爸妈是什么感受⊙0⊙。。
### 三轮开发
大二暑假,基于本学期经验,重构系统。在服务器上,重装系统为Centos7使用home assistant 开源项目提供UI等服务,使用mqtt作为通信协议。使用nodeJS编写了灯控自动化和太阳能加水的控制逻辑。在单片机,更新了固件,支持ota远程更新固件(参考了部分wiot经验,但更加因地制宜)。此外,新增了两个流量计,以实现太阳能加水完全自动化(之前是通过网页设置加水时长)。由于流量计WiFi信号弱,我们使用了Arduino uno + LoRa作为通信手段。本次设计,结合爸妈的意见,充分考虑了整体系统的稳定性。比如,如何handle各种类型的错误和失联,如何在断电后丝滑得重启,如何在服务器无响应情况下保证单片机不紊乱,如何在系统失控后物理切回到手动(比如灯,和太阳能加水)。
### 四轮开发
大三暑假,基于过去积累的传感器数据,使用LSTM模型,通过keras+tensorflow训练神经网络,实现对灯控状态的预测。目前仍在持续优化中,预计9月前完成。此外,有计划接入天猫精灵的打算(仍在队列中,需等待ushio oauth系统的研发,ushio oauth系统需要等待ushio user系统研发,ushio user系统需要稳定的js-session作为支撑,js-session需要使用fp来精确识别用户设备。。目前fp仍处于第三测试阶段。所以,一步一步来吧,,)。
## 硬件设计
### 单片机选材
使用Arduino UNO作为计算单元。一方面,Arduino Uno拥有高可靠性,我之前的智慧窗帘系统使用Arduino Uno作为主控板,平稳运行1年半未出现硬件问题。另一方面,Arduino Uno拥有较大的RAM,无需为了争夺RAM而在单片机编程上煞费苦心。
Arduino UNO的缺陷主要是价格高,但是为保障长期稳定运行,这个成本是必要的。
### 1.2 WiFi通信模块选材
### WiFi通信模块选材
使用ESP-01作为WiFi的通信模块。主要原因是之前学校课程使用过ESP-01搭建遥控小车,对其工作方式和性能比较了解,降低开发成本。
### 1.3 LoRa通信模块选材
### LoRa通信模块选材
使用**安信可 LORA RA-02 LORA**作为LoRa节点和LoRa网关通信模块。原因是surf项目使用的就是这个模块,比较了解它。
### 1.4 智能音箱选材
### 智能音箱选材
智能音箱作为此物联网系统人机交互的最主要界面,发挥着举足轻重的作用。经研究,我使用天猫精灵方糖R作为家用智能音箱。一方面,天猫精灵的性价比摆在那里,非常便宜。第二,与小米开发小爱同学不同,阿里开发天猫精灵的目的是提供平台,它允许开发者以各种形式接入其网络,这一点对我至关重要。
### 1.5 灯拨动开关
### 灯拨动开关
初期设想: 单向控制+复位器。
实际实现:将原有单开改造为双开,一路与继电器串联,另一路与两个pin口相连。
## 2 通信设计
## 通信设计
![网络拓扑图](https://api.yimian.xyz/img/?path=imgbed/img_43b85bd4_1096x660_8_null_normal.png)
采用WiFi+LoRa两种通信模式。在需要高速高质量通信的场景,如天猫精灵,手机,笔记本,使用WiFi作为通信手段。在WiFi信号不稳定的地方,使用LoRa进行通信。使用MQTT为应用层协议。
## 3 主控系统设计
## 主控系统设计
使用python3开源项目Home Assistant 为基础搭建本项目的主控系统。效果如下图:
使用python3开源项目Home Assistant 为基础搭建本项目的主控系统。
![Sola Website](https://api.yimian.xyz/img/?path=imgbed/img_c1a1b81_1895x859_8_null_normal.jpeg)
## 4 多媒体系统设计
## 多媒体系统设计
多媒体主要由天猫精灵提供。此外,通过小米盒子,家庭网盘中的视频,图片,音乐实现了电视与音响上的播放。
## 5 云端支持系统设计
## 云端支持系统设计
dns.yimian.xyz提供dns解析服务。
## 6 NAS存储系统设计
## NAS存储系统设计
通过挂载从老电脑上拆卸的闲置500G机械硬盘到老IBM服务器,实现存储系统的搭建。
对局域网内,由于家里都是win系统,使用smb作为共享协议实现文件传输,支持局域网内挂载。速度稳定,全网读写10MB/s左右。对外网访问,通过http,frp反代实现,但速度较慢。
以下是对网页界面的一个截屏:
![NAS Web Page](https://api.yimian.xyz/img/?path=imgbed/img_352da66_1866x814_8_null_normal.jpeg)
## 总结
### 主要收获
1. 全栈物联网(云+管+端)系统搭建运维经验
2. LoRa,WiFi通信系统搭建经验
3. 机器学习开发运维经验
4. 客户需求分析经验
5. 家用电路线路改装经验
6. 家用水管管道改造经验
### 遇到的挑战
1. 如何保证所有的单片机处拥有优质的网络连接
2. 家人希望预留方法,在系统崩溃时一键回到最古老的手动开关状态。
3. 准确的控制灯的开关
4. 如何降低各模块间的耦合
### 解决方法
1. 使用WiFi,LoRa双协议。WiFi用于连接距离路由器较近的单片机,LoRa 连接距离较远WiFi信号弱的原处的单片机。
2. 我在每一个开关都配置了双保险,让每一个开关都可以经过轻易的操作即可回到手动状态。如果要回到手动状态,只需要扫描开关上的二维码,根据指示操作。详见[应急操作指南](https://sola.yimian.xyz/#/home?id=%E5%BA%94%E6%80%A5%E6%93%8D%E4%BD%9C%E6%8C%87%E5%8D%97)
3. 在第一轮开发,灯控是由单片机决定的。与楼道里的声控灯并无本质差别,都是传感器->单片机->灯。第二轮开发时,将这个判断逻辑转移到了服务器。第三轮开发,我们引入了夜间模式,白天模式,午夜模式等,并在决策时使用了数学模型,通过各传感器的数据测算有人的概率,来决定对灯的控制。但是,这一方法并不总是及时,家里人在天刚黑时总是需要去按一下拨动开关。因此,第四轮开发中,我希望能够借助机器学习,让其自己学习家人的开关习惯。目前,正在持续采集数据并训练中,夜间准确度在0.75左右。
4. 各个模块和单片机都是用mqtt进行交互。每个单片机都有在线模式和离线模式。灯控决策模块和太阳能控制模块是单独的两个nodeJS模块,由pm2守护。为了保证其服务不间断性,他们是用redis(已配置持久化)作为实时数据存储。
------------------------
2020.6 更新
**2020.6 更新**
## RNN实现对灯控制
基于先前积累的人体传感器数据,通过LSTM模型,使用keras训练神经网络,实现对开灯状态的预测。
--------------------------
**2020.8 更新**
## 天猫精灵接入
自建了OAuth服务器,实现了天猫精灵的接入。
{% raw %}</span>{% endraw %}
{% raw %}<span class=".en">{% endraw %}
Combining the knowledge I have learned and using cutting-edge technology to benefit life has been my unremitting pursuit for a long time. In order to let my family experience a more stable, comfortable and intelligent lifestyle, and to consolidate the technical foundation and architecture experience accumulated in the school smartfarm project and my own ushio system, I decided to use 20 to 23 before going abroad. All day long, reconstruct the old IoT system at home. Adopt a layered architecture and interface-oriented, test-oriented, and **document-oriented** development principles, with **Available** and **Reliable** as the highest priority indicators to build an operational target 3. A highly modular, easy-to-remote control, open source home software and hardware intelligent sensor control system for more than years.
## 0 Architecture overview
## Background:
In the first semester of the freshman year, I was new to MCU and used Arduino Uno to build a smart curtain system in the dormitory (for details, please refer to [this blog](https://www.eee.dog/tech/build-236-iot-platform) -on-wifiduino.html)), has accumulated a certain amount of experience.
## Method:
1. Ask experts (for water pipe problems, ask the owner of the hardware store, and LoRa for advice from Oulang R&D department)
2. Be a wheel, keep iterating, optimize the system in refactoring, and gain experience
3. Investigate the needs of customers (family) carefully, pay more attention to customer needs in design, rather than communicate with customers
4. When designing a system, it must be assumed that other systems that interact with it are unstable. Let the interaction between systems be like gentlemen intersect, like water. Thereby improving the margin of the whole system.
5. Continuous operation and maintenance. For example, it happened before the three rounds of development. My mother touched a human sensor while cleaning, causing the entire light control system to be disordered. At that time, I was in Suzhou connected to the server at home via remote ssh, kicked the broken sensor out of the control system and solved the problem. Therefore, you must allow yourself to be connected to the system for operation and maintenance at any time. The future operation and maintenance must be fully considered in the design.
## Process overview:
### First round of development
Freshman summer vacation, I began to try to use WiFiduino to control some objects at home, and realized the control of (broken) solar water (through solenoid valve) (modified the original home pipes and added solenoid valves. I went to the hardware store many times. , I have gained a lot of knowledge and practical experience on water pipes. Later, I will also be useful to do surf pumps.) and control the corridor lights (through photocouplers). I found an abandoned IBM laptop of my dad 10 years ago, installed it with win server 2008, and configured the mysql database, and regularly used http to collect data from the microcontroller. I wrote a simple web interface in php to display relevant information and implement web control. Since the home is assigned a large NAT intranet IP allocated by China Mobile, frp is used to achieve intranet penetration, so that the outside world can access the web pages on the home server.
### Second round of development
During the sophomore winter vacation, the previous firmware was improved, wifiduino was used to control the lights in the kitchen, living room, and dining room one after another, and a series of sensors were deployed and connected to the network. Because the WiFi signal of the single-chip microcomputer of the solar energy pipeline was weak, a router was used nearby to bridge. It is worth mentioning that on the night of New Year’s Eve, I was still at home with a power outage 2 minutes before the start of the Spring Festival Gala. I don’t know how my parents feel. .
### Third round of development
Sophomore summer vacation, based on the experience of this semester, reconstruct the system. On the server, the reinstallation system provides UI and other services for Centos7 to use the home assistant open source project, using mqtt as the communication protocol. Use nodeJS to write the control logic of light control automation and solar water adding. In the single chip microcomputer, the firmware is updated, and the ota remote firmware update is supported (referring to some Wiot experience, but more tailored to local conditions). In addition, two new flow meters have been added to fully automate the solar water addition (previously, the water addition time was set through the web page). Due to the weak WiFi signal of the flowmeter, we used Arduino uno + LoRa as the communication means. This design, combined with the opinions of parents, fully considered the stability of the overall system. For example, how to handle various types of errors and loss of connection, how to restart after a power failure, how to ensure that the MCU is not disordered when the server is unresponsive, and how to physically switch back to manual after the system is out of control (such as lights, and Solar energy plus water).
### Fourth round of development
In the summer vacation of the junior year, based on the sensor data accumulated in the past, the LSTM model is used to train the neural network through keras+tensorflow to realize the prediction of the light control state. The optimization is still ongoing and is expected to be completed before September. In addition, there are plans to connect to the Tmall Wizard (still in the queue, waiting for the development of the ushio oauth system, the ushio oauth system needs to wait for the development of the ushio user system, and the ushio user system needs stable js-session as support, js-session Need to use fp to accurately identify user equipment.. Currently fp is still in the third test stage. So, let's do it step by step,,).
## 1 Hardware Design
## Hardware design
### 1.1 Single Chip Microcomputer Material Selection
### Single Chip Microcomputer Material Selection
Use Arduino UNO as the calculation unit. On the one hand, Arduino Uno has high reliability. My previous smart curtain system used Arduino Uno as the main control board, and it ran smoothly for one and a half years without hardware problems. On the other hand, Arduino Uno has a larger RAM, so there is no need to bother to program the microcontroller in order to compete for RAM.
The main disadvantage of Arduino UNO is its high price, but this cost is necessary to ensure long-term stable operation.
### 1.2 WiFi communication module selection
### WiFi communication module selection
Use ESP-01 as the WiFi communication module. The main reason is that the ESP-01 has been used to build a remote control car in the previous school courses, and I have a better understanding of its working methods and performance to reduce development costs.
### 1.3 LoRa communication module selection
### LoRa communication module selection
Use **Anxinke LORA RA-02 LORA** as the communication module between LoRa node and LoRa gateway. The reason is that this module is used in the surf project, so I understand it better.
### 1.4 Smart speaker selection
### Smart speaker selection
As the most important interface for human-computer interaction in this Internet of Things system, smart speakers play a pivotal role. After research, I use Tmall Elf Sugar R as a home smart speaker. On the one hand, the price/performance ratio of Tmall Genie is very cheap. Second, unlike Xiaomi’s development of Xiao Ai, the purpose of Ali’s development of Tmall Genie is to provide a platform that allows developers to access its network in various forms, which is very important to me.
As the most important interface for human-computer interaction in this IoT system, smart speakers play a pivotal role. After research, I use Tmall Elf Sugar R as a home smart speaker. On the one hand, the price/performance ratio of Tmall Genie is very cheap. Second, unlike Xiaomi’s development of Xiao Ai, the purpose of Ali’s development of Tmall Genie is to provide a platform that allows developers to access its network in various forms, which is very important to me.
### 1.5 Light toggle switch
### Light toggle switch
Initial idea: one-way control + reset device.
Actual realization: The original single-opening is transformed into double-opening, one is connected in series with the relay, and the other is connected with two pin ports.
## 2 Communication Design
## Communication Design
![Network Topology Diagram](https://api.yimian.xyz/img/?path=imgbed/img_43b85bd4_1096x660_8_null_normal.png)
Two communication modes of WiFi+LoRa are adopted. In scenarios that require high-speed and high-quality communication, such as Tmall Genie, mobile phones, and notebooks, use WiFi as a means of communication. In places where the WiFi signal is unstable, use LoRa for communication. Use MQTT as the application layer protocol.
## 3 Main control system design
## Main control system design
Use the python3 open source project Home Assistant as the basis to build the main control system of this project.
Use the python3 open source project Home Assistant as the basis to build the main control system of this project. The effect is as follows:
## 4 Multimedia system design
![Sola Website](https://api.yimian.xyz/img/?path=imgbed/img_c1a1b81_1895x859_8_null_normal.jpeg)
## Multimedia system design
Multimedia is mainly provided by Tmall Genie. In addition, through the Xiaomi box, the video, pictures, and music in the home network disk can be played on the TV and stereo.
## 5 Cloud support system design
## Cloud support system design
dns.yimian.xyz provides dns resolution service.
## 6 NAS storage system design
## NAS storage system design
By mounting the idle 500G mechanical hard disk removed from the old computer to the old IBM server, the storage system is built.
In the local area network, since the home is a win system, smb is used as a sharing protocol to realize file transfer and supports mounting in the local area network. The speed is stable, and the whole network reads and writes about 10MB/s. Access to the external network is realized through http and frp reverse generation, but the speed is slow.
The following is a screenshot of the web interface:
![NAS Web Page](https://api.yimian.xyz/img/?path=imgbed/img_352da66_1866x814_8_null_normal.jpeg)
## Conclusion
### Main gains
1. Full-stack IoT (cloud + pipe + terminal) system construction operation and maintenance experience
2. LoRa, WiFi communication system construction experience
3. Machine learning development operation and maintenance experience
4. Customer needs analysis experience
5. Experience in home circuit modification
6. Experience in renovation of household water pipes
### Challenges encountered
1. How to ensure that all MCUs have high-quality network connections
2. The family hopes to reserve a way to return to the oldest manual switch state with one click when the system crashes.
3. Control the light switch accurately
4. How to reduce the coupling between modules
### Solution
1. Use WiFi, LoRa dual protocol. WiFi is used to connect the single-chip microcomputer closer to the router, and LoRa connects to the single-chip microcomputer in the original place where the WiFi signal is weaker.
2. I have equipped each switch with double insurance, so that each switch can be returned to manual state after easy operation. If you want to return to manual mode, just scan the QR code on the switch and follow the instructions. For details, see [Emergency Operation Guide](https://sola.yimian.xyz/#/home?id=%E5%BA%94%E6%80%A5%E6%93%8D%E4%BD%9C%E6%8C%87%E5%8D%97)
3. In the first round of development, the light control is determined by the microcontroller. There is no essential difference with the sound-controlled lights in the corridor, they are all sensors -> single chip microcomputer -> lights. In the second round of development, this judgment logic was transferred to the server. In the third round of development, we introduced night mode, day mode, midnight mode, etc., and used mathematical models in the decision-making process to determine the probability of people using the data of each sensor to determine the control of the lights. However, this method is not always timely. Family members always need to press the toggle switch when it is just dark. Therefore, in the fourth round of development, I hope to use machine learning to let myself learn the switching habits of my family. Currently, data is being continuously collected and trained, and the night accuracy is around 0.75.
4. Each module and the single-chip microcomputer use mqtt to interact. Each microcontroller has an online mode and an offline mode. The light control decision module and the solar control module are two separate nodeJS modules, guarded by pm2. In order to ensure uninterrupted services, they use redis (configured persistence) as real-time data storage.
------------------------
2020.6 update
**2020.6 update**
## RNN realizes light control
Based on the previously accumulated human sensor data, the LSTM model is used to train the neural network using keras to realize the prediction of the light state.
--------------------------
**2020.8 update**
## Tmall Elf Access
Self-built OAuth server has realized the access of Tmall Wizard.
{% raw %}</span>{% endraw %}

@ -46,8 +46,6 @@ The Internet of Things system based on NodeJS, combined with D1 MINI microcontro
{% raw %}<span class=".zh">{% endraw %}
> 正式开发文档见[**这里**](https://wiot.yimian.xyz)
### wIoT for NodeJS
适用于NodeJS的wIoT服务器控制组件,轻松物联
@ -72,6 +70,9 @@ The Internet of Things system based on NodeJS, combined with D1 MINI microcontro
# 使用方法
> 正式开发文档见[**这里**](https://wiot.yimian.xyz/#/home)
## 先觉条件
- 拥有烧录好[wIoT固件](https://wiot-ota.yimian.xyz/get.php)的**D1 MINI**单片机
- 一台或多台无线WiFi路由器2.4G/5G
@ -129,7 +130,7 @@ wiot.begin([MyMCU], ()=>{ // 第一个参数为要等待的单片机对象数组
### 开始执行
在项目文件夹中打开命令行,输入以下指令:
````shell
````bash
node app.js
````
@ -511,12 +512,17 @@ gugu.print("This is from wIoT!!");
```
{% raw %}</span>{% endraw %}
{% raw %}<span class=".en">{% endraw %}
# Quick Start
This project aims to help web developers who are not familiar with firmware programming to implement their own IoT applications. You only need a server inside the network (such as Raspberry Pi) and several MCUs (single-chip computers) that support networking (via serial port, WiFi, LoRa, Bluetooth, Zigbee, etc.), you can easily create and manage your own Internet of Things Cluster.
## Current Support devices
- D1 MINI
@ -532,7 +538,7 @@ For **windows** user, you can follow the instruction in [this website](https://w
After install Node.js and configure npm successfully, you should then use npm to download wIoT package by enter following command in your command window.
```shell
```bash
npm install wiot
```
@ -705,8 +711,7 @@ var MyMCU = new wiot.client({
- `disConnected` Disconnect from MCU
- `reConnected` Connection with MCU restored
```
js
```js
var MCU = new wiot.client({"MAC": "xx:xx:xx:xx:xx:xx"});
MCU.on('disConnected', function () {

@ -0,0 +1,301 @@
---
title: wIoT发展展望
titleEN: wIoT - What is the future
date: 2020-09-15
display: true
categories:
- tech
tags:
- iot
- WiFi
- nodeJS
---
{% raw %}<span class=".zh">{% endraw %}
本文将讨论wiot项目下一步的发展目标与实施方法。
{% raw %}</span>{% endraw %}
{% raw %}<span class=".en">{% endraw %}
This article will discuss the next development goals and implementation methods of the Wiot project.
{% raw %}</span>{% endraw %}
<!--more-->
{% raw %}
<script>
session.onload(function(){
if(page.tran.getLang() == 'en'){
tips.warning({
title: 'Caution',
position: 'topRight',
message: 'This page was translated by Machine!!',
buttons: [['<button>Show Chinese Page</button>', function (instance, toast) {
page.tran.setLang('zh');
instance.hide({ transitionOut: 'fadeOut' }, toast, 'button');
}, true]]
});
}
});
</script>
{% endraw %}
{% raw %}<span class=".zh">{% endraw %}
### wIoT
wiot,一个基于NodeJS的分布式物联网操作系统。
# 项目简介
## 立项初衷
本项目旨在帮助不熟悉固件编程的网络开发者实现出自己的物联网应用。
在开发传统的物联网程序时,我们需要一次又一次的编写,烧录,调试每一个开发板,以某种方式将其相连结,以提供某种服务。这样的方式非常繁琐,开发成本和门槛都比较高。此外,古老的C和C++语言缺少成熟的依赖管理工具,以至于我们在编写开发板时难以像开发python或nodeJS程序一样轻松便捷。
本项目试图提供一种方法,将烧录,调试开发板的流程自动化,并将逻辑编写的步骤移动到远程计算机的NodeJS界面上。通过此方式,我们进而得以将分布式物联网节点的功能进行集中化管理。此外,借助NodeJS成熟的依赖管理器npm,使得物联网应用的开发更加便捷高效。
至此,下到每一个物联网节点,上到各种类型的数据库、用户终端,都可以在同一个nodeJS界面上配置、操作。开发者将能够专注于物联网逻辑的开发,实现出更加丰富多彩的物联网应用。
# 第一轮开发
> 第一轮开发完成于2019.5,详见[这篇博客](https://www.eee.dog/tech/wiot.html)
实现了对D1 MINI开发板对nodeJS的pin口映射,并支持诸如ota等一系列功能。
# 第二轮开发
> 待进行,计划当做FYP项目
## 支持的开发版
- [NodeMCU](https://www.nodemcu.com/index_en.html)
## 实现方法
通过提供标准化的单片机固件以及自动化的烧录工具,wiot将各开发板的pin口功能进行抽象,整理,并映射为可调用的NodeJS接口。
![wiot Architecture](https://api.yimian.xyz/img/?path=imgbed/img_b0a1fe7_1395x662_8_null_normal.jpeg)
如上图所示,wiot架构主要包含三部分:Node节点,wiot Cloud Module云模块,wiot cli命令行程序。其中,Node节点为烧录好wiot固件的NodeMCU单片机,他们通过IEEE 802.11 WiFi进行分布式通信,并于某个节点接入路由器以连接wiot云模块。用户在自己的PC上使用NodeJS调用wiot依赖编写物联网程序。完成后,用户使用wiot cli对开发好的程序进行检查、测试和部署。被部署的物联网程序将运行在wiot云模块上,并可使用nodeJS的接口与其它云服务或数据库进行交互。
### Node节点
Node节点使用的是NodeMCU开发板(基于ESP8266的扩展板)。在使用wiot-cli烧录wiot固件后,NodeMCU将成为wiot节点。
#### **模式**
wiot节点有四种模式:master模式、slave模式、bridge模式和debug模式。此模式只能在烧录固件时配置。master模式和bridge模式下,nodeMCU将同时开启STA和AP模式。slave模式下则只开启STA模式。master需要有稳定且无限制的电源供电,其功率较大(包含RSA, 协议转换等),不适合低功耗场景。bridge与slave则可以灵活调整功率,可用于低功耗场景。
debug模式下节点工作在STA和AP模式,用户可以使用手机等设备连接到此节点,并打开根目录网页。网页上将实时显示此节点当前所处位置的各种信息,比如收到各其它节点的信号强度等,适用于挑选部署场景。
#### **低功耗**
wiot节点支持低功耗(Low Power)状态。但此状态仅能在slave模式和bridge下开启。此状态可通过wiot api或者wiot-cli进行开启或关闭。低功耗状态由esp8266睡眠功能实现。此状态下可由干电池供电工作数年[[1]](https://makecademy.com/esp8266-battery)。
#### **组网**
wiot节点使用分布式组网。在路由器信号较强的地方,master节点将接入路由器WiFi网络,并桥接。在路由器信号不强的地方,每一个节点都会找到信号最强的另一个上游的master或bridge节点,并桥接(slave除外)。
![wiot节点分布式组网](https://api.yimian.xyz/img/?path=imgbed/img_a42f5a4_1224x561_8_null_normal.jpeg)
如上图,两个距离路由器近的master节点自动接入到路由器wifi。下游的其它节点分别连接至信号最强的上游节点。
#### **认证**
![射频指纹识别[2]](https://api.yimian.xyz/img/?path=imgbed/img_d184ff2_1442x502_8_null_normal.jpeg)
wiot节点支持使用**射频指纹识别**[[2]](https://ieeexplore.ieee.org/document/8715341)来实现下游通信认证。此方法使用esp8266的RSSI函数以及scan返回参数。在下游设备试图接入网络时,上游设备将搜集指纹信息并向服务器汇报。服务器将指纹与数据库存储的先前版本进行比对,并作出是否允许入网的决策。
### 云模块
云模块充当wiot的云部分,提供云的功能。云模块能够守护运行run-time状态下的wiot程序。此外,云模块还能够提供测试,部署等功能。云模块使用Docker进行虚拟化。
### 命令行程序
即wiot-cli。是wiot在开发者终端上提供的操作工具集。通过wiot-cli,开发者可以实现对wiot程序的测试,部署,恢复等功能。此外,wiot-cli也支持一系列debug等常用功能。详见下方`wiot-cli命令`。
## 用户操作步骤
1. 用户下载安装并配置好NodeJS环境。
2. 用户通过命令行运行`npm i -g wiot-cli`指令安装wiot命令行工具
3. 用户运行命令`wiot init my-wiot-proj`在当前目录新建并配置一个wiot项目文件夹,项目名称为my-wiot-proj。此时,会提示用户填写此项目的一些信息,比如项目描述,作者信息,路由器WiFi账户密码,wiot云模块地址,项目主脚本等。
4. 用户进入到项目目录,将nodeMCU通过数据线连接到电脑,运行`wiot node init my-first-node [--type=<master|slave|bridge|debug>]`。这将自动配置并将wiot固件烧录到nodeMCU开发板,并将其命名为my-first-node。type为可选参数,可设置为`master`或`slave`或`bridge`或`debug`,默认为`master`。
5. 依次按照此方法烧录好所有的开发板,将其部署在生产环境。
6. 在项目文件夹运行指令`wiot status`查看是否所有节点均已在线。如果没有,使用指令`wiot log`配合`grep`工具查找日志定位问题。
7. 从项目主脚本(默认是`index.js`)开始编写你的wiot程序。
8. 使用指令`wiot check`检查你wiot程序的逻辑问题。
9. 使用指令`wiot test`将挂起云模块中正在运行的程序,并运行当前项目文件夹中的程序。此时,所有控制台输出将显示在你的命令行窗口。使用`Ctrl+C`终止当前测试并恢复云模块先前的程序。
10. 使用指令`wiot push`将本地的wiot程序部署到云端。
## 其它操作
### 部署自己的wiot云模块
默认使用wiot官方wiot云模块。你也可以部署自己的wiot云服务,方法如下:
安装docker并运行指令`docker run -d --name=wiot-cloud -p 3594:3594 -v /var/wiot/data/:/var/wiot/data/ iotcat/wiot`。
### wiot-cli命令
- `wiot help [command]`查看帮助
- `wiot clone <host:user/project>`将项目从云模块克隆到本地
- `wiot pull`使用远程代码覆盖本地代码
- `wiot push`将当前文件夹wiot程序部署到云模块
- `wiot ls`显示当前所有节点
- `wiot map [nodeID]`显示某节点的连接路径
- `wiot log [nodeID] [--head=<number>|--tail=<number>]`查看某节点的日志
- `wiot stop`停止wiot服务
- `wiot start`开启wiot服务
- `wiot restart`重启wiot服务
- `wiot reload`在不重置flash变量情况下重启wiot服务
- `wiot init <name>`新建并初始化wiot项目文件夹
- `wiot node init <node-name> [--type=<master|slave|bridge|debug>]`配置并烧录nodeMCU开发板
- `wiot check`检查当前文件夹项目逻辑问题。
- `wiot test`将挂起云模块中正在运行的程序,并运行当前项目文件夹中的程序。此时,所有控制台输出将显示在你的命令行窗口。使用`Ctrl+C`终止当前测试并恢复云模块先前的程序。
- `wiot status [nodeID]`显示当前项目或节点状态信息
- `wiot debug start`终止当前云端程序并进入debug模式
- `wiot debug set <nodeID> <pinID> <0-255>`debug模式下设置某个节点pin的PWM输出值
- `wiot debug reset <nodeID>`debug模式下重置某个节点的数据存储,并重连
- `wiot debug get <nodeID> <pinID>`debug模式下获取某个节点pin的PWM值
- `wiot debug sleep <nodeID> <pinID> <HIGH|LOW>`debug模式下设置某节点轻度休眠,直到被某pin的高或低电平唤醒
- `wiot debug dsleep <nodeID> <millisecond>`debug模式下设置某节点深度休眠多少毫秒
- `wiot debug reconnect [nodeID]`debug模式下重新组网或断开重连某个节点
- `wiot debug setphymode <nodeID> <b|g|n>`debug模式下配置节点WiFi协议为802.11b|g|n
···
### 常用API
> 待设计,请参考[一轮开发wiot文档](https://wiot.yimian.xyz/#/home)
{% raw %}</span>{% endraw %}
{% raw %}<span class=".en">{% endraw %}
### wIoT
Wiot, a distributed IoT operating system based on NodeJS.
# Project Description
## The original intention of the project
This project aims to help web developers who are not familiar with firmware programming to implement their own IoT applications.
When developing traditional Internet of Things programs, we need to write, burn, and debug each development board again and again, and connect them in a certain way to provide a certain service. This method is very cumbersome, and the development cost and threshold are relatively high. In addition, the ancient C and C++ languages lack mature dependency management tools, so that it is difficult for us to write development boards as easy and convenient as developing python or nodeJS programs.
This project is trying to provide a method to automate the process of burning and debugging the development board, and move the steps of logic writing to the NodeJS interface of the remote computer. In this way, we are able to centrally manage the functions of distributed IoT nodes. In addition, with NodeJS's mature dependency manager npm, the development of IoT applications is more convenient and efficient.
So far, down to every IoT node, up to various types of databases and user terminals, all can be configured and operated on the same nodeJS interface. Developers will be able to focus on the development of IoT logic and realize more colorful IoT applications.
# First round of development
> The first round of development was completed in May 2019, please refer to [this blog](https://www.eee.dog/tech/wiot.html)
Realize the pin port mapping of D1 MINI development board to nodeJS, and support a series of functions such as ota.
# Second round of development
> To be carried out, plan as FYP project
## Supported development version
- [NodeMCU](https://www.nodemcu.com/index_en.html)
## Implementation
By providing standardized microcontroller firmware and automated burning tools, wiot abstracts, organizes, and maps the pin port functions of each development board into a callable NodeJS interface.
![wiot Architecture](https://api.yimian.xyz/img/?path=imgbed/img_b0a1fe7_1395x662_8_null_normal.jpeg)
As shown in the figure above, the wiot architecture mainly consists of three parts: Node node, wiot Cloud Module, and wiot cli command line program. Among them, the Node node is the NodeMCU microcontroller with the wiot firmware burned. They use IEEE 802.11 WiFi for distributed communication, and connect to a router at a node to connect to the wiot cloud module. Users use NodeJS to call Wiot on their own PCs and rely on writing IoT programs. After completion, the user uses wiot cli to check, test and deploy the developed program. The deployed IoT program will run on the wiot cloud module, and can use the nodeJS interface to interact with other cloud services or databases.
### Node node
Node node uses NodeMCU development board (expansion board based on ESP8266). After using wiot-cli to burn the wiot firmware, NodeMCU will become a wiot node.
#### **Mode**
Wiot nodes have four modes: master mode, slave mode, bridge mode and debug mode. This mode can only be configured when burning firmware. In master mode and bridge mode, nodeMCU will enable STA and AP mode at the same time. In slave mode, only STA mode is enabled. The master needs to have a stable and unlimited power supply, which has a large power and is not suitable for low power consumption scenarios. Bridge and slave can flexibly adjust power, which can be used in low power consumption scenarios.
In debug mode, the node works in STA and AP mode. Users can use mobile phones and other devices to connect to this node and open the root directory webpage. The web page will display various information about the current location of this node in real time, such as the signal strength received from other nodes, which is suitable for deployment scenarios.
#### **Low power**
Wiot nodes support Low Power state. But this state can only be opened in slave mode and bridge. This state can be turned on or off through wiot api or wiot-cli. The low power consumption state is realized by the sleep function of esp8266. In this state, it can be powered by dry batteries for several years [[1]](https://makecademy.com/esp8266-battery).
#### **Networking**
Wiot nodes use distributed networking. Where the router signal is strong, the master node will access the router WiFi network and bridge it. Where the router signal is not strong, each node will find another upstream master or bridge node with the strongest signal and bridge it (except slave).
![wiot node distributed networking](https://api.yimian.xyz/img/?path=imgbed/img_a42f5a4_1224x561_8_null_normal.jpeg)
As shown in the figure above, the two master nodes close to the router are automatically connected to the router wifi. The other downstream nodes are respectively connected to the upstream node with the strongest signal.
#### **Certification**
![Radio frequency fingerprint identification[2]](https://api.yimian.xyz/img/?path=imgbed/img_d184ff2_1442x502_8_null_normal.jpeg)
Wiot nodes support the use of **RF Fingerprint Recognition**[[2]](https://ieeexplore.ieee.org/document/8715341) to achieve downstream communication authentication. This method uses the RSSI function of esp8266 and scan return parameters. When the downstream device attempts to access the network, the upstream device will collect fingerprint information and report to the server. The server compares the fingerprint with the previous version stored in the database and makes a decision whether to allow access to the network.
### Cloud Module
The cloud module acts as the cloud part of Wiot and provides cloud functions. The cloud module can guard the wiot program running in the run-time state. In addition, the cloud module can also provide functions such as testing and deployment. The cloud module uses Docker for virtualization.
### Command Line Program
That is wiot-cli. It is a set of operation tools provided by Wiot on the developer terminal. Through wiot-cli, developers can implement functions such as testing, deploying, and restoring wiot programs. In addition, wiot-cli also supports a series of common functions such as debug. See the `wiot-cli command` below for details.
## User operation steps
1. The user downloads, installs and configures the NodeJS environment.
2. The user runs the command `npm i -g wiot-cli` through the command line to install the wiot command line tool
3. The user runs the command `wiot init my-wiot-proj` to create and configure a wiot project folder in the current directory, the project name is my-wiot-proj. At this point, the user will be prompted to fill in some information about this project, such as project description, author information, WiFi account password, wiot cloud module address, project main script, etc.
4. The user enters the project directory, connects the nodeMCU to the computer through the data cable, and runs `wiot node init my-first-node [--type=<master|slave|bridge|debug>]`. This will automatically configure and burn the Wiot firmware to the nodeMCU development board and name it my-first-node. type is an optional parameter, which can be set to `master` or `slave` or `bridge` or `debug`, and the default is `master`.
5. Follow this method to burn all the development boards and deploy them in the production environment.
6. Run the command `wiot status` in the project folder to see if all nodes are online. If not, use the command `wiot log` with the `grep` tool to find the log location problem.
7. Start writing your wiot program from the main project script (default is `index.js`).
8. Use the command `wiot check` to check the logic of your wiot program.
9. Use the command `wiot test` to suspend the running program in the cloud module and run the program in the current project folder. At this point, all console output will be displayed in your command line window. Use `Ctrl+C` to terminate the current test and restore the previous program of the cloud module.
10. Use the command `wiot push` to deploy the local wiot program to the cloud.
## Other operations
### Deploy your own wiot cloud module
Install docker and run the command `docker run -d --name=wiot-cloud -p 3594:3594 -v /var/wiot/data/:/var/wiot/data/ iotcat/wiot`.
### wiot-cli command
- `wiot help [command]` view help
- `wiot clone <host:user/project>` to clone the project from the cloud module to the local
- `wiot pull` uses remote code to overwrite local code
- `wiot push` deploys the current folder wiot program to the cloud module
- `wiot ls` shows all current nodes
- `wiot map [nodeID]` shows the connection path of a node
- `wiot log [nodeID] [--head=<number>|--tail=<number>]` view the log of a node
- `wiot stop` stop wiot service
- `wiot start` to start wiot service
- `wiot restart` restart wiot service
- `wiot reload` restarts the wiot service without resetting the flash variable
- `wiot init <name>` creates and initializes the wiot project folder
- `wiot node init <node-name> [--type=<master|slave|bridge|debug>]` configure and burn nodeMCU development board
- `wiot check` checks the current folder project logic problem.
- `wiot test` will suspend the running program in the cloud module and run the program in the current project folder. At this point, all console output will be displayed in your command line window. Use `Ctrl+C` to terminate the current test and restore the previous program of the cloud module.
- `wiot status [nodeID]` displays current project or node status information
- `wiot debug start` terminates the current cloud program and enters debug mode
- `wiot debug set <nodeID> <pinID> <0-255>`Set the PWM output value of a node pin in debug mode
- In `wiot debug reset <nodeID>`debug mode, reset the data storage of a node and reconnect
- `wiot debug get <nodeID> <pinID>` get the PWM value of a node pin in debug mode
- `wiot debug sleep <nodeID> <pinID> <HIGH|LOW>`debug mode to set a node to lightly sleep until it is awakened by a pin's high or low level
- `wiot debug dsleep <nodeID> <millisecond>` set how many milliseconds a node deeply sleeps in debug mode
- In `wiot debug reconnect [nodeID]`debug mode, reconnect to the network or disconnect and reconnect to a node
### Common API
> To be designed, please refer to [One-round development wiot document](https://wiot.yimian.xyz/#/home)
{% raw %}</span>{% endraw %}
Loading…
Cancel
Save