"use strict";(self.webpackChunkwebserial_docs=self.webpackChunkwebserial_docs||[]).push([[558],{3905:(e,t,r)=>{r.d(t,{Zo:()=>c,kt:()=>m});var n=r(7294);function i(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t=0||(i[r]=e[r]);return i}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r])}return i}var s=n.createContext({}),p=function(e){var t=n.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):o(o({},t),e)),r},c=function(e){var t=p(e.components);return n.createElement(s.Provider,{value:t},e.children)},d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},u=n.forwardRef((function(e,t){var r=e.components,i=e.mdxType,a=e.originalType,s=e.parentName,c=l(e,["components","mdxType","originalType","parentName"]),u=p(r),m=i,b=u["".concat(s,".").concat(m)]||u[m]||d[m]||a;return r?n.createElement(b,o(o({ref:t},c),{},{components:r})):n.createElement(b,o({ref:t},c))}));function m(e,t){var r=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var a=r.length,o=new Array(a);o[0]=u;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l.mdxType="string"==typeof e?e:i,o[1]=l;for(var p=2;p{r.r(t),r.d(t,{assets:()=>s,contentTitle:()=>o,default:()=>d,frontMatter:()=>a,metadata:()=>l,toc:()=>p});var n=r(7462),i=(r(7294),r(3905));const a={title:"Printing Logs",sidebar_label:"Printing Logs",sidebar_position:5},o="Printing Logs",l={unversionedId:"printing",id:"printing",title:"Printing Logs",description:"The WebSerial library provides you a really nice UI on the web browser itself using WebSockets protocol, making it easy to debug and monitor your projects/devices. Under the hood, this library inherits Print class of the Arduino core, so it uses methods similar to the Serial library.",source:"@site/docs/printing.md",sourceDirName:".",slug:"/printing",permalink:"/printing",draft:!1,tags:[],version:"current",sidebarPosition:5,frontMatter:{title:"Printing Logs",sidebar_label:"Printing Logs",sidebar_position:5},sidebar:"tutorialSidebar",previous:{title:"Callbacks",permalink:"/callbacks"},next:{title:"Toggle Input (Pro)",permalink:"/toggle-input"}},s={},p=[{value:"Methods",id:"methods",level:2},{value:"print()",id:"print",level:3},{value:"println()",id:"println",level:3},{value:"printf()",id:"printf",level:3},{value:"write()",id:"write",level:3}],c={toc:p};function d(e){let{components:t,...r}=e;return(0,i.kt)("wrapper",(0,n.Z)({},c,r,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("h1",{id:"printing-logs"},"Printing Logs"),(0,i.kt)("p",null,"The WebSerial library provides you a really nice UI on the web browser itself using WebSockets protocol, making it easy to debug and monitor your projects/devices. Under the hood, this library inherits ",(0,i.kt)("inlineCode",{parentName:"p"},"Print")," class of the Arduino core, so it uses methods similar to the ",(0,i.kt)("inlineCode",{parentName:"p"},"Serial")," library."),(0,i.kt)("admonition",{title:"Important Tip",type:"tip"},(0,i.kt)("p",{parentName:"admonition"},(0,i.kt)("strong",{parentName:"p"},"Don't")," send large amounts of data in a single shot with WebSerial. (ie. more than 1KB)"),(0,i.kt)("p",{parentName:"admonition"},"WebSerial uses WebSockets as its underlying transport mechanism which is of low throughput (due to hardware limitation). Although there are built-in mechanisms in WebSerial library to ease this burden, it's advised to optimize the your firmware for a crash-free experience.")),(0,i.kt)("h2",{id:"methods"},"Methods"),(0,i.kt)("p",null,"Here are a example few methods which can be used to print logs/messages to WebSerial terminal:"),(0,i.kt)("h3",{id:"print"},(0,i.kt)("inlineCode",{parentName:"h3"},"print()")),(0,i.kt)("p",null,"Prints data to the WebSerial port as human-readable ASCII text."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-cpp"},"WebSerial.print(data);\n")),(0,i.kt)("h3",{id:"println"},(0,i.kt)("inlineCode",{parentName:"h3"},"println()")),(0,i.kt)("p",null,"Prints data to the WebSerial terminal followed by a carriage return and newline."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-cpp"},"WebSerial.println(data);\n")),(0,i.kt)("h3",{id:"printf"},(0,i.kt)("inlineCode",{parentName:"h3"},"printf()")),(0,i.kt)("p",null,"Prints formatted data to the WebSerial terminal."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-cpp"},"WebSerial.printf(format, args...);\n")),(0,i.kt)("h3",{id:"write"},(0,i.kt)("inlineCode",{parentName:"h3"},"write()")),(0,i.kt)("p",null,"Writes binary data to the WebSerial terminal."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-cpp"},"WebSerial.write(data);\nWebSerial.write(buffer, size);\n")))}d.isMDXComponent=!0}}]);