I have a php file in my website which returns sensor reading. I had been fetching this reading and displaying in my Serial monitor using the below code
http.begin("http://<MYWEBSITE>/fetch_sensor.php");
int httpCode = http.GET();
if (httpCode > 0) {
String payload = http.getString();
SensorReading = payload.toInt();
Serial.print("Sensor Reading=");
Serial.print(SensorReading);
Serial.println();
}
Now I have updated my php file to return readings of multiple sensors. The readings are returned seperated by commas like 23,66,82,100
I am looking to update my code so that the readings returned by the php file is assigned as SensorReading1, SensorReading2, SensorReading3 etc.
Seeking help from experts..
Thanks!!
You need to split your incoming string into separate strings, and then display each one. There are a few ways of splitting a string: https://arduino.stackexchange.com/questions/1013/how-do-i-split-an-incoming-string
Related
I used the example repo of Azure für sending telemetry data: https://github.com/Azure/azure-iot-arduino/tree/master/examples/esp8266/iothub_ll_telemetry_sample
I did not modify any code. This is the important part:
const char* telemetry_msg = "test_message";
message_handle = IoTHubMessage_CreateFromString(telemetry_msg);
result = IoTHubDeviceClient_LL_SendEventAsync(device_ll_handle, message_handle, send_confirm_callback, NULL);
Why does my body-result looks like an ASCII array? (Note: Using Azure IoT explorer)
Is it meant to be an array like this. Do I have to unpack this array on the other side?
I want to be able to send the data in JSON format like the azure device simulator does:
Nevermind, figured it out. The following example will send data in JSON format:
char telemetry_msg_buffer[80];
sprintf(telemetry_msg_buffer, "{\"temperature\":11.11,\"humidity\":12.12,\"scale\":\"13.13\"}");
message_handle = IoTHubMessage_CreateFromString(telemetry_msg_buffer);
As per subject, how do I to manipulate the string passed through SoftwareSerial Print/Println function? The reason why is I tried to make the URL parameter dynamic in order to access different webpages.
*Note: The code snippet below are working fine if without using String variable
// This is working fine
SoftwareSerial iSerial(28, 29);
iSerial.println("AT+HTTPPARA=\"URL\",\"http://website.com/data1.php\"");
delay(1000);
Serial.write(iSerial.read());
// This is not working
SoftwareSerial gprsSerial(28, 29 );
Int inputNumber;
String S1 = "AT+HTTPPARA=\"URL\",\"http://website.com/";
String S2 = String(inputNumber) + "data.php\"";
String_Variable = S1+S2;
iSerial.println(String_Variable);
delay(1000);
Serial.write(iSerial.read());
*Working means able to access the webpage via simcard using SIM900 (AT+HTTPPARA)
I even tried converting the string to array using malloc() and toCharArray() but it is still not working when I use the SoftwareSerial print function.
I'm new to Arduino. Kindly advise. Thanks! :)
Hello im using Nodejs with farhadi node-smpp library to send Message through smpp v3.4 protocals and gsm library to split the message, In my case i have a long Message(More than 255 characters), when i split the message i want it to be delivered as single long message, but unfortunately it is delivered in parts. Here are my sample codes for sending the message
var info = gsm(text);
var concat_ref = Math.floor(Math.random() * 255);
var part_id = 0;
info.parts.forEach(function(part){
part_id++;
var udh = new Buffer.allocUnsafe(6);
udh.write(String.fromCharCode(0x5), 0); //Length of UDF
udh.write(String.fromCharCode(0x0), 1); //Indicator for concatenated message
udh.write(String.fromCharCode(0x3), 2); // Subheader Length ( 3 bytes)
udh.write(String.fromCharCode(concat_ref), 3); //Same reference for all concatenated messages
udh.write(String.fromCharCode(info.sms_count), 4); //Number of total messages in the concatenation
udh.write(String.fromCharCode(part_id), 5); //Sequence number ( used by the mobile to concatenate the split messages)
session.submit_sm({
source_addr: from,
destination_addr: to,
message_payload: { udh: part.udh, message: part }
}, function(pdu) {
console.log('sms pdu status', lookupPDUStatusKey(pdu.command_status));
if (pdu.command_status == 0) {
// Message successfully sent
console.log(pdu.message_id);
}
});
})
You can use the message_payload parameter (field name) as stated in the official SMPP's specification to send messages longer than 254 octets.
message_payload definition:
Contains the extended short message user data. Up to 64K octets can be
transmitted.
The official document says:
Applications which need to send messages longer than 254 octets should
use the message_payload parameter. In this case the sm_length field
should be set to zero.
The short message data should be inserted in either the short_message
or message_payload fields. Both fields must not be used
simultaneously.
I made a test with node-smpp, and it works. No need to concatenate.
It's not very clear what you mean by "i want it to be delivered as single long message".
But SMPP wise, what you are doing seems correct. Long messages are delivered in parts and they are concatenated by the terminal(phone) based on the three parameters : part_ref, part_number and total_parts. However, from my experience, the concatenation is not really standard across all devices. For instance, some devices don't wait long enough for all the parts to arrive and show incomplete messages or nothing at all.
You have 2 choices when sending concatenated sms via SMPP : One is what you used (UDH), but there are also TLV parameters dedicated for the 3 parameters. You could ask your SMPP provider about extra details on how they support the sending of concatenated messages.
I read bytes from a microcontroller in VC++2010(that i dont know absolutely but i must use as in lack of someone else) using SerialPort and on DataReceived event.
private: System::Void serialPort1_DataReceived(System::Object^ sender,
System::IO::Ports::SerialDataReceivedEventArgs^ e)
{
String^mystr;
mystr = serialPort1->ReadExisting();
I need raw data but everything >0x7F looks changed to 0x3F.
in the watch window mystr[3]=0x3F,despite i sent 0x80;
Why are some data lost?I expect that a raw byte could be converted in a char ,maybe an impossible to print char,but without altering the data.
Is there any way to have an array of raw data instead?
Thanks
How can I grab all the text in a website, and I don't just mean ctrl+a/c. I'd like to be able to extract all the text from a website (and all the pages associated) and use it to build a concordance of words from that site. Any ideas?
I was intrigued by this so I've written the first part of a solution to this.
The code is written in PHP because of the convenient strip_tags function. It's also rough and procedural but I feel in demonstrates my ideas.
<?php
$url = "http://www.stackoverflow.com";
//To use this you'll need to get a key for the Readabilty Parser API http://readability.com/developers/api/parser
$token = "";
//I make a HTTP GET request to the readabilty API and then decode the returned JSON
$parserResponse = json_decode(file_get_contents("http://www.readability.com/api/content/v1/parser?url=$url&token=$token"));
//I'm only interested in the content string in the json object
$content = $parserResponse->content;
//I strip the HTML tags for the article content
$wordsOnPage = strip_tags($content);
$wordCounter = array();
$wordSplit = explode(" ", $wordsOnPage);
//I then loop through each word in the article keeping count of how many times I've seen the word
foreach($wordSplit as $word)
{
incrementWordCounter($word);
}
//Then I sort the array so the most frequent words are at the end
asort($wordCounter);
//And dump the array
var_dump($wordCounter);
function incrementWordCounter($word)
{
global $wordCounter;
if(isset($wordCounter[$word]))
{
$wordCounter[$word] = $wordCounter[$word] + 1;
}
else
{
$wordCounter[$word] = 1;
}
}
?>
I needed to do this to configure PHP for the SSL the readability API uses.
The next step in the solution would be too search for links in the page and call this recursively in an intelligent way to hance the associated pages requirement.
Also the code above just gives the raw data of a word-count you would want to process it some more to make it meaningful.