-
@Gordon
Sorry for the delayed response and Thank you for the suggestion, i tried as above suggested, when i tried to tap on puck it did not redirect me the the webpage. Please see the below code i tried on puck.NRF.on('NFCon', function() { var currentTime = new Date(); NRF.nfcURL('http://192.168.1.154/studentsystem/details.php?time=' + currentTime.toISOString().substr(0, 16)); });
Below is the Javascript code to extract the date and time from URL on my php webpage
<script> function getUrlParameter(name) { name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); var results = regex.exec(location.search); return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); } window.onload = function() { var timeParam = getUrlParameter('time'); if (timeParam !== '') { var loginTime = new Date(timeParam); var logintimeElement = document.getElementById('logintime'); logintimeElement.textContent = loginTime.toLocaleString(); // Update the text content of the logintime element with the extracted time and date } }; </script>
Dont know what i am doing wrong, please guide thank you.
-
How do i use the NRFon event to set the contents of he NFC tag to be a URL?
The only think i did was this and it showed the output perfectly on the terminal when the phone was scanned.NRF.on('NFCon', function() { var currentTime = new Date(); var day = currentTime.getDate(); var month = currentTime.getMonth() + 1; var year = currentTime.getFullYear(); var hours = currentTime.getHours(); var minutes = currentTime.getMinutes(); var formattedDate = padNumber(day) + '/' + padNumber(month) + '/' + year; var formattedTime = padNumber(hours) + ':' + padNumber(minutes); console.log("Student checked-in at: " + formattedDate + " " + formattedTime); }); function padNumber(number){return (number < 10 ? '0': '') + number;}
If i set the contents of the NFC Tag to be a URL content, how would i display it on my webpage? please could you help, thank you.
-
Hello @Gordon
Sorry for the delayed response, so what I did was i used the puck as a beacon, and added a JavaScript code with NDEFreading event, so basically when someone scans a puck device it should display the current date and time of the sacn, which unfortunately did not work, I read on googlechome that NDEFreading is not supported anymore and it’s a experimental feature, I tried turning on the experimental feature in chrome still did not work.
This is the js code<script src="https://www.puck-js.com/puck.js"></script> <script> // Add an event listener to detect NFC tag scanning window.addEventListener('NDEFReading', event => { // Get the data from the NFC tag const message = event.message; // Capture current date and time in UK format const currentTime = new Date(); const day = currentTime.getDate(); const month = currentTime.getMonth() + 1; const year = currentTime.getFullYear(); const hours = currentTime.getHours(); const minutes = currentTime.getMinutes(); const formattedDate = padNumber(day) + '/' + padNumber(month) + '/' + year; const formattedTime = padNumber(hours) + ':' + padNumber(minutes); const checkedInInfo = "Student checked-in at: " + formattedDate + " " + formattedTime; // Display the NFC data on the webpage document.getElementById('nfcData').innerText = checkedInInfo; // Save the NFC data to the logintime textarea document.getElementById('logintime').value = checkedInInfo; }); function padNumber(number) { return (number < 10 ? '0' : '') + number; } </script>
Since this did not work, what I have done now is I put the url of my webpage on puck, when scanned it takes user to webpage, they login and on details page they click on checkin button which records date and time.
I want to record the time and date on the event of nfc scan automatically, is this still possible?
Can the puck be used just a a beacon?
-
@Gordon
Thank you very much for your response, unfortunatly i tried the approach and was unsucessful, do you have any resources that i can look into? or a code which i can look into please?I tried to capture the cureent time when the page loaded but its showing the current login time to details page.
I tried to capture the time from puck and tried to send the data to my webpage even this did not work.
Out of ideas now, i dont know where i am going wrong on my php or puck js.
-
Hello,
I hope you're doing well.
I'm new to this and I'm working on a small project with Puck.js. Here's what I'm trying to do:
I've made a simple webpage using PHP. When a user logs in on their mobile, it takes them to a details page showing a few pieces of information.
Now, when the user taps their phone on the Puck device, I want the NFC function to activate and record the date and time.
I have code that currently works fine. It shows the date and time when the phone is tapped on the Puck device. Here's the code:
NRF.nfcURL('https://www.espruino.com');
NRF.on('NFCon', function() {
var currentTime = new Date(); var day = currentTime.getDate(); var month = currentTime.getMonth() + 1; var year = currentTime.getFullYear(); var hours = currentTime.getHours(); var minutes = currentTime.getMinutes(); var formattedDate = padNumber(day) + '/' + padNumber(month) + '/' + year; var formattedTime = padNumber(hours) + ':' + padNumber(minutes); console.log("Student checked-in at: " + formattedDate + " " + formattedTime);
});
function padNumber(number){return (number < 10 ? '0': '') + number;}
But now, I'm not sure how to send this data from the Puck device to my webpage or a text file. I've tried different methods but couldn't figure it out. Please help me. Thank you.
Let me know if you need the PHP code too.
Best regards,
@Gordon
But if i just use
And scan the puck, it works perfectly.