This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| boolean isJavaFun = true; | |
| System.out.println(isJavaFun);// Outputs true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Math.max(50, 100); | |
| Math.min(50, 100); | |
| Math.sqrt(100); | |
| Math.random(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int num1 = 200 + 50; // 250 (200 + 50) | |
| int num2 = num1 + 250; // 500 (250 + 250) | |
| int num3 = num2 + num2; // 1000 (500 + 500) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int myInt = 9; | |
| double myDouble = myInt; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This is a single line comment | |
| System.out.println("Hello World"); | |
| System.out.println("Hello World"); // This is a single comment | |
| /* This is a multiple line comment, | |
| The code below will print the words Hello World to the screen, and it is amazing */ | |
| System.out.println("Hello World"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Hello { | |
| public static void main(String[] args) { | |
| System.out.println("Hello World"); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void loop() { | |
| if (!client.connected()) { | |
| reconnect(); | |
| } | |
| client.loop(); | |
| long now = millis(); | |
| if (now - lastMsg > 2000) { | |
| lastMsg = now; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void setup() { | |
| // Initialize NodeMCU | |
| Serial.begin(115200); | |
| setup_wifi(); | |
| client.setServer(mqtt_server, 1883); | |
| client.setCallback(callback); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void reconnect() { | |
| // Loop until we’ re reconnected | |
| while (!client.connected()) { | |
| Serial.print("Attempting MQTT connection..."); | |
| // Create a random client ID | |
| String clientId = "ESP8266Client-"; | |
| clientId += String(random(0xffff), HEX); | |
| // Attempt to connect | |
| if (client.connect(clientId.c_str())) { | |
| Serial.println("connected"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void callback(char* topic, byte* payload, unsigned int length) { | |
| Serial.print("Message arrived ["); | |
| Serial.print(topic); | |
| Serial.print("] "); | |
| for (int i = 0; i < length; i++) { | |
| Serial.print((char)payload[i]); | |
| } | |
| Serial.println(); | |
| // Do something with node MCU |