Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 469.6k

How to send message back to things network using javascript

Dec 16 2019 2:12 PM
Hi Team
 
Is there someone who have once worked with things network to send data, using jquery as a restful client to the broswer or device. I have code that tries to do such logic, but i am seem to be failing to this right. I am not getting help either from stackoverflow. Please help me mates below is my logic.
  1. <div class = "wrapper" align = "center">  
  2. <div class="btn-group" id="toggle_event_editing">  
  3. <button type="button" class="btn btn-danger locked_active">OFF</button>  
  4. <button type="button" class="btn btn-success unlocked_inactive">ON</button>  
  5. </div>  
  6. <div class="alert alert-danger" id="switch_status">Switched off.</div> </div> <br/>  
  7. // button for switch functionality on/off.  
  8. $(document).ready(function()  
  9. {  
  10. $('#toggle_event_editing button').click(function(){  
  11. if($(this).hasClass('locked_active')) {  
  12. $('#switch_status').html('Switched off');  
  13. $.ajax({  
  14. url:'https://integrations.thethingsnetwork.org/ttn-eu/api/v2/down/acts083_test/mkr1300?key=ttn-account-v2.7Ph6lBffU7wI9cLY5ljIhIb_I7sqH5EVvo5zs9uVyA0',  
  15. type:'POST',  
  16. data:{  
  17. payload_raw: 'AAA',  
  18. dev_id:'mkr1300'  
  19. },  
  20. success:function(response){  
  21. alert(response);  
  22. },  
  23. error:function() {  
  24. $('#error').text("There was an error while processing your request. Please try again");  
  25. }  
  26. });  
  27. }else{  
  28. $('#switch_status').html('Switched on.');  
  29. $.ajax({  
  30. url:'https://integrations.thethingsnetwork.org/ttn-eu/api/v2/down/acts083_test/mkr1300?key=ttn-account-v2.7Ph6lBffU7wI9cLY5ljIhIb_I7sqH5EVvo5zs9uVyA0',  
  31. type:'POST',  
  32. data:{  
  33. payload_raw:'AAE',  
  34. dev_id:'mkr1300'  
  35. },  
  36. success:function(response) {  
  37. alert(response);  
  38. },  
  39. error:function() {  
  40. $('#error').text("There was an error while processing your request.Please try again");  
  41. }  
  42. });  
  43. }  
  44. });  
  45. });  

Answers (2)