AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 08.09.2017, 11:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
gideonvos: Dynamics AX RFID using IoT
Источник: https://gideonvos.wordpress.com/2016...fid-using-iot/
==============

Don’t you hate it when you need to track someone down in an office building for an urgent message, or to sign some paperwork and you have no idea where they are? In a meeting perhaps, phone switched on silent? In the kitchen taking a break?

So here is a quick and easy worker locator using RFID swipe cards with an IoT board that displays your office layout in Dynamics AX, and pin-points where you can find Waldo right now.

For this project we’ll use a $20 Adafruit HUZZAH ESP8266/WiFi board with an MFC522 RFID reader. Mount the reader in a small plastic casing as shown below. The signal is strong enough to read access cards through the plastic wall.

We’ll add a LiPo rechargeable battery to make this portable as well. Just in case you need to mount one of these as and when required.



Next we’ll solder the Adafruit board onto some PCB and add a red and green LED to signal “success” or “failure” when a card is touched to the box. The PCB is really just required to add resistors between VCC and the LED’s.

I like reusing stuff between projects so again, mounting the IoT board with headers onto the PCB makes sense. The completed PCB setup is shown below. The edges of the PCB have been trimmed to fit into the box with the rest, and that measures 8cm x 5cm so perfect to mount on a wall.



Once the RFID reader has been connected and soldered onto the PCB we can stack all of it safely into the box as seen below. The LiPo battery can be recharged via USB and we can get a lot of usage out of it between charges, by putting the ESP8266 WiFi chip into deep sleep mode as often as possible.



We’ll drill two small holes for the LED’s at the top, connect the battery and make another hole for a USB charger connection. All sorted the finished product is seen below ready for mounting.



Coding-wise, I’ve used C through the Arduino IDE to make the whole project work. The code for this is below.

