span rel=""> 40
+        Next the '_after_action' hook is executed.
41
+
42
+        """
43
+        try:
44
+            handlers = self.route_map[msg.action]
45
+        except KeyError:
46
+            _raise_key_error(msg.action, self._ocpp_version)
47
+            return
48
+
49
+        if not handlers.get("_skip_schema_validation", False):
50
+            validate_payload(msg, self._ocpp_version)
51
+        # OCPP uses camelCase for the keys in the payload. It's more pythonic
52
+        # to use snake_case for keyword arguments. Therefore the keys must be
53
+        # 'translated'. Some examples:
54
+        #
55
+        # * chargePointVendor becomes charge_point_vendor
56
+        # * firmwareVersion becomes firmwareVersion
57
+        if msg.payload is None:
58
+            msg.payload = {}
59
+        snake_case_payload = camel_to_snake_case(msg.payload)
60
+
61
+        try:
62
+            handler = handlers["_on_action"]
63
+        except KeyError:
64
+            _raise_key_error(msg.action, self._ocpp_version)
65
+
66
+        try:
67
+            response = handler(**snake_case_payload)
68
+            if inspect.isawaitable(response):
69
+                response = await response
70
+        except Exception as e:
71
+            LOGGER.exception("Error while handling request '%s'", msg)
72
+            response = msg.create_call_error(e).to_json()
73
+            await self._send(response)
74
+
75
+            return
76
+
77
+        temp_response_payload = asdict(response)
78
+
79
+        # Remove nones ensures that we strip out optional arguments
80
+        # which were not set and have a default value of None
81
+        response_payload = remove_nones(temp_response_payload)
82
+
83
+        # The response payload must be 'translated' from snake_case to
84
+        # camelCase. So:
85
+        #
86
+        # * charge_point_vendor becomes chargePointVendor
87
+        # * firmware_version becomes firmwareVersion
88
+        camel_case_payload = snake_to_camel_case(response_payload)
89
+
90
+        response = msg.create_call_result(camel_case_payload)
91
+
92
+        if not handlers.get("_skip_schema_validation", False):
93
+            validate_payload(response, self._ocpp_version)
94
+
95
+        await self._send(response.to_json())
96
+
97
+        try:
98
+            handler = handlers["_after_action"]
99
+            # Create task to avoid blocking when making a call inside the
100
+            # after handler
101
+            response = handler(**snake_case_payload)
102
+            if inspect.isawaitable(response):
103
+                asyncio.ensure_future(response)
104
+        except KeyError:
105
+            # '_on_after' hooks are not required. Therefore ignore exception
106
+            # when no '_on_after' hook is installed.
107
+            pass
108
+        return response
109
+	
110
+
111
+class ChargePoint(cp):
112
+
113
+	@on(Action.BootNotification)
114
+	def on_boot_notification(
115
+			self, charge_point_vendor: str, charge_point_model: str, **kwargs):
116
+		pprint(kwargs)
117
+		return call_result.BootNotificationPayload(
118
+				current_time=datetime.utcnow().isoformat(),
119
+				interval=10,
120
+				status=RegistrationStatus.accepted,
121
+				)
122
+
123
+	@on(Action.Authorize)
124
+	def on_authorization(self, id_tag):
125
+		# pprint(kwargs)
126
+		idti = IdTagInfo(status=AuthorizationStatus.accepted)
127
+		# idti.status = AuthorizationStatus.accepted
128
+
129
+		return call_result.AuthorizePayload(
130
+				id_tag_info=idti
131
+				)
132
+
133
+	@on(Action.StatusNotification)
134
+	def on_status_notification(self, id_tag):
135
+		# pprint(kwargs)
136
+		# idti = IdTagInfo(status=AuthorizationStatus.accepted)
137
+		# idti.status = AuthorizationStatus.accepted
138
+		return call_result.StatusNotificationPayload()
139
+
140
+	@on(Action.Heartbeat, skip_schema_validation=True)
141
+	def on_heartbeat(self, **kwargs):  # receives empty payload from CP
142
+		print("--HeartBeat--")
143
+		print(kwargs)
144
+		return call_result.HeartbeatPayload(
145
+				current_time=datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
146
+				)
147
+
148
+
149
+
150
+async def on_connect(websocket, path):
151
+	"""For every new charge point that connects, create a ChargePoint
152
+	instance and start listening for messages.
153
+	"""
154
+	try:
155
+		requested_protocols = websocket.request_headers["Sec-WebSocket-Protocol"]
156
+	except KeyError:
157
+		logging.error("Client hasn't requested any Subprotocol. Closing Connection")
158
+		return await websocket.close()
159
+	if websocket.subprotocol:
160
+		logging.info("Protocols Matched: %s", websocket.subprotocol)
161
+	else:
162
+		# In the websockets lib if no subprotocols are supported by the
163
+		# client and the server, it proceeds without a subprotocol,
164
+		# so we have to manually close the connection.
165
+		logging.warning(
166
+				"Protocols Mismatched | Expected Subprotocols: %s,"
167
+				" but client supports  %s | Closing connection",
168
+				websocket.available_subprotocols,
169
+				requested_protocols,
170
+				)
171
+		return await websocket.close()
172
+
173
+	charge_point_id = path.strip("/")
174
+	cp = ChargePoint(charge_point_id, websocket)
175
+
176
+	await cp.start()
177
+
178
+
179
+async def main():
180
+	server = await websockets.serve(
181
+			on_connect, "0.0.0.0", 9000, subprotocols=["ocpp1.6"]
182
+			)
183
+
184
+	logging.info("Server Started listening to new connections...")
185
+	await server.wait_closed()
186
+
187
+
188
+if __name__ == "__main__":
189
+	# asyncio.run() is used when running this example with Python >= 3.7v
190
+	asyncio.run(main())

+ 1 - 0
ocpp

@@ -0,0 +1 @@
1
+Subproject commit a9df8ebdaee922c323be1d06eace2d5a35a5f747

mcot/spacemcot - Gogs: Simplico Git Service

Nav apraksta

function.html 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <title>Test</title>
  5. <meta charset="UTF-8">
  6. <meta http-equiv="X-UA-Compatible" content="IE-edge">
  7. <meta name="viewport" content="width=device-width, initial-scal=1">
  8. <link rel="stylesheet" type="text/css" href="/static/css/test.css">
  9. <link rel="stylesheet" type="text/css" href="/static/css/test-theme.css">
  10. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  11. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  12. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  13. <style type="text/css">
  14. html, body {
  15. margin: 0;
  16. padding: 0;
  17. background-color: #010010;
  18. }
  19. h3 {color: #fff;}
  20. * {
  21. box-sizing: border-box;
  22. }
  23. .slider {
  24. width: 100%;
  25. }
  26. .slick-slide {
  27. margin: 0px 10px;
  28. }
  29. .slick-slide img {
  30. width: 100%;
  31. height: 250px;
  32. }
  33. .slick-prev:before,
  34. .slick-next:before {
  35. color: #fff;
  36. }
  37. .slick-slide {
  38. transition: all ease-in-out .3s;
  39. opacity: .2;
  40. }
  41. .slick-active {
  42. opacity: .5;
  43. }
  44. .menu {
  45. width: 35px;
  46. height: 5px;
  47. background-color: #fff;
  48. margin: 6px 0;
  49. }
  50. .searchicon{
  51. margin-top: 15px;
  52. margin-right: 20px;
  53. color: #fff;
  54. }
  55. .fontwhite{
  56. color: #fff;
  57. }
  58. </style>
  59. </head>
  60. <body>
  61. <div class="subNav hidden-lg">
  62. <nav id="subNav">
  63. <button type="button" class="hidden-lg-up navbar-toggle hamberger-menu pull-left" data-toggle="collapse" data-target="#collapsingSubNavbar">
  64. <span class="sr-only">Toggle navigation</span>
  65. <span class="icon-bar" style="background-color:#fff"></span>
  66. <span class="icon-bar" style="background-color:#fff"></span>
  67. <span class="icon-bar" style="background-color:#fff"></span>
  68. </button>
  69. <div class='pull-right avt-container' style='display:none'>
  70. <fb-avatar></fb-avatar>
  71. </div>
  72. <div>
  73. <a class="navbar-brand hidden-lg-up brand mcot-logo-box" ui-sref="app.index" >
  74. <img src="http://imgs.mcot.net/images/2017/10/1509338573304.png" style="height:auto; width:55px; margin-left:55px;;display:inherit;margin-top: -5px;">
  75. </a>
  76. </div>
  77. <div class="" style="background-color: #2860AA;">
  78. <a class="">
  79. <span class="glyphicon glyphicon-search searchicon" style="margin-left: 85px;"></span>
  80. </div>
  81. <div class="container" style="background-color: #2860AA;">
  82. <div id="collapsingSubNavbar" class="collapse navbar-toggleable-md hidden-lg-up" style="margin-top:50px;">
  83. <ul class="nav navbar-nav">
  84. <li class="nav-item text-center">
  85. <a class="nav-link" href="http://www.tnamcot.com" target="_blank">ข่าว</a>
  86. </li>
  87. <li class="nav-item text-center">
  88. <a class="nav-link" href="http://www.nineentertain.tv" target="_blank">บันเทิง</a>
  89. </li>
  90. <li class="nav-item text-center">
  91. <a class="nav-link" href="http://lively.mcot.net/index" target="_blank">ไลฟ์สไตล์</a>
  92. </li>
  93. <li class="nav-item text-center">
  94. <a class="nav-link" href="http://tv.mcot.net" target="_blank">โทรทัศน์</a>
  95. </li>
  96. <li class="nav-item text-center">
  97. <a class="nav-link" href="http://mcot-web.mcot.net/radio/" target="_blank">วิทยุ</a>
  98. </li>
  99. <li class="nav-item text-center">
  100. <a class="nav-link" href="/category/กิจกรรม">กิจกรรม</a>
  101. </li>
  102. <li class="nav-item text-center">
  103. <a class="nav-link" href="/category/ประชาสัมพันธ์">ประชาสัมพันธ์</a>
  104. </li>
  105. </ul>
  106. </div>
  107. </div>
  108. </nav>
  109. </div>
  110. <!--Titlebar-->
  111. <div class="container-fluid visible-lg" style="background-color: #2860AA;">
  112. <div class="navbar-header" style="margin-top: 5px; margin-left: -10px;">
  113. <div class="menu"></div>
  114. <div class="menu"></div>
  115. <div class="menu"></div>
  116. </div>
  117. <div>
  118. <a class="navbar-brand hidden-lg-up brand mcot-logo-box" ui-sref="app.index" >
  119. <img src="http://imgs.mcot.net/images/2017/10/1509338573304.png" style="height:auto; width:55px; margin-left:600px;;display:inherit;margin-top: -5px;">
  120. </a>
  121. </div>
  122. <span class="visible-lg glyphicon glyphicon-search" style="color: #fff; margin-top: 15px; float: right;"></span>
  123. </div>
  124. <!--Hilight-->
  125. <div class="hidden-lg">
  126. <a href="#"><img src="https://placeholdit.imgix.net/~text?txtsize=18&txt=260x320" style="height: 260px;width: 100%;"></a>
  127. </div>
  128. <div class="visible-lg">
  129. <a href="#"><img src="https://placeholdit.imgix.net/~text?txtsize=18&txt=1350x500" style="height: 500px;width:100%;"></a>
  130. </div>
  131. <div class="container">
  132. <p><h3 class="fontwhite">The Walking Dead</h3></p>
  133. <button type="button" class="btn btn-default">Add Favorite</button>
  134. <button type="button" class="btn btn-default">Rate</button>
  135. </div>
  136. <hr>
  137. <!--End Hilight-->
  138. <!--ContinueWatch-->
  139. <!--Moblie Continue-->
  140. <div class="container hidden-lg " style="margin-top: -30px;">
  141. <h3>Season7</h3>
  142. </div>
  143. <div class="col-lg-6 hidden-lg">
  144. <a href="#"><img src="https://placeholdit.imgix.net/~text?txtsize=18&txt=160x140" style="height: 130px;width: 143px;"></a>
  145. <a href="#"><img src="https://placeholdit.imgix.net/~text?txtsize=18&txt=160x140" style="height: 130px;width: 143px;"></a>
  146. </div>
  147. <br>
  148. <div class="col-lg-6 hidden-lg">
  149. <a href="#"><img src="https://placeholdit.imgix.net/~text?txtsize=18&txt=160x140" style="height: 130px;width: 143px;"></a>
  150. <a href="#"><img src="https://placeholdit.imgix.net/~text?txtsize=18&txt=160x140" style="height: 130px;width: 143px;"></a>
  151. </div><br>
  152. </div>
  153. <!--End Moblie Continue-->
  154. <div class="container visible-lg">
  155. <h3>Continue Watch For You</h3>
  156. <div class="col-lg-12">
  157. <div class="col-lg-6">
  158. <a href="#"><img src="https://placeholdit.imgix.net/~text?txtsize=18&txt=250x540" style="height: 250px;width: 540px;"></a>
  159. </div>
  160. <div class="col-lg-6">
  161. <a href="#"><img src="https://placeholdit.imgix.net/~text?txtsize=18&txt=250x540" style="height: 250px;width: 540px;"></a>
  162. </div>
  163. </div><br>
  164. <div class="col-lg-12" style="margin-top: 15px;">
  165. <div class="col-lg-6">
  166. <a href="#"><img src="https://placeholdit.imgix.net/~text?txtsize=18&txt=250x540" style="height: 250px;width: 540px;"></a>
  167. </div>
  168. <div class="col-lg-6">
  169. <a href="#"><img src="https://placeholdit.imgix.net/~text?txtsize=18&txt=250x540" style="height: 250px;width: 540px;"></a>
  170. </div></div><br>
  171. <div class="col-lg-12" style="margin-top: 15px;">
  172. <div class="col-lg-6">
  173. <a href="#"><img src="https://placeholdit.imgix.net/~text?txtsize=18&txt=250x540" style="height: 250px;width: 540px;"></a>
  174. </div>
  175. <div class="col-lg-6">
  176. <a href="#"><img src="https://placeholdit.imgix.net/~text?txtsize=18&txt=250x540" style="height: 250px;width: 540px;"></a>
  177. </div></div><br>
  178. </div>
  179. <!--endcon-->
  180. </body>
  181. </html>