
A Programming Language for the Internet of Things Magnus Åsrud Master’s Thesis Spring 2017 A Programming Language for the Internet of Things Magnus Åsrud 2nd May 2017 2 Abstract The Internet of Things (IoT) is becoming more integrated with our daily lives for each passing day. Some households are already equipped with smart devices which perform tasks such as monitoring the indoor climate to mowing the lawn. There exists open source frameworks designed for IoT which can be used by hobbyist and professionals for their own projects. However, many of those tools require the user to know programming languages such as C, Python and JavaScript. Users who do not know much programming and who would like to tinker with IoT may find it challenging to work with those tools. In this thesis we’ll look at how to design a programming language tar- geted specifically at IoT. The language is targeted at amateur programmers with the goal to make it easy to program any IoT device. We’ll discuss the current limitations of the IoT hardware and how the language should work around them. Finally, we’ll look at how to implement an interpreter for this language on a Raspberry Pi 3 Model B. 3 4 Contents I Background 13 1 Introduction 15 1.1 Impulse SmartCity........................ 15 1.2 The Current Project........................ 16 1.3 Acknowledgements........................ 16 2 The Internet of Things 17 2.1 Internet of Things......................... 17 2.1.1 What is the Internet of things?............. 17 2.2 Sensors............................... 18 2.2.1 Energy efficiency..................... 20 2.3 Communication.......................... 20 2.3.1 Bluetooth......................... 20 2.3.2 WiFi............................ 22 2.3.3 WiFi HaLow........................ 23 3 Related Projects 25 3.1 Alternatives............................ 25 3.1.1 Scriptr........................... 25 3.1.2 Libelium Waspmote Plug & Sense........... 25 3.1.3 Johnny-Five........................ 26 3.1.4 Tessel 2........................... 26 3.2 Evaluation............................. 26 II Design 27 4 Requirements for an IoT Programming Language 29 4.1 The Target Platform........................ 29 4.2 The Target Audience....................... 29 4.3 The Core Requirements...................... 30 4.4 Hot Swap Scripts......................... 30 4.5 Interpreting vs Compiling.................... 30 4.5.1 Compiling......................... 30 4.5.2 Interpretation....................... 32 4.5.3 Evaluation......................... 32 4.6 The Type System......................... 32 4.6.1 Static Typing....................... 32 5 4.6.2 Dynamic Typing..................... 33 4.6.3 Inferred Typing...................... 33 4.6.4 Evaluation......................... 33 4.7 Event Oriented Programming.................. 34 4.7.1 Handling Events..................... 34 4.8 Security............................... 34 4.9 Errors and Exceptions...................... 35 4.10 Handling a Software Crash................... 35 4.10.1 Alternative 1: Reset.................... 35 4.10.2 Alternative 2: Remove the script............ 36 4.10.3 Alternative 3: Ignore it.................. 36 4.10.4 Alternative 4: Terminate................. 36 4.10.5 Alternative 5: Inform the user.............. 37 4.10.6 Watchdog Daemon.................... 37 4.11 Sensors and Actuators...................... 37 4.12 The Standard Library....................... 38 5 Designing Daspel 39 5.1 What is Daspel?.......................... 39 5.2 The syntax............................. 39 5.3 Data types............................. 39 5.4 Integer............................... 40 5.4.1 Integer Syntax....................... 40 5.5 Real................................. 40 5.5.1 Real Syntax........................ 41 5.6 Boolean............................... 41 5.6.1 Why include boolean?.................. 41 5.7 String................................ 42 5.7.1 Unicode.......................... 42 5.7.2 Dynamic Size....................... 42 5.7.3 Single Character..................... 42 5.7.4 String Syntax....................... 42 5.8 List................................. 43 5.8.1 List Syntax......................... 43 5.9 Nil the Error Type......................... 43 5.10 Variables and Variable Declaration............... 43 5.10.1 Variable Declaration Ambiguity............ 44 5.10.2 Variable Declaration Part................ 44 5.10.3 Variables and Scopes................... 45 5.11 Scoping............................... 45 5.11.1 Variable Scope....................... 46 5.11.2 Library Scope....................... 47 5.11.3 Global Scope....................... 47 5.11.4 Function Scope...................... 47 5.12 Operators............................. 47 5.13 Statements............................. 48 5.13.1 For Loop.......................... 49 5.13.2 While Loop........................ 49 6 5.13.3 Conditionals aka. If-Else................. 49 5.13.4 Functions......................... 49 5.14 Things That Did Not Make It To The Language........ 50 5.14.1 Variadic Function..................... 50 5.14.2 Tuple............................ 50 5.14.3 Type Annotation For Function Parameters...... 50 5.14.4 Data Type Methods.................... 51 5.15 Unicode Syntax.......................... 51 III Implementation 59 6 Proof of Concept 61 6.1 The Goal of the Implementation................. 61 6.2 The Hardware........................... 61 6.3 The Interpreter.......................... 61 6.4 Source Code............................ 62 6.5 Disclaimer............................. 62 7 The Raspberry Pi and the Sense HAT 63 7.1 Raspberry Pi 3 Model B..................... 63 7.1.1 Software.......................... 64 7.2 Sense HAT............................. 64 7.2.1 Sensor Communication................. 65 7.2.2 Byte Encoding....................... 65 7.2.3 The Sensors........................ 65 7.2.4 The LED Matrix...................... 66 7.2.5 RTIMULib......................... 67 7.2.6 Errors In Reading Temperatures............ 67 8 Implementation 69 8.1 Criteria............................... 69 8.2 Implementation Language.................... 69 8.2.1 Python........................... 70 8.2.2 C.............................. 70 8.2.3 C++............................. 71 8.2.4 Rust............................ 72 8.2.5 Conclusion........................ 73 8.3 Work setup............................. 73 8.3.1 Required Software.................... 73 8.4 Porting the Sense HAT library to Rust............. 74 8.4.1 Writing the C wrapper.................. 74 8.4.2 The Framebuffer..................... 75 8.4.3 Reimplementing the Sense HAT module from C to Rust 76 8.5 The Lexical Analysis and Syntax Analysis........... 76 8.5.1 The Scanner........................ 76 8.5.2 The Parser......................... 77 8.6 Representing the Data Type Real in Rust............ 78 7 8.6.1 Arithmetic Operations.................. 78 IV Summary 81 9 Conclusion 83 9.1 Analysis.............................. 83 9.2 Future Work............................ 83 8 List of Figures 1.1 A program for controlling a fan using graphical notation.. 16 2.1 Range representation of the WiFI bands............ 23 4.1 Flowchart for the program execution.............. 31 5.1 The bit pattern of a fixed point number............ 41 5.2 An example of how variables can be declared in a language with a static type system..................... 46 7.1 The Raspberry Pi 3 Model B. Source [39]............ 63 7.2 The Sense HAT. Source [41]................... 65 7.3 The orientation. Source [43]................... 66 7.4 The RGB 565 bit field after a RGB 888 value has been encoded by the Python library........................ 66 8.1 A tagged union in C....................... 71 9 10 List of Tables 5.1 Arithmetic operators....................... 48 5.2 Logical operators......................... 48 5.3 Emojis for nil............................ 52 5.4 Emojis for send.......................... 52 5.5 Emojis for power......................... 53 5.6 Emojis for timer.......................... 53 5.7 Emojis for microphone...................... 53 5.8 Emojis for speaker......................... 54 5.9 Emojis for GPS........................... 54 5.10 Emojis for temperature...................... 54 5.11 Emojis for humidity........................ 55 5.12 Emojis for pressure........................ 55 5.13 Emojis for LED.......................... 55 5.14 Emojis for Light.......................... 56 5.15 Emojis for monitors........................ 56 5.16 Emojis for On/Off action..................... 56 5.17 Emojis for loop.......................... 57 5.18 Emojis for If-Else......................... 57 5.19 Emojis for function........................ 57 7.1 The Raspberry Pi 3 Model B specification [36]......... 64 7.2 The Sense HAT sensor modules [42].............. 66 7.3 The Sense HAT specification [40, 48].............. 67 11 12 Part I Background 13 Chapter 1 Introduction 1.1 Impulse SmartCity This project was initially going to be a contribution to another project called Pulse SmartCity. Pulse SmartCity is, as the name implies, a smart city project lead by Jon Bøhmer. The idea was to use hundreds of IoT devices scattered accords a city to gather information about weather, temperature, movement of vehicles and to monitor the electrical consumption. The system would consist of a gateway, nodes and tags. The nodes would communicate with a gateway to transmit data. The tags would be used as identifiers and nodes would be able to recognise them. The contribution to Pulse SmartCity was to design a script language
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages90 Page
-
File Size-