<div style="background:#ffffff;overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"> #include #include #include #define RST_PIN 15 #define SS_PIN 2 #define LED_GREEN 4 #define LED_RED 5 const char* tempssid = "TempAP"; // use a mobile phone to setup AP using IoTLink.net const char* temppass = "TempPass"; const char* iotlink = "www.iotlink.net"; bool routed = false; MFRC522 mfrc522(SS_PIN, RST_PIN); void setup() { Serial1.begin(115200); while(!Serial1){} Serial.begin(9600); SPI.begin(); mfrc522.PCD_Init(); pinMode(LED_GREEN, OUTPUT); pinMode(LED_RED, OUTPUT); digitalWrite(LED_GREEN, LOW); digitalWrite(LED_RED, LOW); WiFi.begin(tempssid, temppass); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } } void loop() { if (!routed) { route(); } MFRC522::MIFARE_Key key; // default to FFFFFFFFFFFF key.keyByte[0] = 0xFF; key.keyByte[1] = 0xFF; key.keyByte[2] = 0xFF; key.keyByte[3] = 0xFF; key.keyByte[4] = 0xFF; key.keyByte[5] = 0xFF; // Loop until card is presented if (!mfrc522.PICC_IsNewCardPresent()) { return; } if (!mfrc522.PICC_ReadCardSerial()) { digitalWrite(LED_RED, HIGH); delay(1000); return; } byte readbuffer1[18]; byte readbuffer2[18]; byte block; MFRC522::StatusCode status; byte len; byte sizeread = sizeof(readbuffer1); block = 0; status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid)); if (status != MFRC522::STATUS_OK) { // failed digitalWrite(LED_RED, HIGH); delay(1000); digitalWrite(LED_RED, LOW); return; } else { for (int i = 0; i </span span style="color:#0000dd;font-weight:bold;"18/span; ispan style="color:#333333;"++/span) { readbuffer1[i] span style="color:#333333;"=/span span style="color:#005588;font-weight:bold;"0x00/span; readbuffer2[i] span style="color:#333333;"=/span span style="color:#005588;font-weight:bold;"0x00/span; } span style="color:#888888;"// read worker name or ID from card/span status span style="color:#333333;"=/span mfrc522.MIFARE_Read(span style="color:#0000dd;font-weight:bold;"1/span, readbuffer1, span style="color:#333333;"&/spansizeread); span style="color:#008800;font-weight:bold;"if/span (status span style="color:#333333;"!=/span MFRC522span style="color:#333333;"::/spanSTATUS_OK) { span style="color:#888888;"// read failed/span digitalWrite(LED_RED, HIGH); delay(span style="color:#0000dd;font-weight:bold;"1000/span); digitalWrite(LED_RED, LOW); span style="color:#008800;font-weight:bold;"return/span; } mfrc522.PICC_HaltA(); mfrc522.PCD_StopCrypto1(); } span style="color:#888888;"// success/span String workername span style="color:#333333;"=/span String((span style="color:#333399;font-weight:bold;"char/span span style="color:#333333;"*/span)readbuffer1); digitalWrite(LED_GREEN, HIGH); delay(span style="color:#0000dd;font-weight:bold;"1000/span); digitalWrite(LED_GREEN, LOW); span style="color:#888888;"// send to ThingSpeak/span span style="color:#008800;font-weight:bold;"const/span span style="color:#333399;font-weight:bold;"char/spanspan style="color:#333333;"*/span host span style="color:#333333;"=/span span style="background-color:#fff0f0;""api.thingspeak.com"/span; span style="color:#008800;font-weight:bold;"const/span span style="color:#333399;font-weight:bold;"char/spanspan style="color:#333333;"*/span thingspeak_key span style="color:#333333;"=/span span style="background-color:#fff0f0;""your api key"/span; WiFiClient client; span style="color:#008800;font-weight:bold;"const/span span style="color:#333399;font-weight:bold;"int/span httpPort span style="color:#333333;"=/span span style="color:#0000dd;font-weight:bold;"80/span; span style="color:#008800;font-weight:bold;"if/span (span style="color:#333333;"!/spanclient.connect(host, httpPort)) { span style="color:#008800;font-weight:bold;"return/span; } String url span style="color:#333333;"=/span span style="background-color:#fff0f0;""/update?key="/span; url span style="color:#333333;"+=/span thingspeak_key; url span style="color:#333333;"+=/span span style="background-color:#fff0f0;""&field1="/span; url span style="color:#333333;"+=/span workername; client.print(String(span style="background-color:#fff0f0;""GET "/span) span style="color:#333333;"+/span url span style="color:#333333;"+/span span style="background-color:#fff0f0;"" HTTP/1.1/spanspan style="color:#666666;font-weight:bold;background-color:#fff0f0;"\r\n/spanspan style="background-color:#fff0f0;""/span span style="color:#333333;"+/span span style="background-color:#fff0f0;""Host: "/span span style="color:#333333;"+/span host span style="color:#333333;"+/span span style="background-color:#fff0f0;""/spanspan style="color:#666666;font-weight:bold;background-color:#fff0f0;"\r\n/spanspan style="background-color:#fff0f0;""/span span style="color:#333333;"+/span span style="background-color:#fff0f0;""Connection: close/spanspan style="color:#666666;font-weight:bold;background-color:#fff0f0;"\r\n\r\n/spanspan style="background-color:#fff0f0;""/span); delay(span style="color:#0000dd;font-weight:bold;"10/span); span style="color:#008800;font-weight:bold;"while/span(client.available()){ String line span style="color:#333333;"=/span client.readStringUntil(span style="color:#0044dd;"'\r'/span); } } span style="color:#333399;font-weight:bold;"void/span span style="color:#0066bb;font-weight:bold;"route/span() { WiFiClient client; span style="color:#008800;font-weight:bold;"if/span (span style="color:#333333;"!/spanclient.connect(iotlink, span style="color:#0000dd;font-weight:bold;"80/span)) { Serial.println(span style="background-color:#fff0f0;""IoTLink connection failed"/span); span style="color:#008800;font-weight:bold;"return/span; } span style="color:#888888;"// uniquely identify our device using the chip id./span span style="color:#888888;"// this id needs to be loaded into IoTLink and mapped to an AP by the customer/span String url span style="color:#333333;"=/span span style="background-color:#fff0f0;""/route?deviceid="/span span style="color:#333333;"+/span String(ESP.getChipId()); client.print(String(span style="background-color:#fff0f0;""GET "/span) span style="color:#333333;"+/span url span style="color:#333333;"+/span span style="background-color:#fff0f0;"" HTTP/1.1/spanspan style="color:#666666;font-weight:bold;background-color:#fff0f0;"\r\n/spanspan style="background-color:#fff0f0;""/span span style="color:#333333;"+/span span style="background-color:#fff0f0;""Host: "/span span style="color:#333333;"+/span iotlink span style="color:#333333;"+/span span style="background-color:#fff0f0;""/spanspan style="color:#666666;font-weight:bold;background-color:#fff0f0;"\r\n/spanspan style="background-color:#fff0f0;""/span span style="color:#333333;"+/span span style="background-color:#fff0f0;""Connection: close/spanspan style="color:#666666;font-weight:bold;background-color:#fff0f0;"\r\n\r\n/spanspan style="background-color:#fff0f0;""/span); span style="color:#333399;font-weight:bold;"unsigned/span span style="color:#333399;font-weight:bold;"long/span timeout span style="color:#333333;"=/span millis(); span style="color:#008800;font-weight:bold;"while/span (client.available() span style="color:#333333;"==/span span style="color:#0000dd;font-weight:bold;"0/span) { span style="color:#008800;font-weight:bold;"if/span (millis() span style="color:#333333;"-/span timeout span style="color:#333333;"> 5000) { Serial.println("IoTLink Timeout !"); client.stop(); return; } } String response = ""; while(client.available()){ response = client.readStringUntil('\r'); } response.remove(0,1); // gobble NL String ssidx = getValue(response,',',0); String passx = getValue(response,',',1); char ssidnew[32] = {0}; char passnew[32] = {0}; ssidx.toCharArray(ssidnew, 32); passx.toCharArray(passnew, 32); WiFi.disconnect(); delay(4000); WiFi.begin((char *)ssidnew, (char *)passnew); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } routed = true; // optionally store retrieved AP information into EEPROM in case of device reset // this avoids having to use a temporary AP again to route to IoTLink } // Helper String getValue(String data, char separator, int index) { int found = 0; int strIndex[] = {0, -1}; int maxIndex = data.length()-1; for(int i=0; i<span style="color:#333333;">
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
axforum blogs: Квест: Подружим Dynamics Ax 2009 Sp1 RU7 c SharePoint Foundation 2010 Blog bot DAX Blogs 4 16.10.2017 17:50
stephenmann: Technical History of Dynamics AX - From Axapta 3.0 to AX2012 Blog bot DAX Blogs 5 03.03.2017 10:22
DAX: Microsoft Dynamics AX 2012 R3 is now available! Blog bot DAX Blogs 1 02.05.2014 23:00
amer-ax: It was a great day! Blog bot DAX Blogs 3 29.12.2012 01:02
emeadaxsupport: List of fixes that improve performance of certain features in Dynamics AX 2009 Blog bot DAX Blogs 0 13.10.2009 19:06

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 04:36.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.