Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. //wifi
  2. var WIFI_NAME = "Redmib";
  3. var WIFI_OPTIONS = {
  4. password: "12345678"
  5. };
  6. var wifi = require("Wifi");
  7. wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) {
  8. if (err) {
  9. console.log("Connection error: " + err);
  10. return;
  11. }
  12. console.log("Connected!");
  13. });
  14. //GET
  15. var http = require("http");
  16. http.get("http://185.243.52.8/api/getCurrentLecture/E3", function(res) {
  17. var contents = "";
  18. res.on('data', function(data) { contents += data; });
  19. res.on('close', function () { var list = JSON.parse(contents);
  20. console.log(list[0].start_date);
  21. });
  22. });
  23.  
  24.  
  25.  
  26.  
  27. //obsługa ekranu
  28. var a = 1;
  29. setInterval(function() {
  30. a++;
  31. if(a>3){
  32. a=1;
  33. }
  34. console.log("zmiana");
  35. }, 5000);
  36.  
  37. function drawScreen() {
  38. setInterval(function() {
  39. if (a == 1) {
  40. g.clear();
  41. g.setFontVector(10);
  42. g.drawString("Aktualne zajęcia", 10, 10);
  43. g.drawString("Aktualne zajęcia", 10, 25);
  44. g.flip();
  45. console.log("2");
  46. }
  47. if(a == 2){
  48. g.clear();
  49. var d = new Date();
  50. g.setFontVector(10);
  51. g.drawString(d.toUTCString().substring(0,15), 10, 10);
  52. g.drawString(d.toUTCString().substring(16,25), 10, 25);
  53. g.flip();
  54. console.log("1");
  55. }
  56. if(a == 3){
  57. g.clear();
  58. g.setFontVector(10);
  59. g.drawString("Następne zajęcia", 10, 10);
  60. g.drawString("Następne zajęcia", 10, 25);
  61. g.flip();
  62. console.log("3");
  63. }
  64.  
  65. }, 1000);
  66. }
  67. drawScreen();
  68. //SPI
  69. var s = new SPI();
  70. s.setup({ mosi: D16, sck: D2 });
  71. var g = require("SH1106").connectSPI(
  72. s,
  73. D04 /* DC */,
  74. D0 /* RST - can leave as undefined */,
  75. drawScreen
  76. );
  77.  
  78. //----- -------------------------------------
  79.  
  80.  
  81. //SPi do kart
  82.  
  83. var spi1 = new SPI();
  84. spi1.setup({
  85. mosi: NodeMCU.D6,
  86. miso: NodeMCU.D5,
  87. sck: NodeMCU.D7
  88. });
  89. var nfc = require("MFRC522").connect(spi1, NodeMCU.D8 /*CS*/ );
  90. //zakomentowane bo nei wiedziałem gdzie wysłać
  91. /*var classroom = 'E4';
  92. var wifi = require("Wifi");
  93. var http = require('http');*/
  94. /*
  95. function sendRequest(idlegitymacji) {
  96. payload = {
  97. classroom: classroom,
  98. els_Id: idlegitymacji,
  99. };
  100. payload = JSON.stringify(payload);
  101. registerOptions = {
  102. host: '169.254.196.250',
  103. port: 8081,
  104. path: '/rejestracja',
  105. method: 'POST',
  106. protocol: 'http',
  107. headers: {
  108. 'Content-Type': 'application/json',
  109. 'Content-Length': payload.length,
  110. 'Accept': 'application/json'
  111. }
  112. };
  113. var req = http.request(registerOptions, function(res) {
  114. console.log('Status: ' + res.statusCode);
  115. console.log('Headers: ' + JSON.stringify(res.headers));
  116. res.on('data', function(data) {
  117. console.log("HTTP> " + data);
  118. });
  119. res.on('close', function(data) {
  120. console.log("Connection closed");
  121. });
  122. res.on('error', function(error) {
  123. console.log(error);
  124. });
  125. });
  126. req.write(payload);
  127. req.end();
  128. }
  129.  
  130. */
  131. setInterval(function() {
  132. nfc.findCards(function(card) {
  133.  
  134. print("Found card " + card);
  135. card = JSON.stringify(card);
  136. print("Found card " + card);
  137. });
  138. }, 500);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement